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

Function _init

packages/node-core/src/light/sdk.ts:83–139  ·  view source on GitHub ↗

* Initialize Sentry for Node in light mode.

(
  _options: NodeOptions | undefined = {},
  getDefaultIntegrationsImpl: (options: Options) => Integration[],
)

Source from the content-addressed store, hash-verified

81 * Initialize Sentry for Node in light mode.
82 */
83function _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

Callers 2

initFunction · 0.70

Calls 15

flushMethod · 0.95
consoleSandboxFunction · 0.90
getCurrentScopeFunction · 0.90
applySdkMetadataFunction · 0.90
isCjsFunction · 0.90
pushMethod · 0.80
setClientMethod · 0.80
getClientOptionsFunction · 0.70
enableMethod · 0.65

Tested by

no test coverage detected