123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- var {
- _optionalChain
- } = require('@sentry/utils');
- Object.defineProperty(exports, '__esModule', { value: true });
- const core = require('@sentry/core');
- const utils = require('@sentry/utils');
- const index$2 = require('./async/index.js');
- const client = require('./client.js');
- const console = require('./integrations/console.js');
- const context = require('./integrations/context.js');
- const contextlines = require('./integrations/contextlines.js');
- const http = require('./integrations/http.js');
- const index$1 = require('./integrations/local-variables/index.js');
- const modules = require('./integrations/modules.js');
- const onuncaughtexception = require('./integrations/onuncaughtexception.js');
- const onunhandledrejection = require('./integrations/onunhandledrejection.js');
- const spotlight = require('./integrations/spotlight.js');
- const index = require('./integrations/undici/index.js');
- const module$1 = require('./module.js');
- const http$1 = require('./transports/http.js');
- const defaultIntegrations = [
-
- core.inboundFiltersIntegration(),
- core.functionToStringIntegration(),
- core.linkedErrorsIntegration(),
- core.requestDataIntegration(),
-
- console.consoleIntegration(),
- http.httpIntegration(),
- index.nativeNodeFetchintegration(),
-
- onuncaughtexception.onUncaughtExceptionIntegration(),
- onunhandledrejection.onUnhandledRejectionIntegration(),
-
- contextlines.contextLinesIntegration(),
- index$1.localVariablesIntegration(),
- context.nodeContextIntegration(),
- modules.modulesIntegration(),
- ];
- function getDefaultIntegrations(_options) {
- const carrier = core.getMainCarrier();
- const autoloadedIntegrations = _optionalChain([carrier, 'access', _ => _.__SENTRY__, 'optionalAccess', _2 => _2.integrations]) || [];
- return [
-
- ...defaultIntegrations,
- ...autoloadedIntegrations,
- ];
- }
- function init(options = {}) {
- index$2.setNodeAsyncContextStrategy();
- if (options.defaultIntegrations === undefined) {
- options.defaultIntegrations = getDefaultIntegrations();
- }
- if (options.dsn === undefined && process.env.SENTRY_DSN) {
- options.dsn = process.env.SENTRY_DSN;
- }
- const sentryTracesSampleRate = process.env.SENTRY_TRACES_SAMPLE_RATE;
- if (options.tracesSampleRate === undefined && sentryTracesSampleRate) {
- const tracesSampleRate = parseFloat(sentryTracesSampleRate);
- if (isFinite(tracesSampleRate)) {
- options.tracesSampleRate = tracesSampleRate;
- }
- }
- if (options.release === undefined) {
- const detectedRelease = getSentryRelease();
- if (detectedRelease !== undefined) {
- options.release = detectedRelease;
- } else {
-
- options.autoSessionTracking = false;
- }
- }
- if (options.environment === undefined && process.env.SENTRY_ENVIRONMENT) {
- options.environment = process.env.SENTRY_ENVIRONMENT;
- }
- if (options.autoSessionTracking === undefined && options.dsn !== undefined) {
- options.autoSessionTracking = true;
- }
- if (options.instrumenter === undefined) {
- options.instrumenter = 'sentry';
- }
-
- const clientOptions = {
- ...options,
- stackParser: utils.stackParserFromStackParserOptions(options.stackParser || defaultStackParser),
- integrations: core.getIntegrationsToSetup(options),
- transport: options.transport || http$1.makeNodeTransport,
- };
- core.initAndBind(options.clientClass || client.NodeClient, clientOptions);
- if (options.autoSessionTracking) {
- startSessionTracking();
- }
- updateScopeFromEnvVariables();
- if (options.spotlight) {
- const client = core.getClient();
- if (client && client.addIntegration) {
-
-
- const integrations = client.getOptions().integrations;
- for (const integration of integrations) {
- client.addIntegration(integration);
- }
- client.addIntegration(
- spotlight.spotlightIntegration({ sidecarUrl: typeof options.spotlight === 'string' ? options.spotlight : undefined }),
- );
- }
- }
- }
- function isAutoSessionTrackingEnabled(client) {
- if (client === undefined) {
- return false;
- }
- const clientOptions = client && client.getOptions();
- if (clientOptions && clientOptions.autoSessionTracking !== undefined) {
- return clientOptions.autoSessionTracking;
- }
- return false;
- }
- function getSentryRelease(fallback) {
-
- if (process.env.SENTRY_RELEASE) {
- return process.env.SENTRY_RELEASE;
- }
-
- if (utils.GLOBAL_OBJ.SENTRY_RELEASE && utils.GLOBAL_OBJ.SENTRY_RELEASE.id) {
- return utils.GLOBAL_OBJ.SENTRY_RELEASE.id;
- }
- return (
-
- process.env.GITHUB_SHA ||
-
- process.env.COMMIT_REF ||
-
- process.env.VERCEL_GIT_COMMIT_SHA ||
- process.env.VERCEL_GITHUB_COMMIT_SHA ||
- process.env.VERCEL_GITLAB_COMMIT_SHA ||
- process.env.VERCEL_BITBUCKET_COMMIT_SHA ||
-
- process.env.ZEIT_GITHUB_COMMIT_SHA ||
- process.env.ZEIT_GITLAB_COMMIT_SHA ||
- process.env.ZEIT_BITBUCKET_COMMIT_SHA ||
-
- process.env.CF_PAGES_COMMIT_SHA ||
- fallback
- );
- }
- const defaultStackParser = utils.createStackParser(utils.nodeStackLineParser(module$1.createGetModuleFromFilename()));
- function startSessionTracking() {
- core.startSession();
-
-
-
-
- process.on('beforeExit', () => {
- const session = core.getIsolationScope().getSession();
- const terminalStates = ['exited', 'crashed'];
-
-
-
-
- if (session && !terminalStates.includes(session.status)) {
- core.endSession();
- }
- });
- }
- function updateScopeFromEnvVariables() {
- const sentryUseEnvironment = (process.env.SENTRY_USE_ENVIRONMENT || '').toLowerCase();
- if (!['false', 'n', 'no', 'off', '0'].includes(sentryUseEnvironment)) {
- const sentryTraceEnv = process.env.SENTRY_TRACE;
- const baggageEnv = process.env.SENTRY_BAGGAGE;
- const propagationContext = utils.propagationContextFromHeaders(sentryTraceEnv, baggageEnv);
- core.getCurrentScope().setPropagationContext(propagationContext);
- }
- }
- exports.defaultIntegrations = defaultIntegrations;
- exports.defaultStackParser = defaultStackParser;
- exports.getDefaultIntegrations = getDefaultIntegrations;
- exports.getSentryRelease = getSentryRelease;
- exports.init = init;
- exports.isAutoSessionTrackingEnabled = isAutoSessionTrackingEnabled;
|