* Initialize Sentry for Node in light mode.
(
_options: NodeOptions | undefined = {},
getDefaultIntegrationsImpl: (options: Options) => Integration[],
)
| 81 | * Initialize Sentry for Node in light mode. |
| 82 | */ |
| 83 | function _init( |
| 84 | _options: NodeOptions | undefined = {}, |
| 85 | getDefaultIntegrationsImpl: (options: Options) => Integration[], |
| 86 | ): LightNodeClient { |
| 87 | const options = getClientOptions(_options, getDefaultIntegrationsImpl); |
| 88 | |
| 89 | if (options.debug === true) { |
| 90 | if (DEBUG_BUILD) { |
| 91 | debug.enable(); |
| 92 | } else { |
| 93 | // use `console.warn` rather than `debug.warn` since by non-debug bundles have all `debug.x` statements stripped |
| 94 | consoleSandbox(() => { |
| 95 | // eslint-disable-next-line no-console |
| 96 | console.warn('[Sentry] Cannot initialize SDK with `debug` option using a non-debug bundle.'); |
| 97 | }); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // Use AsyncLocalStorage-based context strategy instead of OpenTelemetry |
| 102 | setAsyncLocalStorageAsyncContextStrategy(); |
| 103 | |
| 104 | const scope = getCurrentScope(); |
| 105 | scope.update(options.initialScope); |
| 106 | |
| 107 | if (options.spotlight && !options.integrations.some(({ name }) => name === SPOTLIGHT_INTEGRATION_NAME)) { |
| 108 | options.integrations.push( |
| 109 | spotlightIntegration({ |
| 110 | sidecarUrl: typeof options.spotlight === 'string' ? options.spotlight : undefined, |
| 111 | }), |
| 112 | ); |
| 113 | } |
| 114 | |
| 115 | applySdkMetadata(options, 'node-light', ['node-core']); |
| 116 | |
| 117 | const client = new LightNodeClient(options); |
| 118 | // The client is on the current scope, from where it generally is inherited |
| 119 | getCurrentScope().setClient(client); |
| 120 | |
| 121 | client.init(); |
| 122 | |
| 123 | debug.log(`SDK initialized from ${isCjs() ? 'CommonJS' : 'ESM'} (light mode)`); |
| 124 | |
| 125 | client.startClientReportTracking(); |
| 126 | |
| 127 | updateScopeFromEnvVariables(); |
| 128 | |
| 129 | // Ensure we flush events when vercel functions are ended |
| 130 | // See: https://vercel.com/docs/functions/functions-api-reference#sigterm-signal |
| 131 | if (process.env.VERCEL) { |
| 132 | process.on('SIGTERM', async () => { |
| 133 | // We have 500ms for processing here, so we try to make sure to have enough time to send the events |
| 134 | await client.flush(200); |
| 135 | }); |
| 136 | } |
| 137 | |
| 138 | return client; |
| 139 | } |
| 140 |
no test coverage detected