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

Function init

packages/vercel-edge/src/sdk.ts:64–119  ·  view source on GitHub ↗
(options: VercelEdgeOptions = {})

Source from the content-addressed store, hash-verified

62
63/** Inits the Sentry NextJS SDK on the Edge Runtime. */
64export function init(options: VercelEdgeOptions = {}): Client | undefined {
65 // We force skipOpenTelemetrySetup: true here, because this triggers the custom lookup for the AsyncLocalStorage instance
66 // Since we use a custom Context Manager here (because AsyncLocalStorage is looked up differently than in Node), we need to do this
67 setOpenTelemetryContextAsyncContextStrategy({ skipOpenTelemetrySetup: true });
68
69 const scope = getCurrentScope();
70 scope.update(options.initialScope);
71
72 if (options.defaultIntegrations === undefined) {
73 options.defaultIntegrations = getDefaultIntegrations(options);
74 }
75
76 if (options.dsn === undefined && process.env.SENTRY_DSN) {
77 options.dsn = process.env.SENTRY_DSN;
78 }
79
80 if (options.tracesSampleRate === undefined && process.env.SENTRY_TRACES_SAMPLE_RATE) {
81 const tracesSampleRate = parseFloat(process.env.SENTRY_TRACES_SAMPLE_RATE);
82 if (isFinite(tracesSampleRate)) {
83 options.tracesSampleRate = tracesSampleRate;
84 }
85 }
86
87 if (options.release === undefined) {
88 const detectedRelease = getSentryRelease();
89 if (detectedRelease !== undefined) {
90 options.release = detectedRelease;
91 }
92 }
93
94 options.environment =
95 options.environment || process.env.SENTRY_ENVIRONMENT || getVercelEnv(false) || process.env.NODE_ENV;
96
97 const client = new VercelEdgeClient({
98 ...options,
99 stackParser: stackParserFromStackParserOptions(options.stackParser || nodeStackParser),
100 integrations: getIntegrationsToSetup(options),
101 transport: options.transport || makeEdgeTransport,
102 });
103 // The client is on the current scope, from where it generally is inherited
104 getCurrentScope().setClient(client);
105
106 client.init();
107
108 // If users opt-out of this, they _have_ to set up OpenTelemetry themselves
109 // There is no way to use this SDK without OpenTelemetry!
110 if (!options.skipOpenTelemetrySetup) {
111 setupOtel(client);
112 validateOpenTelemetrySetup();
113 }
114
115 enhanceDscWithOpenTelemetryRootSpanName(client);
116 setupEventContextTrace(client);
117
118 return client;
119}
120
121function validateOpenTelemetrySetup(): void {

Callers 1

sdk.test.tsFile · 0.90

Calls 14

getCurrentScopeFunction · 0.90
getVercelEnvFunction · 0.90
getIntegrationsToSetupFunction · 0.90
setupEventContextTraceFunction · 0.90
setClientMethod · 0.80
getDefaultIntegrationsFunction · 0.70
getSentryReleaseFunction · 0.70
setupOtelFunction · 0.70

Tested by

no test coverage detected