(options: VercelEdgeOptions = {})
| 62 | |
| 63 | /** Inits the Sentry NextJS SDK on the Edge Runtime. */ |
| 64 | export 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 | |
| 121 | function validateOpenTelemetrySetup(): void { |
no test coverage detected