Skip to content

Mixing node and edge instrumentations causes webpack errors #11823

Closed

Description

@r34son

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

8.0.0-beta.4

Framework Version

No response

Link to Sentry event

No response

SDK Setup

import { init } from '@sentry/nextjs';
import { nodeProfilingIntegration } from '@sentry/profiling-node';
import { SENTRY_CAPTURE_RATE, SENTRY_DSN } from 'sentry.constants.mjs';

export function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
init({
dsn: SENTRY_DSN,
debug: false,
tracesSampleRate: SENTRY_CAPTURE_RATE,
profilesSampleRate: SENTRY_CAPTURE_RATE,
environment: process.env.ENV,
integrations: [nodeProfilingIntegration()],
});
}
if (process.env.NEXT_RUNTIME === 'edge') {
init({
dsn: SENTRY_DSN,
tracesSampleRate: SENTRY_CAPTURE_RATE,
environment: process.env.ENV,
});
}
}

Steps to Reproduce

https://docs.sentry.io/platforms/javascript/guides/nextjs/migration/v7-to-v8/#opentelemetry-instrumentation
3 step says to remove instrumentation.node.ts. Tried it and it causes errors because now webpack emits one chunk for edge and node instrumentation. And it fails because node api is not available in edge.

Before i was using:

export async function register() {
  if (process.env.NEXT_RUNTIME === 'nodejs') {
    await import('./instrumentation.node');
  }
  if (process.env.NEXT_RUNTIME === 'edge') {
    await import('./instrumentation.edge');
  }
}

Should i use it? but i am not sure that this dynamic imports are good way to init sdk

Expected Result

Build without errors

Actual Result

next build

▲ Next.js 14.3.0-canary.28

  • Environments: .env.local
  • Experiments (use with caution):
    · webpackBuildWorker
    · instrumentationHook
    · preloadEntriesOnStart

Creating an optimized production build ...
Failed to compile.

./node_modules/.pnpm/detect-libc@2.0.3/node_modules/detect-libc/lib/detect-libc.js:6:1
Module not found: Can't resolve 'child_process'
4 | 'use strict';
5 |

6 | const childProcess = require('child_process');
| ^
7 | const { isLinux, getReport } = require('./process');
8 | const { LDD_PATH, readFile, readFileSync } = require('./filesystem');
9 |

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/.pnpm/@sentry+profiling-node@8.0.0-beta.4/node_modules/@sentry/profiling-node/lib/esm/index.js
./src/instrumentation.ts

./node_modules/.pnpm/detect-libc@2.0.3/node_modules/detect-libc/lib/filesystem.js:6:1
Module not found: Can't resolve 'fs'
4 | 'use strict';
5 |

6 | const fs = require('fs');
| ^
7 |
8 | /**
9 | * The path where we can find the ldd

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/.pnpm/detect-libc@2.0.3/node_modules/detect-libc/lib/detect-libc.js
./node_modules/.pnpm/@sentry+profiling-node@8.0.0-beta.4/node_modules/@sentry/profiling-node/lib/esm/index.js
./src/instrumentation.ts

node:module
Module build failed: UnhandledSchemeError: Reading from "node:module" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
at /Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:401799
at Hook.eval [as callAsync] (eval at create (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:13:28858), :6:1)
at Object.processResource (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:401724)
at processResource (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:5308)
at iteratePitchingLoaders (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:4667)
at runLoaders (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:8590)
at NormalModule.doBuild (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:401586)
at NormalModule.build (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:403614)
at /Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:82061
at NormalModule.needBuild (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:407746)

Import trace for requested module:
node:module
./node_modules/.pnpm/@sentry+profiling-node@8.0.0-beta.4/node_modules/@sentry/profiling-node/lib/esm/index.js

node:path
Module build failed: UnhandledSchemeError: Reading from "node:path" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
at /Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:401799
at Hook.eval [as callAsync] (eval at create (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:13:28858), :6:1)
at Object.processResource (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:401724)
at processResource (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:5308)
at iteratePitchingLoaders (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:4667)
at runLoaders (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:8590)
at NormalModule.doBuild (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:401586)
at NormalModule.build (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:403614)
at /Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:82061
at NormalModule.needBuild (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:407746)

Import trace for requested module:
node:path
./node_modules/.pnpm/@sentry+profiling-node@8.0.0-beta.4/node_modules/@sentry/profiling-node/lib/esm/index.js

node:url
Module build failed: UnhandledSchemeError: Reading from "node:url" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
at /Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:401799
at Hook.eval [as callAsync] (eval at create (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:13:28858), :6:1)
at Hook.CALL_ASYNC_DELEGATE [as callAsync] (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:13:26012)
at Object.processResource (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:401724)
at processResource (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:5308)
at iteratePitchingLoaders (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:4667)
at runLoaders (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:8590)
at NormalModule.doBuild (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:401586)
at NormalModule.build (/Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:403614)
at /Users/seitasanov/ownProjects/profile/node_modules/.pnpm/next@14.3.0-canary.28_@babel+core@7.24.1_@opentelemetry+api@1.8.0_@playwright+test@1.43.1_rea_h4jxyf2ocyapuotaulkocqpl24/node_modules/next/dist/compiled/webpack/bundle5.js:28:82061

Import trace for requested module:
node:url
./node_modules/.pnpm/@sentry+profiling-node@8.0.0-beta.4/node_modules/@sentry/profiling-node/lib/esm/index.js

Build failed because of webpack errors

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 2on Apr 27, 2024
  2. r34son commented on Apr 27, 2024

    @r34son
    Author

    Problem with @sentry/profiling-node integration

  3. JonasBa commented on Apr 29, 2024

    @JonasBa
    Contributor

    @r34son profiling will not work without a nodejs API, so I would recommend you remove this for edge runtime. I will need to look at how and if it's even possible to support this. I'm sorry if this isnt of much help.

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 2on Apr 29, 2024
  5. r34son commented on Apr 29, 2024

    @r34son
    Author

    @r34son profiling will not work without a nodejs API, so I would recommend you remove this for edge runtime. I will need to look at how and if it's even possible to support this. I'm sorry if this isnt of much help.

    It is actually the problem, because of one chunk emited for both runtimes

  6. moved this to Waiting for: Product Owner in GitHub Issues with 👀 2on Apr 29, 2024
  7. lforst commented on May 2, 2024

    @lforst
    Contributor

    It should be fine to inti the edge SDK with a dynamic import. If possible, try to leave the node SDK init synchronous.

  8. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 2on May 2, 2024
  9. r34son commented on May 2, 2024

    @r34son
    Author

    Thanks!

  10. r34son commented on May 2, 2024

    @r34son
    Author

    If I init sdk this way:

    import { init } from '@sentry/nextjs';
    import { nodeProfilingIntegration } from '@sentry/profiling-node';
    import { SENTRY_CAPTURE_RATE, SENTRY_DSN } from 'sentry.constants.mjs';
    
    export async function register() {
      if (process.env.NEXT_RUNTIME === 'nodejs') {
        init({
          dsn: SENTRY_DSN,
          debug: false,
          tracesSampleRate: SENTRY_CAPTURE_RATE,
          profilesSampleRate: SENTRY_CAPTURE_RATE,
          environment: process.env.ENV,
          integrations: [nodeProfilingIntegration()],
        });
      }
      if (process.env.NEXT_RUNTIME === 'edge') {
        await import('./instrumentation.edge');
      }
    }

    It somehow fails in turbopack:
    image

  11. r34son commented on May 2, 2024

    @r34son
    Author

    Only works importing @sentry/profiling-node dynamically:

    import { init } from '@sentry/nextjs';
    import { SENTRY_CAPTURE_RATE, SENTRY_DSN } from 'sentry.constants.mjs';
    
    export async function register() {
      if (process.env.NEXT_RUNTIME === 'nodejs') {
        const { nodeProfilingIntegration } = await import('@sentry/profiling-node');
        init({
          dsn: SENTRY_DSN,
          debug: false,
          tracesSampleRate: SENTRY_CAPTURE_RATE,
          profilesSampleRate: SENTRY_CAPTURE_RATE,
          environment: process.env.ENV,
          integrations: [nodeProfilingIntegration()],
        });
      }
      if (process.env.NEXT_RUNTIME === 'edge') {
        await import('./instrumentation.edge');
      }
    }
  12. lforst commented on May 3, 2024

    @lforst
    Contributor

    This is actually a good insight. Thanks for raising this! I see this as a documentation issue we need to resolve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions