UNPKG

@sentry/node

Version:

Sentry Node SDK using OpenTelemetry for performance instrumentation

203 lines (199 loc) • 8.11 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const core = require('@sentry/core'); const node_worker_threads = require('node:worker_threads'); const serverUtils = require('@sentry/server-utils'); const debugBuild = require('../debug-build.js'); const childProcess = require('../integrations/childProcess.js'); const console$1 = require('../integrations/console.js'); const context = require('../integrations/context.js'); const contextlines = require('../integrations/contextlines.js'); const index = require('../integrations/http/index.js'); const index$2 = require('../integrations/local-variables/index.js'); const modules = require('../integrations/modules.js'); const index$1 = require('../integrations/node-fetch/index.js'); const onuncaughtexception = require('../integrations/onuncaughtexception.js'); const onunhandledrejection = require('../integrations/onunhandledrejection.js'); const processSession = require('../integrations/processSession.js'); const spotlight = require('../integrations/spotlight.js'); const systemError = require('../integrations/systemError.js'); const workerThreads = require('../integrations/workerThreads.js'); const http = require('../transports/http.js'); const entryPoint = require('../utils/entry-point.js'); const spotlight$1 = require('../utils/spotlight.js'); const api = require('./api.js'); const client = require('./client.js'); const initOtel = require('./initOtel.js'); const vercel = require('./vercel.js'); function getBaseDefaultIntegrations() { return [ // Common core.eventFiltersIntegration(), core.functionToStringIntegration(), core.linkedErrorsIntegration(), core.dedupeIntegration(), core.requestDataIntegration(), systemError.systemErrorIntegration(), core.conversationIdIntegration(), // Native Wrappers console$1.consoleIntegration(), index.httpIntegration(), index$1.nativeNodeFetchIntegration(), // Global Handlers onuncaughtexception.onUncaughtExceptionIntegration(), onunhandledrejection.onUnhandledRejectionIntegration(), // Event Info contextlines.contextLinesIntegration(), index$2.localVariablesIntegration(), context.nodeContextIntegration(), childProcess.childProcessIntegration(), workerThreads.workerThreadsIntegration(), processSession.processSessionIntegration(), modules.modulesIntegration(), // Framework-level integrations ...serverUtils.getErrorIntegrations() ]; } function getDefaultIntegrationsWithoutPerformance() { return getBaseDefaultIntegrations(); } function getDefaultIntegrations(options) { return [ ...getDefaultIntegrationsWithoutPerformance(), // We only add tracing-only integrations if tracing is enabled ...core.hasSpansEnabled(options) ? serverUtils.getTracingIntegrations() : [] ]; } function init(options = {}) { return _init(options, getDefaultIntegrations); } function initWithoutDefaultIntegrations(options = {}) { return _init(options, () => []); } function _init(options = {}, getDefaultIntegrationsImpl) { if (!node_worker_threads.isMainThread && !node_worker_threads.parentPort) { return void 0; } if (entryPoint.getEntryPointType() === "require") { core.consoleSandbox(() => { console.warn( "[Sentry] Initializing the SDK via the Node `--require` flag is no longer supported, because Node re-runs `--require` preloads on its module loader thread. Use `--import` instead: `node --import ./instrument.js app.js`" ); }); } core.applySdkMetadata(options, "node"); if (core.envToBool(options.debug ?? process.env.SENTRY_DEBUG)) { if (debugBuild.DEBUG_BUILD) { core.debug.enable(); } else { core.consoleSandbox(() => { console.warn("[Sentry] Cannot initialize SDK with `debug` option using a non-debug bundle."); }); } } const optionsWithResolvedTracing = { ...options, tracesSampleRate: getTracesSampleRate(options.tracesSampleRate) }; const defaultIntegrations = options.defaultIntegrations ?? getDefaultIntegrationsImpl(optionsWithResolvedTracing); const clientOptions = getClientOptions({ ...options, defaultIntegrations }, getDefaultIntegrationsImpl); core._INTERNAL_warnIfClientIsActive(); const scope = core.getCurrentScope(); scope.update(clientOptions.initialScope); if (clientOptions.spotlight && !clientOptions.integrations.some(({ name }) => name === spotlight.INTEGRATION_NAME)) { clientOptions.integrations.push( spotlight.spotlightIntegration({ sidecarUrl: typeof clientOptions.spotlight === "string" ? clientOptions.spotlight : void 0 }) ); } const client$1 = new client.NodeClient(clientOptions); core.getCurrentScope().setClient(client$1); client$1.init(); core.debug.log(`SDK initialized from CommonJS`); client$1.startClientReportTracking(); updateScopeFromEnvVariables(); if (process.env.VERCEL) { vercel.setupVercelKeepAlive(client$1); } if (clientOptions.enableOpenTelemetrySetup) { initOtel.initOpenTelemetry(client$1); } serverUtils.detectOrchestrionSetup(); return client$1; } function getClientOptions(options, getDefaultIntegrationsImpl) { const release = getRelease(options.release); const spotlight = spotlight$1.getSpotlightConfig(options.spotlight); const tracesSampleRate = getTracesSampleRate(options.tracesSampleRate); const traceLifecycle = getTraceLifecycle(options.traceLifecycle); const mergedOptions = { ...options, dsn: options.dsn ?? process.env.SENTRY_DSN, environment: options.environment ?? process.env.SENTRY_ENVIRONMENT, sendClientReports: options.sendClientReports ?? true, transport: options.transport ?? http.makeNodeTransport, stackParser: core.stackParserFromStackParserOptions(options.stackParser || api.defaultStackParser), release, tracesSampleRate, spotlight, traceLifecycle, // Most Node-based SDKs default to running without a Sentry OpenTelemetry tracer provider. SDKs // that need OTel spans surfaced in Sentry (nextjs, sveltekit) opt back in by passing `true`. enableOpenTelemetrySetup: options.enableOpenTelemetrySetup ?? false, debug: core.envToBool(options.debug ?? process.env.SENTRY_DEBUG) }; const integrations = options.integrations; const defaultIntegrations = options.defaultIntegrations ?? getDefaultIntegrationsImpl(mergedOptions); const resolvedIntegrations = core.getIntegrationsToSetup({ defaultIntegrations, integrations }); return { ...mergedOptions, integrations: resolvedIntegrations }; } function getRelease(release) { if (release !== void 0) { return release; } const detectedRelease = api.getSentryRelease(); if (detectedRelease !== void 0) { return detectedRelease; } return void 0; } function getTracesSampleRate(tracesSampleRate) { if (tracesSampleRate !== void 0) { return tracesSampleRate; } const sampleRateFromEnv = process.env.SENTRY_TRACES_SAMPLE_RATE; if (!sampleRateFromEnv) { return void 0; } const parsed = parseFloat(sampleRateFromEnv); return isFinite(parsed) ? parsed : void 0; } function getTraceLifecycle(traceLifecycle) { if (traceLifecycle !== void 0) { return traceLifecycle; } const lifecycleFromEnv = process.env.SENTRY_TRACE_LIFECYCLE; if (lifecycleFromEnv === "stream" || lifecycleFromEnv === "static") { return lifecycleFromEnv; } return "stream"; } function updateScopeFromEnvVariables() { if (core.envToBool(process.env.SENTRY_USE_ENVIRONMENT) !== false) { const sentryTraceEnv = process.env.SENTRY_TRACE; const baggageEnv = process.env.SENTRY_BAGGAGE; const propagationContext = core.propagationContextFromHeaders(sentryTraceEnv, baggageEnv); core.getCurrentScope().setPropagationContext(propagationContext); } } exports.getDefaultIntegrations = getDefaultIntegrations; exports.getDefaultIntegrationsWithoutPerformance = getDefaultIntegrationsWithoutPerformance; exports.init = init; exports.initWithoutDefaultIntegrations = initWithoutDefaultIntegrations; //# sourceMappingURL=index.js.map