Unverified Commit f8864fd2 authored by mknichel's avatar mknichel Committed by GitHub

Remove path normalization logic when uploading .next/trace traces (#59305)

When uploading traces from `.next/trace`, target paths that trigger
compilations were being normalized to paths like
`[project]/../../../../../middleware`. This PR removes the normalization
logic so that the triggers appear as `/middleware` which is easier to
understand.
parent bef52342
......@@ -1747,7 +1747,7 @@ export default async function getBaseWebpackConfig(
exportRuntime: true,
appDirEnabled: hasAppDir,
}),
new ProfilingPlugin({ runWebpackSpan }),
new ProfilingPlugin({ runWebpackSpan, rootDir: dir }),
config.optimizeFonts &&
!dev &&
isNodeServer &&
......
import { NormalModule } from 'next/dist/compiled/webpack/webpack'
import type { Span } from '../../../trace'
import type { webpack } from 'next/dist/compiled/webpack/webpack'
import path from 'path'
const pluginName = 'ProfilingPlugin'
export const spans = new WeakMap<webpack.Compilation | webpack.Compiler, Span>()
......@@ -27,9 +28,17 @@ function inTraceLabelsSeal(label: string) {
export class ProfilingPlugin {
compiler: any
runWebpackSpan: Span
rootDir: string
constructor({ runWebpackSpan }: { runWebpackSpan: Span }) {
constructor({
runWebpackSpan,
rootDir,
}: {
runWebpackSpan: Span
rootDir: string
}) {
this.runWebpackSpan = runWebpackSpan
this.rootDir = rootDir
}
apply(compiler: any) {
this.traceTopLevelHooks(compiler)
......@@ -105,7 +114,9 @@ export class ProfilingPlugin {
onStart: (span) => webpackInvalidSpans.set(compiler, span),
onStop: () => webpackInvalidSpans.delete(compiler),
attrs: (fileName: any) => ({
trigger: fileName || 'manual',
trigger: fileName
? path.relative(this.rootDir, fileName).replaceAll(path.sep, '/')
: 'manual',
}),
}
)
......
......@@ -110,17 +110,6 @@ interface TraceMetadata {
shouldUploadFullTrace ||
EVENT_FILTER.has(event.name)
) {
if (
typeof event.tags.trigger === 'string' &&
path.isAbsolute(event.tags.trigger)
) {
event.tags.trigger =
'[project]/' +
path
.relative(projectDir, event.tags.trigger)
.replaceAll(path.sep, '/')
}
let trace = traces.get(event.traceId)
if (trace === undefined) {
trace = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment