Closed r34son closed 2 weeks ago
Problem with @sentry/profiling-node
integration
@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.
@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
It should be fine to inti the edge SDK with a dynamic import. If possible, try to leave the node SDK init synchronous.
Thanks!
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:
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');
}
}
This is actually a good insight. Thanks for raising this! I see this as a documentation issue we need to resolve.
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:
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.js 14.3.0-canary.28
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 |
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 |
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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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/nodemodules/.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