MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / init

Function init

packages/nextjs/src/edge/index.ts:53–193  ·  view source on GitHub ↗
(options: VercelEdgeOptions = {})

Source from the content-addressed store, hash-verified

51
52/** Inits the Sentry NextJS SDK on the Edge Runtime. */
53export function init(options: VercelEdgeOptions = {}): void {
54 registerSpanErrorInstrumentation();
55
56 if (isBuild()) {
57 return;
58 }
59
60 if (!DEBUG_BUILD && options.debug) {
61 // eslint-disable-next-line no-console
62 console.warn(
63 '[@sentry/nextjs] You have enabled `debug: true`, but Sentry debug logging was removed from your bundle (likely via `withSentryConfig({ disableLogger: true })` / `webpack.treeshake.removeDebugLogging: true`). Set that option to `false` to see Sentry debug output.',
64 );
65 }
66
67 const customDefaultIntegrations = getDefaultIntegrations(options);
68
69 // This value is injected at build time, based on the output directory specified in the build config. Though a default
70 // is set there, we set it here as well, just in case something has gone wrong with the injection.
71 const distDirName = process.env._sentryRewriteFramesDistDir || globalWithInjectedValues._sentryRewriteFramesDistDir;
72
73 if (distDirName) {
74 customDefaultIntegrations.push(distDirRewriteFramesIntegration({ distDirName }));
75 }
76
77 // Detect if running on OpenNext/Cloudflare
78 const isRunningOnCloudflare = isCloudflareWaitUntilAvailable();
79
80 const opts: VercelEdgeOptions = {
81 defaultIntegrations: customDefaultIntegrations,
82 environment: options.environment || process.env.SENTRY_ENVIRONMENT,
83 release: process.env._sentryRelease || globalWithInjectedValues._sentryRelease,
84 ...options,
85 // Override runtime to 'cloudflare' when running on OpenNext/Cloudflare
86 ...(isRunningOnCloudflare && { runtime: { name: 'cloudflare' } }),
87 };
88
89 const nextjsIgnoreSpans: NonNullable<VercelEdgeOptions['ignoreSpans']> = [
90 // (set in `dropMiddlewareTunnelRequests` during `spanStart`)
91 { attributes: { [TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION]: true } },
92 ];
93 opts.ignoreSpans = [...(opts.ignoreSpans || []), ...nextjsIgnoreSpans];
94
95 // Use appropriate SDK metadata based on the runtime environment
96 if (isRunningOnCloudflare) {
97 applySdkMetadata(opts, 'nextjs', ['nextjs', 'cloudflare']);
98 } else {
99 applySdkMetadata(opts, 'nextjs', ['nextjs', 'vercel-edge']);
100 }
101
102 const client = vercelEdgeInit(opts);
103
104 client?.on('spanStart', span => {
105 const spanAttributes = spanToJSON(span).data;
106 const rootSpan = getRootSpan(span);
107 const isRootSpan = span === rootSpan;
108
109 dropMiddlewareTunnelRequests(span, spanAttributes);
110

Callers 2

edgeSdk.test.tsFile · 0.90

Calls 15

isBuildFunction · 0.90
getDefaultIntegrationsFunction · 0.90
applySdkMetadataFunction · 0.90
spanToJSONFunction · 0.90
getCapturedScopesOnSpanFunction · 0.90
getIsolationScopeFunction · 0.90
getCurrentScopeFunction · 0.90
getScopesFromContextFunction · 0.90
setCapturedScopesOnSpanFunction · 0.90

Tested by

no test coverage detected