Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ export default async function getBaseWebpackConfig(
exportRuntime: true,
appDirEnabled: hasAppDir,
}),
new ProfilingPlugin({ runWebpackSpan }),
new ProfilingPlugin({ runWebpackSpan, rootDir: dir }),
config.optimizeFonts &&
!dev &&
isNodeServer &&
Expand Down
15 changes: 13 additions & 2 deletions packages/next/src/build/webpack/plugins/profiling-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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>()
Expand All @@ -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)
Expand Down Expand Up @@ -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',
}),
}
)
Expand Down
11 changes: 0 additions & 11 deletions packages/next/src/trace/trace-uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '/')
Comment on lines -117 to -121
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to ensure we aren't passing through the full absolute path or is this only the case for middleware specifically?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only other place we set this right now is in webpack when a file is modified. Otherwise we are passing a target path (like /api/foo or /app/[slug]/home). I moved the absolute path logic to the webpack code.

Please take another look.

cc @wbinnssmith

}

let trace = traces.get(event.traceId)
if (trace === undefined) {
trace = []
Expand Down
Loading