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

Fix webpack 5 warning + disabling of profiling #21276

Merged
Merged
Changes from 4 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
19 changes: 17 additions & 2 deletions packages/next/build/webpack/plugins/profiling-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import { tracer } from '../../tracer'
import { webpack, isWebpack5 } from 'next/dist/compiled/webpack/webpack'

const pluginName = 'ProfilingPlugin'

export const spans = new WeakMap()

function getNormalModuleLoaderHook(compilation: any) {
if (isWebpack5) {
// @ts-ignore TODO: Remove ignore when webpack 5 is stable
return webpack.NormalModule.getCompilationHooks(compilation).loader
}

return compilation.hooks.normalModuleLoader
}

export class ProfilingPlugin {
apply(compiler: any) {
// Only enabled when instrumentation is loaded
if (!tracer.getCurrentSpan()) {
const currentSpan = tracer.getCurrentSpan()
console.log({
currentSpan,
isRecording: currentSpan?.isRecording(),
})
Copy link
Contributor

Choose a reason for hiding this comment

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

@timneutkens
Is this console.log kept intentionally?

Copy link
Member Author

@timneutkens timneutkens Jan 19, 2021

Choose a reason for hiding this comment

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

It wasn't, totally missed this! Thanks!

if (!currentSpan || !currentSpan.isRecording()) {
return
}

Expand All @@ -29,7 +44,7 @@ export class ProfilingPlugin {
})
})

compilation.hooks.normalModuleLoader.tap(
getNormalModuleLoaderHook(compilation).tap(
pluginName,
(loaderContext: any, module: any) => {
const parentSpan = spans.get(module)
Expand Down