@sentry/node 8.0.0 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/cron/common.js +56 -0
- package/cjs/cron/common.js.map +1 -0
- package/cjs/cron/cron.js +112 -0
- package/cjs/cron/cron.js.map +1 -0
- package/cjs/cron/index.js +15 -0
- package/cjs/cron/index.js.map +1 -0
- package/cjs/cron/node-cron.js +72 -0
- package/cjs/cron/node-cron.js.map +1 -0
- package/cjs/cron/node-schedule.js +69 -0
- package/cjs/cron/node-schedule.js.map +1 -0
- package/cjs/debug-build.js +11 -0
- package/cjs/debug-build.js.map +1 -0
- package/cjs/index.js +85 -4018
- package/cjs/index.js.map +1 -1
- package/cjs/integrations/anr/index.js +211 -0
- package/cjs/integrations/anr/index.js.map +1 -0
- package/cjs/integrations/console.js +40 -0
- package/cjs/integrations/console.js.map +1 -0
- package/cjs/integrations/context.js +435 -0
- package/cjs/integrations/context.js.map +1 -0
- package/cjs/integrations/contextlines.js +137 -0
- package/cjs/integrations/contextlines.js.map +1 -0
- package/cjs/integrations/http.js +161 -0
- package/cjs/integrations/http.js.map +1 -0
- package/cjs/integrations/local-variables/common.js +87 -0
- package/cjs/integrations/local-variables/common.js.map +1 -0
- package/cjs/integrations/local-variables/index.js +12 -0
- package/cjs/integrations/local-variables/index.js.map +1 -0
- package/cjs/integrations/local-variables/local-variables-async.js +149 -0
- package/cjs/integrations/local-variables/local-variables-async.js.map +1 -0
- package/cjs/integrations/local-variables/local-variables-sync.js +376 -0
- package/cjs/integrations/local-variables/local-variables-sync.js.map +1 -0
- package/cjs/integrations/modules.js +99 -0
- package/cjs/integrations/modules.js.map +1 -0
- package/cjs/integrations/node-fetch.js +81 -0
- package/cjs/integrations/node-fetch.js.map +1 -0
- package/cjs/integrations/onuncaughtexception.js +135 -0
- package/cjs/integrations/onuncaughtexception.js.map +1 -0
- package/cjs/integrations/onunhandledrejection.js +90 -0
- package/cjs/integrations/onunhandledrejection.js.map +1 -0
- package/cjs/integrations/spotlight.js +109 -0
- package/cjs/integrations/spotlight.js.map +1 -0
- package/cjs/integrations/tracing/connect.js +41 -0
- package/cjs/integrations/tracing/connect.js.map +1 -0
- package/cjs/integrations/tracing/express.js +127 -0
- package/cjs/integrations/tracing/express.js.map +1 -0
- package/cjs/integrations/tracing/fastify.js +84 -0
- package/cjs/integrations/tracing/fastify.js.map +1 -0
- package/cjs/integrations/tracing/graphql.js +32 -0
- package/cjs/integrations/tracing/graphql.js.map +1 -0
- package/cjs/integrations/tracing/hapi/index.js +106 -0
- package/cjs/integrations/tracing/hapi/index.js.map +1 -0
- package/cjs/integrations/tracing/index.js +43 -0
- package/cjs/integrations/tracing/index.js.map +1 -0
- package/cjs/integrations/tracing/koa.js +60 -0
- package/cjs/integrations/tracing/koa.js.map +1 -0
- package/cjs/integrations/tracing/mongo.js +31 -0
- package/cjs/integrations/tracing/mongo.js.map +1 -0
- package/cjs/integrations/tracing/mongoose.js +31 -0
- package/cjs/integrations/tracing/mongoose.js.map +1 -0
- package/cjs/integrations/tracing/mysql.js +24 -0
- package/cjs/integrations/tracing/mysql.js.map +1 -0
- package/cjs/integrations/tracing/mysql2.js +31 -0
- package/cjs/integrations/tracing/mysql2.js.map +1 -0
- package/cjs/integrations/tracing/nest.js +69 -0
- package/cjs/integrations/tracing/nest.js.map +1 -0
- package/cjs/integrations/tracing/postgres.js +32 -0
- package/cjs/integrations/tracing/postgres.js.map +1 -0
- package/cjs/integrations/tracing/prisma.js +48 -0
- package/cjs/integrations/tracing/prisma.js.map +1 -0
- package/cjs/integrations/tracing/redis.js +29 -0
- package/cjs/integrations/tracing/redis.js.map +1 -0
- package/cjs/nodeVersion.js +10 -0
- package/cjs/nodeVersion.js.map +1 -0
- package/cjs/otel/contextManager.js +16 -0
- package/cjs/otel/contextManager.js.map +1 -0
- package/cjs/proxy/base.js +127 -0
- package/cjs/proxy/base.js.map +1 -0
- package/cjs/proxy/index.js +178 -0
- package/cjs/proxy/index.js.map +1 -0
- package/cjs/proxy/parse-proxy-response.js +104 -0
- package/cjs/proxy/parse-proxy-response.js.map +1 -0
- package/cjs/sdk/api.js +45 -0
- package/cjs/sdk/api.js.map +1 -0
- package/cjs/sdk/client.js +63 -0
- package/cjs/sdk/client.js.map +1 -0
- package/cjs/sdk/init.js +318 -0
- package/cjs/sdk/init.js.map +1 -0
- package/cjs/sdk/initOtel.js +58 -0
- package/cjs/sdk/initOtel.js.map +1 -0
- package/cjs/sdk/scope.js +18 -0
- package/cjs/sdk/scope.js.map +1 -0
- package/cjs/transports/http.js +163 -0
- package/cjs/transports/http.js.map +1 -0
- package/cjs/utils/addOriginToSpan.js +11 -0
- package/cjs/utils/addOriginToSpan.js.map +1 -0
- package/cjs/utils/errorhandling.js +44 -0
- package/cjs/utils/errorhandling.js.map +1 -0
- package/cjs/utils/getRequestUrl.js +18 -0
- package/cjs/utils/getRequestUrl.js.map +1 -0
- package/cjs/utils/module.js +62 -0
- package/cjs/utils/module.js.map +1 -0
- package/esm/cron/common.js +54 -0
- package/esm/cron/common.js.map +1 -0
- package/esm/cron/cron.js +110 -0
- package/esm/cron/cron.js.map +1 -0
- package/esm/cron/index.js +13 -0
- package/esm/cron/index.js.map +1 -0
- package/esm/cron/node-cron.js +67 -0
- package/esm/cron/node-cron.js.map +1 -0
- package/esm/cron/node-schedule.js +64 -0
- package/esm/cron/node-schedule.js.map +1 -0
- package/esm/debug-build.js +9 -0
- package/esm/debug-build.js.map +1 -0
- package/esm/index.js +35 -3973
- package/esm/index.js.map +1 -1
- package/esm/integrations/anr/index.js +204 -0
- package/esm/integrations/anr/index.js.map +1 -0
- package/esm/integrations/anr/worker-script.js +2 -2
- package/esm/integrations/console.js +38 -0
- package/esm/integrations/console.js.map +1 -0
- package/esm/integrations/context.js +427 -0
- package/esm/integrations/context.js.map +1 -0
- package/esm/integrations/contextlines.js +131 -0
- package/esm/integrations/contextlines.js.map +1 -0
- package/esm/integrations/http.js +156 -0
- package/esm/integrations/http.js.map +1 -0
- package/esm/integrations/local-variables/common.js +81 -0
- package/esm/integrations/local-variables/common.js.map +1 -0
- package/esm/integrations/local-variables/index.js +10 -0
- package/esm/integrations/local-variables/index.js.map +1 -0
- package/esm/integrations/local-variables/local-variables-async.js +143 -0
- package/esm/integrations/local-variables/local-variables-async.js.map +1 -0
- package/esm/integrations/local-variables/local-variables-sync.js +370 -0
- package/esm/integrations/local-variables/local-variables-sync.js.map +1 -0
- package/esm/integrations/local-variables/worker-script.js +1 -1
- package/esm/integrations/modules.js +97 -0
- package/esm/integrations/modules.js.map +1 -0
- package/esm/integrations/node-fetch.js +79 -0
- package/esm/integrations/node-fetch.js.map +1 -0
- package/esm/integrations/onuncaughtexception.js +132 -0
- package/esm/integrations/onuncaughtexception.js.map +1 -0
- package/esm/integrations/onunhandledrejection.js +87 -0
- package/esm/integrations/onunhandledrejection.js.map +1 -0
- package/esm/integrations/spotlight.js +106 -0
- package/esm/integrations/spotlight.js.map +1 -0
- package/esm/integrations/tracing/connect.js +38 -0
- package/esm/integrations/tracing/connect.js.map +1 -0
- package/esm/integrations/tracing/express.js +120 -0
- package/esm/integrations/tracing/express.js.map +1 -0
- package/esm/integrations/tracing/fastify.js +78 -0
- package/esm/integrations/tracing/fastify.js.map +1 -0
- package/esm/integrations/tracing/graphql.js +30 -0
- package/esm/integrations/tracing/graphql.js.map +1 -0
- package/esm/integrations/tracing/hapi/index.js +99 -0
- package/esm/integrations/tracing/hapi/index.js.map +1 -0
- package/esm/integrations/tracing/index.js +41 -0
- package/esm/integrations/tracing/index.js.map +1 -0
- package/esm/integrations/tracing/koa.js +57 -0
- package/esm/integrations/tracing/koa.js.map +1 -0
- package/esm/integrations/tracing/mongo.js +29 -0
- package/esm/integrations/tracing/mongo.js.map +1 -0
- package/esm/integrations/tracing/mongoose.js +29 -0
- package/esm/integrations/tracing/mongoose.js.map +1 -0
- package/esm/integrations/tracing/mysql.js +22 -0
- package/esm/integrations/tracing/mysql.js.map +1 -0
- package/esm/integrations/tracing/mysql2.js +29 -0
- package/esm/integrations/tracing/mysql2.js.map +1 -0
- package/esm/integrations/tracing/nest.js +63 -0
- package/esm/integrations/tracing/nest.js.map +1 -0
- package/esm/integrations/tracing/postgres.js +30 -0
- package/esm/integrations/tracing/postgres.js.map +1 -0
- package/esm/integrations/tracing/prisma.js +43 -0
- package/esm/integrations/tracing/prisma.js.map +1 -0
- package/esm/integrations/tracing/redis.js +27 -0
- package/esm/integrations/tracing/redis.js.map +1 -0
- package/esm/nodeVersion.js +7 -0
- package/esm/nodeVersion.js.map +1 -0
- package/esm/otel/contextManager.js +14 -0
- package/esm/otel/contextManager.js.map +1 -0
- package/esm/proxy/base.js +122 -0
- package/esm/proxy/base.js.map +1 -0
- package/esm/proxy/index.js +172 -0
- package/esm/proxy/index.js.map +1 -0
- package/esm/proxy/parse-proxy-response.js +102 -0
- package/esm/proxy/parse-proxy-response.js.map +1 -0
- package/esm/sdk/api.js +42 -0
- package/esm/sdk/api.js.map +1 -0
- package/esm/sdk/client.js +58 -0
- package/esm/sdk/client.js.map +1 -0
- package/esm/sdk/init.js +312 -0
- package/esm/sdk/init.js.map +1 -0
- package/esm/sdk/initOtel.js +55 -0
- package/esm/sdk/initOtel.js.map +1 -0
- package/esm/sdk/scope.js +16 -0
- package/esm/sdk/scope.js.map +1 -0
- package/esm/transports/http.js +158 -0
- package/esm/transports/http.js.map +1 -0
- package/esm/utils/addOriginToSpan.js +9 -0
- package/esm/utils/addOriginToSpan.js.map +1 -0
- package/esm/utils/errorhandling.js +42 -0
- package/esm/utils/errorhandling.js.map +1 -0
- package/esm/utils/getRequestUrl.js +16 -0
- package/esm/utils/getRequestUrl.js.map +1 -0
- package/esm/utils/module.js +60 -0
- package/esm/utils/module.js.map +1 -0
- package/package.json +16 -16
- package/types/index.d.ts +2 -2
- package/types/index.d.ts.map +1 -1
- package/types/integrations/tracing/hapi/index.d.ts.map +1 -1
- package/types/integrations/tracing/koa.d.ts.map +1 -1
- package/types/sdk/init.d.ts +4 -0
- package/types/sdk/init.d.ts.map +1 -1
- package/types-ts3.8/index.d.ts +2 -2
- package/types-ts3.8/sdk/init.d.ts +4 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sources":["../../../src/sdk/client.ts"],"sourcesContent":["import * as os from 'os';\nimport type { Tracer } from '@opentelemetry/api';\nimport { trace } from '@opentelemetry/api';\nimport type { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';\nimport type { ServerRuntimeClientOptions } from '@sentry/core';\nimport { SDK_VERSION, ServerRuntimeClient, applySdkMetadata } from '@sentry/core';\nimport { logger } from '@sentry/utils';\nimport { isMainThread, threadId } from 'worker_threads';\nimport type { NodeClientOptions } from '../types';\n\n/** A client for using Sentry with Node & OpenTelemetry. */\nexport class NodeClient extends ServerRuntimeClient<NodeClientOptions> {\n public traceProvider: BasicTracerProvider | undefined;\n private _tracer: Tracer | undefined;\n\n public constructor(options: NodeClientOptions) {\n const clientOptions: ServerRuntimeClientOptions = {\n ...options,\n platform: 'node',\n runtime: { name: 'node', version: global.process.version },\n serverName: options.serverName || global.process.env.SENTRY_NAME || os.hostname(),\n };\n\n applySdkMetadata(clientOptions, 'node');\n\n logger.log(\n `Initializing Sentry: process: ${process.pid}, thread: ${isMainThread ? 'main' : `worker-${threadId}`}.`,\n );\n\n super(clientOptions);\n }\n\n /** Get the OTEL tracer. */\n public get tracer(): Tracer {\n if (this._tracer) {\n return this._tracer;\n }\n\n const name = '@sentry/node';\n const version = SDK_VERSION;\n const tracer = trace.getTracer(name, version);\n this._tracer = tracer;\n\n return tracer;\n }\n\n /**\n * @inheritDoc\n */\n public async flush(timeout?: number): Promise<boolean> {\n const provider = this.traceProvider;\n const spanProcessor = provider?.activeSpanProcessor;\n\n if (spanProcessor) {\n await spanProcessor.forceFlush();\n }\n\n return super.flush(timeout);\n }\n}\n"],"names":["ServerRuntimeClient","applySdkMetadata","logger","isMainThread","threadId","SDK_VERSION","trace"],"mappings":";;;;;;;;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,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA;IACA,MAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,aAAA;IACA,MAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;IAEA,CAAA,EAAA,CAAA,aAAA,EAAA;MACA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA;IACA;;IAEA,OAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,KAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;EACA;AACA;;"}
|
package/cjs/sdk/init.js
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
const core = require('@sentry/core');
|
|
4
|
+
const opentelemetry = require('@sentry/opentelemetry');
|
|
5
|
+
const utils = require('@sentry/utils');
|
|
6
|
+
const debugBuild = require('../debug-build.js');
|
|
7
|
+
const console$1 = require('../integrations/console.js');
|
|
8
|
+
const context = require('../integrations/context.js');
|
|
9
|
+
const contextlines = require('../integrations/contextlines.js');
|
|
10
|
+
const moduleModule = require('module');
|
|
11
|
+
const http = require('../integrations/http.js');
|
|
12
|
+
const index = require('../integrations/local-variables/index.js');
|
|
13
|
+
const modules = require('../integrations/modules.js');
|
|
14
|
+
const nodeFetch = require('../integrations/node-fetch.js');
|
|
15
|
+
const onuncaughtexception = require('../integrations/onuncaughtexception.js');
|
|
16
|
+
const onunhandledrejection = require('../integrations/onunhandledrejection.js');
|
|
17
|
+
const spotlight = require('../integrations/spotlight.js');
|
|
18
|
+
const index$1 = require('../integrations/tracing/index.js');
|
|
19
|
+
const http$1 = require('../transports/http.js');
|
|
20
|
+
const api = require('./api.js');
|
|
21
|
+
const client = require('./client.js');
|
|
22
|
+
const initOtel = require('./initOtel.js');
|
|
23
|
+
|
|
24
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
25
|
+
function isCjs() {
|
|
26
|
+
return typeof require !== 'undefined';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getCjsOnlyIntegrations() {
|
|
30
|
+
return isCjs() ? [modules.modulesIntegration()] : [];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Get default integrations, excluding performance.
|
|
35
|
+
*/
|
|
36
|
+
function getDefaultIntegrationsWithoutPerformance() {
|
|
37
|
+
return [
|
|
38
|
+
// Common
|
|
39
|
+
core.inboundFiltersIntegration(),
|
|
40
|
+
core.functionToStringIntegration(),
|
|
41
|
+
core.linkedErrorsIntegration(),
|
|
42
|
+
core.requestDataIntegration(),
|
|
43
|
+
// Native Wrappers
|
|
44
|
+
console$1.consoleIntegration(),
|
|
45
|
+
http.httpIntegration(),
|
|
46
|
+
nodeFetch.nativeNodeFetchIntegration(),
|
|
47
|
+
// Global Handlers
|
|
48
|
+
onuncaughtexception.onUncaughtExceptionIntegration(),
|
|
49
|
+
onunhandledrejection.onUnhandledRejectionIntegration(),
|
|
50
|
+
// Event Info
|
|
51
|
+
contextlines.contextLinesIntegration(),
|
|
52
|
+
index.localVariablesIntegration(),
|
|
53
|
+
context.nodeContextIntegration(),
|
|
54
|
+
...getCjsOnlyIntegrations(),
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Get the default integrations for the Node SDK. */
|
|
59
|
+
function getDefaultIntegrations(options) {
|
|
60
|
+
return [
|
|
61
|
+
...getDefaultIntegrationsWithoutPerformance(),
|
|
62
|
+
...(core.hasTracingEnabled(options) ? index$1.getAutoPerformanceIntegrations() : []),
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Initialize Sentry for Node.
|
|
68
|
+
*/
|
|
69
|
+
function init(options = {}) {
|
|
70
|
+
return _init(options, getDefaultIntegrations);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Initialize Sentry for Node, without any integrations added by default.
|
|
75
|
+
*/
|
|
76
|
+
function initWithoutDefaultIntegrations(options = {}) {
|
|
77
|
+
return _init(options, () => []);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Initialize Sentry for Node, without performance instrumentation.
|
|
82
|
+
*/
|
|
83
|
+
function _init(
|
|
84
|
+
options = {},
|
|
85
|
+
getDefaultIntegrationsImpl,
|
|
86
|
+
) {
|
|
87
|
+
const clientOptions = getClientOptions(options, getDefaultIntegrationsImpl);
|
|
88
|
+
|
|
89
|
+
if (clientOptions.debug === true) {
|
|
90
|
+
if (debugBuild.DEBUG_BUILD) {
|
|
91
|
+
utils.logger.enable();
|
|
92
|
+
} else {
|
|
93
|
+
// use `console.warn` rather than `logger.warn` since by non-debug bundles have all `logger.x` statements stripped
|
|
94
|
+
utils.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
|
+
if (!isCjs()) {
|
|
102
|
+
const [nodeMajor, nodeMinor] = process.versions.node.split('.').map(Number);
|
|
103
|
+
|
|
104
|
+
// Register hook was added in v20.6.0 and v18.19.0
|
|
105
|
+
if (nodeMajor >= 22 || (nodeMajor === 20 && nodeMinor >= 6) || (nodeMajor === 18 && nodeMinor >= 19)) {
|
|
106
|
+
// We need to work around using import.meta.url directly because jest complains about it.
|
|
107
|
+
const importMetaUrl =
|
|
108
|
+
typeof (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('sdk/init.js', document.baseURI).href)) !== 'undefined' ? (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('sdk/init.js', document.baseURI).href)) : undefined;
|
|
109
|
+
|
|
110
|
+
if (!utils.GLOBAL_OBJ._sentryEsmLoaderHookRegistered && importMetaUrl) {
|
|
111
|
+
// @ts-expect-error register is available in these versions
|
|
112
|
+
moduleModule.default.register('@opentelemetry/instrumentation/hook.mjs', importMetaUrl);
|
|
113
|
+
utils.GLOBAL_OBJ._sentryEsmLoaderHookRegistered = true;
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
utils.consoleSandbox(() => {
|
|
117
|
+
// eslint-disable-next-line no-console
|
|
118
|
+
console.warn(
|
|
119
|
+
'[Sentry] You are using Node.js in ESM mode ("import syntax"). The Sentry Node.js SDK is not compatible with ESM in Node.js versions before 18.19.0 or before 20.6.0. Please either build your application with CommonJS ("require() syntax"), or use version 7.x of the Sentry Node.js SDK.',
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
opentelemetry.setOpenTelemetryContextAsyncContextStrategy();
|
|
126
|
+
|
|
127
|
+
const scope = core.getCurrentScope();
|
|
128
|
+
scope.update(options.initialScope);
|
|
129
|
+
|
|
130
|
+
const client$1 = new client.NodeClient(clientOptions);
|
|
131
|
+
// The client is on the current scope, from where it generally is inherited
|
|
132
|
+
core.getCurrentScope().setClient(client$1);
|
|
133
|
+
|
|
134
|
+
if (isEnabled(client$1)) {
|
|
135
|
+
client$1.init();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (options.autoSessionTracking) {
|
|
139
|
+
startSessionTracking();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
updateScopeFromEnvVariables();
|
|
143
|
+
|
|
144
|
+
if (options.spotlight) {
|
|
145
|
+
// force integrations to be setup even if no DSN was set
|
|
146
|
+
// If they have already been added before, they will be ignored anyhow
|
|
147
|
+
const integrations = client$1.getOptions().integrations;
|
|
148
|
+
for (const integration of integrations) {
|
|
149
|
+
client$1.addIntegration(integration);
|
|
150
|
+
}
|
|
151
|
+
client$1.addIntegration(
|
|
152
|
+
spotlight.spotlightIntegration({
|
|
153
|
+
sidecarUrl: typeof options.spotlight === 'string' ? options.spotlight : undefined,
|
|
154
|
+
}),
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// If users opt-out of this, they _have_ to set up OpenTelemetry themselves
|
|
159
|
+
// There is no way to use this SDK without OpenTelemetry!
|
|
160
|
+
if (!options.skipOpenTelemetrySetup) {
|
|
161
|
+
initOtel.initOpenTelemetry(client$1);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
validateOpenTelemetrySetup();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function validateOpenTelemetrySetup() {
|
|
168
|
+
if (!debugBuild.DEBUG_BUILD) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const setup = opentelemetry.openTelemetrySetupCheck();
|
|
173
|
+
|
|
174
|
+
const required = ['SentrySpanProcessor', 'SentryContextManager', 'SentryPropagator'] ;
|
|
175
|
+
for (const k of required) {
|
|
176
|
+
if (!setup.includes(k)) {
|
|
177
|
+
utils.logger.error(
|
|
178
|
+
`You have to set up the ${k}. Without this, the OpenTelemetry & Sentry integration will not work properly.`,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (!setup.includes('SentrySampler')) {
|
|
184
|
+
utils.logger.warn(
|
|
185
|
+
'You have to set up the SentrySampler. Without this, the OpenTelemetry & Sentry integration may still work, but sample rates set for the Sentry SDK will not be respected.',
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function getClientOptions(
|
|
191
|
+
options,
|
|
192
|
+
getDefaultIntegrationsImpl,
|
|
193
|
+
) {
|
|
194
|
+
const release = getRelease(options.release);
|
|
195
|
+
|
|
196
|
+
const autoSessionTracking =
|
|
197
|
+
typeof release !== 'string'
|
|
198
|
+
? false
|
|
199
|
+
: options.autoSessionTracking === undefined
|
|
200
|
+
? true
|
|
201
|
+
: options.autoSessionTracking;
|
|
202
|
+
|
|
203
|
+
const tracesSampleRate = getTracesSampleRate(options.tracesSampleRate);
|
|
204
|
+
|
|
205
|
+
const baseOptions = utils.dropUndefinedKeys({
|
|
206
|
+
transport: http$1.makeNodeTransport,
|
|
207
|
+
dsn: process.env.SENTRY_DSN,
|
|
208
|
+
environment: process.env.SENTRY_ENVIRONMENT,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const overwriteOptions = utils.dropUndefinedKeys({
|
|
212
|
+
release,
|
|
213
|
+
autoSessionTracking,
|
|
214
|
+
tracesSampleRate,
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const mergedOptions = {
|
|
218
|
+
...baseOptions,
|
|
219
|
+
...options,
|
|
220
|
+
...overwriteOptions,
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
if (options.defaultIntegrations === undefined) {
|
|
224
|
+
options.defaultIntegrations = getDefaultIntegrationsImpl(mergedOptions);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const clientOptions = {
|
|
228
|
+
...mergedOptions,
|
|
229
|
+
stackParser: utils.stackParserFromStackParserOptions(options.stackParser || api.defaultStackParser),
|
|
230
|
+
integrations: core.getIntegrationsToSetup({
|
|
231
|
+
defaultIntegrations: options.defaultIntegrations,
|
|
232
|
+
integrations: options.integrations,
|
|
233
|
+
}),
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
return clientOptions;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function getRelease(release) {
|
|
240
|
+
if (release !== undefined) {
|
|
241
|
+
return release;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const detectedRelease = api.getSentryRelease();
|
|
245
|
+
if (detectedRelease !== undefined) {
|
|
246
|
+
return detectedRelease;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function getTracesSampleRate(tracesSampleRate) {
|
|
253
|
+
if (tracesSampleRate !== undefined) {
|
|
254
|
+
return tracesSampleRate;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const sampleRateFromEnv = process.env.SENTRY_TRACES_SAMPLE_RATE;
|
|
258
|
+
if (!sampleRateFromEnv) {
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const parsed = parseFloat(sampleRateFromEnv);
|
|
263
|
+
return isFinite(parsed) ? parsed : undefined;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Update scope and propagation context based on environmental variables.
|
|
268
|
+
*
|
|
269
|
+
* See https://github.com/getsentry/rfcs/blob/main/text/0071-continue-trace-over-process-boundaries.md
|
|
270
|
+
* for more details.
|
|
271
|
+
*/
|
|
272
|
+
function updateScopeFromEnvVariables() {
|
|
273
|
+
const sentryUseEnvironment = (process.env.SENTRY_USE_ENVIRONMENT || '').toLowerCase();
|
|
274
|
+
if (!['false', 'n', 'no', 'off', '0'].includes(sentryUseEnvironment)) {
|
|
275
|
+
const sentryTraceEnv = process.env.SENTRY_TRACE;
|
|
276
|
+
const baggageEnv = process.env.SENTRY_BAGGAGE;
|
|
277
|
+
const propagationContext = utils.propagationContextFromHeaders(sentryTraceEnv, baggageEnv);
|
|
278
|
+
core.getCurrentScope().setPropagationContext(propagationContext);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Enable automatic Session Tracking for the node process.
|
|
284
|
+
*/
|
|
285
|
+
function startSessionTracking() {
|
|
286
|
+
const client = core.getClient();
|
|
287
|
+
if (client && client.getOptions().autoSessionTracking) {
|
|
288
|
+
client.initSessionFlusher();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
core.startSession();
|
|
292
|
+
|
|
293
|
+
// Emitted in the case of healthy sessions, error of `mechanism.handled: true` and unhandledrejections because
|
|
294
|
+
// The 'beforeExit' event is not emitted for conditions causing explicit termination,
|
|
295
|
+
// such as calling process.exit() or uncaught exceptions.
|
|
296
|
+
// Ref: https://nodejs.org/api/process.html#process_event_beforeexit
|
|
297
|
+
process.on('beforeExit', () => {
|
|
298
|
+
const session = core.getIsolationScope().getSession();
|
|
299
|
+
|
|
300
|
+
// Only call endSession, if the Session exists on Scope and SessionStatus is not a
|
|
301
|
+
// Terminal Status i.e. Exited or Crashed because
|
|
302
|
+
// "When a session is moved away from ok it must not be updated anymore."
|
|
303
|
+
// Ref: https://develop.sentry.dev/sdk/sessions/
|
|
304
|
+
if (session && session.status !== 'ok') {
|
|
305
|
+
core.endSession();
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function isEnabled(client) {
|
|
311
|
+
return client.getOptions().enabled !== false && client.getTransport() !== undefined;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
exports.getDefaultIntegrations = getDefaultIntegrations;
|
|
315
|
+
exports.getDefaultIntegrationsWithoutPerformance = getDefaultIntegrationsWithoutPerformance;
|
|
316
|
+
exports.init = init;
|
|
317
|
+
exports.initWithoutDefaultIntegrations = initWithoutDefaultIntegrations;
|
|
318
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sources":["../../../src/sdk/init.ts"],"sourcesContent":["import {\n endSession,\n functionToStringIntegration,\n getClient,\n getCurrentScope,\n getIntegrationsToSetup,\n getIsolationScope,\n hasTracingEnabled,\n inboundFiltersIntegration,\n linkedErrorsIntegration,\n requestDataIntegration,\n startSession,\n} from '@sentry/core';\nimport { openTelemetrySetupCheck, setOpenTelemetryContextAsyncContextStrategy } from '@sentry/opentelemetry';\nimport type { Client, Integration, Options } from '@sentry/types';\nimport {\n GLOBAL_OBJ,\n consoleSandbox,\n dropUndefinedKeys,\n logger,\n propagationContextFromHeaders,\n stackParserFromStackParserOptions,\n} from '@sentry/utils';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { consoleIntegration } from '../integrations/console';\nimport { nodeContextIntegration } from '../integrations/context';\nimport { contextLinesIntegration } from '../integrations/contextlines';\n\nimport moduleModule from 'module';\nimport { httpIntegration } from '../integrations/http';\nimport { localVariablesIntegration } from '../integrations/local-variables';\nimport { modulesIntegration } from '../integrations/modules';\nimport { nativeNodeFetchIntegration } from '../integrations/node-fetch';\nimport { onUncaughtExceptionIntegration } from '../integrations/onuncaughtexception';\nimport { onUnhandledRejectionIntegration } from '../integrations/onunhandledrejection';\nimport { spotlightIntegration } from '../integrations/spotlight';\nimport { getAutoPerformanceIntegrations } from '../integrations/tracing';\nimport { makeNodeTransport } from '../transports';\nimport type { NodeClientOptions, NodeOptions } from '../types';\nimport { defaultStackParser, getSentryRelease } from './api';\nimport { NodeClient } from './client';\nimport { initOpenTelemetry } from './initOtel';\n\nfunction isCjs(): boolean {\n return typeof require !== 'undefined';\n}\n\nfunction getCjsOnlyIntegrations(): Integration[] {\n return isCjs() ? [modulesIntegration()] : [];\n}\n\n/**\n * Get default integrations, excluding performance.\n */\nexport function getDefaultIntegrationsWithoutPerformance(): Integration[] {\n return [\n // Common\n inboundFiltersIntegration(),\n functionToStringIntegration(),\n linkedErrorsIntegration(),\n requestDataIntegration(),\n // Native Wrappers\n consoleIntegration(),\n httpIntegration(),\n nativeNodeFetchIntegration(),\n // Global Handlers\n onUncaughtExceptionIntegration(),\n onUnhandledRejectionIntegration(),\n // Event Info\n contextLinesIntegration(),\n localVariablesIntegration(),\n nodeContextIntegration(),\n ...getCjsOnlyIntegrations(),\n ];\n}\n\n/** Get the default integrations for the Node SDK. */\nexport function getDefaultIntegrations(options: Options): Integration[] {\n return [\n ...getDefaultIntegrationsWithoutPerformance(),\n ...(hasTracingEnabled(options) ? getAutoPerformanceIntegrations() : []),\n ];\n}\n\ndeclare const __IMPORT_META_URL_REPLACEMENT__: string;\n\n/**\n * Initialize Sentry for Node.\n */\nexport function init(options: NodeOptions | undefined = {}): void {\n return _init(options, getDefaultIntegrations);\n}\n\n/**\n * Initialize Sentry for Node, without any integrations added by default.\n */\nexport function initWithoutDefaultIntegrations(options: NodeOptions | undefined = {}): void {\n return _init(options, () => []);\n}\n\n/**\n * Initialize Sentry for Node, without performance instrumentation.\n */\nfunction _init(\n options: NodeOptions | undefined = {},\n getDefaultIntegrationsImpl: (options: Options) => Integration[],\n): void {\n const clientOptions = getClientOptions(options, getDefaultIntegrationsImpl);\n\n if (clientOptions.debug === true) {\n if (DEBUG_BUILD) {\n logger.enable();\n } else {\n // use `console.warn` rather than `logger.warn` since by non-debug bundles have all `logger.x` statements stripped\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.warn('[Sentry] Cannot initialize SDK with `debug` option using a non-debug bundle.');\n });\n }\n }\n\n if (!isCjs()) {\n const [nodeMajor, nodeMinor] = process.versions.node.split('.').map(Number);\n\n // Register hook was added in v20.6.0 and v18.19.0\n if (nodeMajor >= 22 || (nodeMajor === 20 && nodeMinor >= 6) || (nodeMajor === 18 && nodeMinor >= 19)) {\n // We need to work around using import.meta.url directly because jest complains about it.\n const importMetaUrl =\n typeof __IMPORT_META_URL_REPLACEMENT__ !== 'undefined' ? __IMPORT_META_URL_REPLACEMENT__ : undefined;\n\n if (!GLOBAL_OBJ._sentryEsmLoaderHookRegistered && importMetaUrl) {\n // @ts-expect-error register is available in these versions\n moduleModule.register('@opentelemetry/instrumentation/hook.mjs', importMetaUrl);\n GLOBAL_OBJ._sentryEsmLoaderHookRegistered = true;\n }\n } else {\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.warn(\n '[Sentry] You are using Node.js in ESM mode (\"import syntax\"). The Sentry Node.js SDK is not compatible with ESM in Node.js versions before 18.19.0 or before 20.6.0. Please either build your application with CommonJS (\"require() syntax\"), or use version 7.x of the Sentry Node.js SDK.',\n );\n });\n }\n }\n\n setOpenTelemetryContextAsyncContextStrategy();\n\n const scope = getCurrentScope();\n scope.update(options.initialScope);\n\n const client = new NodeClient(clientOptions);\n // The client is on the current scope, from where it generally is inherited\n getCurrentScope().setClient(client);\n\n if (isEnabled(client)) {\n client.init();\n }\n\n if (options.autoSessionTracking) {\n startSessionTracking();\n }\n\n updateScopeFromEnvVariables();\n\n if (options.spotlight) {\n // force integrations to be setup even if no DSN was set\n // If they have already been added before, they will be ignored anyhow\n const integrations = client.getOptions().integrations;\n for (const integration of integrations) {\n client.addIntegration(integration);\n }\n client.addIntegration(\n spotlightIntegration({\n sidecarUrl: typeof options.spotlight === 'string' ? options.spotlight : undefined,\n }),\n );\n }\n\n // If users opt-out of this, they _have_ to set up OpenTelemetry themselves\n // There is no way to use this SDK without OpenTelemetry!\n if (!options.skipOpenTelemetrySetup) {\n initOpenTelemetry(client);\n }\n\n validateOpenTelemetrySetup();\n}\n\nfunction validateOpenTelemetrySetup(): void {\n if (!DEBUG_BUILD) {\n return;\n }\n\n const setup = openTelemetrySetupCheck();\n\n const required = ['SentrySpanProcessor', 'SentryContextManager', 'SentryPropagator'] as const;\n for (const k of required) {\n if (!setup.includes(k)) {\n logger.error(\n `You have to set up the ${k}. Without this, the OpenTelemetry & Sentry integration will not work properly.`,\n );\n }\n }\n\n if (!setup.includes('SentrySampler')) {\n logger.warn(\n 'You have to set up the SentrySampler. Without this, the OpenTelemetry & Sentry integration may still work, but sample rates set for the Sentry SDK will not be respected.',\n );\n }\n}\n\nfunction getClientOptions(\n options: NodeOptions,\n getDefaultIntegrationsImpl: (options: Options) => Integration[],\n): NodeClientOptions {\n const release = getRelease(options.release);\n\n const autoSessionTracking =\n typeof release !== 'string'\n ? false\n : options.autoSessionTracking === undefined\n ? true\n : options.autoSessionTracking;\n\n const tracesSampleRate = getTracesSampleRate(options.tracesSampleRate);\n\n const baseOptions = dropUndefinedKeys({\n transport: makeNodeTransport,\n dsn: process.env.SENTRY_DSN,\n environment: process.env.SENTRY_ENVIRONMENT,\n });\n\n const overwriteOptions = dropUndefinedKeys({\n release,\n autoSessionTracking,\n tracesSampleRate,\n });\n\n const mergedOptions = {\n ...baseOptions,\n ...options,\n ...overwriteOptions,\n };\n\n if (options.defaultIntegrations === undefined) {\n options.defaultIntegrations = getDefaultIntegrationsImpl(mergedOptions);\n }\n\n const clientOptions: NodeClientOptions = {\n ...mergedOptions,\n stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),\n integrations: getIntegrationsToSetup({\n defaultIntegrations: options.defaultIntegrations,\n integrations: options.integrations,\n }),\n };\n\n return clientOptions;\n}\n\nfunction getRelease(release: NodeOptions['release']): string | undefined {\n if (release !== undefined) {\n return release;\n }\n\n const detectedRelease = getSentryRelease();\n if (detectedRelease !== undefined) {\n return detectedRelease;\n }\n\n return undefined;\n}\n\nfunction getTracesSampleRate(tracesSampleRate: NodeOptions['tracesSampleRate']): number | undefined {\n if (tracesSampleRate !== undefined) {\n return tracesSampleRate;\n }\n\n const sampleRateFromEnv = process.env.SENTRY_TRACES_SAMPLE_RATE;\n if (!sampleRateFromEnv) {\n return undefined;\n }\n\n const parsed = parseFloat(sampleRateFromEnv);\n return isFinite(parsed) ? parsed : undefined;\n}\n\n/**\n * Update scope and propagation context based on environmental variables.\n *\n * See https://github.com/getsentry/rfcs/blob/main/text/0071-continue-trace-over-process-boundaries.md\n * for more details.\n */\nfunction updateScopeFromEnvVariables(): void {\n const sentryUseEnvironment = (process.env.SENTRY_USE_ENVIRONMENT || '').toLowerCase();\n if (!['false', 'n', 'no', 'off', '0'].includes(sentryUseEnvironment)) {\n const sentryTraceEnv = process.env.SENTRY_TRACE;\n const baggageEnv = process.env.SENTRY_BAGGAGE;\n const propagationContext = propagationContextFromHeaders(sentryTraceEnv, baggageEnv);\n getCurrentScope().setPropagationContext(propagationContext);\n }\n}\n\n/**\n * Enable automatic Session Tracking for the node process.\n */\nfunction startSessionTracking(): void {\n const client = getClient<NodeClient>();\n if (client && client.getOptions().autoSessionTracking) {\n client.initSessionFlusher();\n }\n\n startSession();\n\n // Emitted in the case of healthy sessions, error of `mechanism.handled: true` and unhandledrejections because\n // The 'beforeExit' event is not emitted for conditions causing explicit termination,\n // such as calling process.exit() or uncaught exceptions.\n // Ref: https://nodejs.org/api/process.html#process_event_beforeexit\n process.on('beforeExit', () => {\n const session = getIsolationScope().getSession();\n\n // Only call endSession, if the Session exists on Scope and SessionStatus is not a\n // Terminal Status i.e. Exited or Crashed because\n // \"When a session is moved away from ok it must not be updated anymore.\"\n // Ref: https://develop.sentry.dev/sdk/sessions/\n if (session && session.status !== 'ok') {\n endSession();\n }\n });\n}\n\nfunction isEnabled(client: Client): boolean {\n return client.getOptions().enabled !== false && client.getTransport() !== undefined;\n}\n"],"names":["modulesIntegration","inboundFiltersIntegration","functionToStringIntegration","linkedErrorsIntegration","requestDataIntegration","consoleIntegration","httpIntegration","nativeNodeFetchIntegration","onUncaughtExceptionIntegration","onUnhandledRejectionIntegration","contextLinesIntegration","localVariablesIntegration","nodeContextIntegration","hasTracingEnabled","getAutoPerformanceIntegrations","DEBUG_BUILD","logger","consoleSandbox","GLOBAL_OBJ","moduleModule","setOpenTelemetryContextAsyncContextStrategy","getCurrentScope","client","NodeClient","spotlightIntegration","initOpenTelemetry","openTelemetrySetupCheck","dropUndefinedKeys","makeNodeTransport","stackParserFromStackParserOptions","defaultStackParser","getIntegrationsToSetup","getSentryRelease","propagationContextFromHeaders","getClient","startSession","getIsolationScope","endSession"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA2CA,SAAS,KAAK,GAAY;AAC1B,EAAE,OAAO,OAAO,OAAQ,KAAI,WAAW,CAAA;AACvC,CAAA;AACA;AACA,SAAS,sBAAsB,GAAkB;AACjD,EAAE,OAAO,KAAK,EAAC,GAAI,CAACA,0BAAkB,EAAE,CAAA,GAAI,EAAE,CAAA;AAC9C,CAAA;AACA;AACA;AACA;AACA;AACO,SAAS,wCAAwC,GAAkB;AAC1E,EAAE,OAAO;AACT;AACA,IAAIC,8BAAyB,EAAE;AAC/B,IAAIC,gCAA2B,EAAE;AACjC,IAAIC,4BAAuB,EAAE;AAC7B,IAAIC,2BAAsB,EAAE;AAC5B;AACA,IAAIC,4BAAkB,EAAE;AACxB,IAAIC,oBAAe,EAAE;AACrB,IAAIC,oCAA0B,EAAE;AAChC;AACA,IAAIC,kDAA8B,EAAE;AACpC,IAAIC,oDAA+B,EAAE;AACrC;AACA,IAAIC,oCAAuB,EAAE;AAC7B,IAAIC,+BAAyB,EAAE;AAC/B,IAAIC,8BAAsB,EAAE;AAC5B,IAAI,GAAG,sBAAsB,EAAE;AAC/B,GAAG,CAAA;AACH,CAAA;AACA;AACA;AACO,SAAS,sBAAsB,CAAC,OAAO,EAA0B;AACxE,EAAE,OAAO;AACT,IAAI,GAAG,wCAAwC,EAAE;AACjD,IAAI,IAAIC,sBAAiB,CAAC,OAAO,CAAA,GAAIC,sCAA8B,EAAC,GAAI,EAAE;AAC1E,GAAG,CAAA;AACH,CAAA;;AAIA;AACA;AACA;AACO,SAAS,IAAI,CAAC,OAAO,GAA4B,EAAE,EAAQ;AACl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AE,IAAI,MAAA,IAAU,MAAM,CAAC,UAAU,EAAE,CAAC,mBAAmB,EAAE;AACzD,IAAI,MAAM,CAAC,kBAAkB,EAAE,CAAA;AAC/B,GAAE;AACF;AACA,EAAEC,iBAAY,EAAE,CAAA;AAChB;AACA;AACA;AACA;AACA;AACA,EAAE,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM;AACjC,IAAI,MAAM,UAAUC,sBAAiB,EAAE,CAAC,UAAU,EAAE,CAAA;AACpD;AACA;AACA;AACA;AACA;AACA,IAAI,IAAI,OAAQ,IAAG,OAAO,CAAC,MAAA,KAAW,IAAI,EAAE;AAC5C,MAAMC,eAAU,EAAE,CAAA;AAClB,KAAI;AACJ,GAAG,CAAC,CAAA;AACJ,CAAA;AACA;AACA,SAAS,SAAS,CAAC,MAAM,EAAmB;AAC5C,EAAE,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC,OAAA,KAAY,KAAA,IAAS,MAAM,CAAC,YAAY,EAAC,KAAM,SAAS,CAAA;AACrF;;;;;;;"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
const api = require('@opentelemetry/api');
|
|
4
|
+
const resources = require('@opentelemetry/resources');
|
|
5
|
+
const sdkTraceBase = require('@opentelemetry/sdk-trace-base');
|
|
6
|
+
const semanticConventions = require('@opentelemetry/semantic-conventions');
|
|
7
|
+
const core = require('@sentry/core');
|
|
8
|
+
const opentelemetry = require('@sentry/opentelemetry');
|
|
9
|
+
const utils = require('@sentry/utils');
|
|
10
|
+
const contextManager = require('../otel/contextManager.js');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Initialize OpenTelemetry for Node.
|
|
14
|
+
*/
|
|
15
|
+
function initOpenTelemetry(client) {
|
|
16
|
+
if (client.getOptions().debug) {
|
|
17
|
+
const otelLogger = new Proxy(utils.logger , {
|
|
18
|
+
get(target, prop, receiver) {
|
|
19
|
+
const actualProp = prop === 'verbose' ? 'debug' : prop;
|
|
20
|
+
return Reflect.get(target, actualProp, receiver);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
api.diag.setLogger(otelLogger, api.DiagLogLevel.DEBUG);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
opentelemetry.setupEventContextTrace(client);
|
|
28
|
+
|
|
29
|
+
const provider = setupOtel(client);
|
|
30
|
+
client.traceProvider = provider;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Just exported for tests. */
|
|
34
|
+
function setupOtel(client) {
|
|
35
|
+
// Create and configure NodeTracerProvider
|
|
36
|
+
const provider = new sdkTraceBase.BasicTracerProvider({
|
|
37
|
+
sampler: new opentelemetry.SentrySampler(client),
|
|
38
|
+
resource: new resources.Resource({
|
|
39
|
+
[semanticConventions.SEMRESATTRS_SERVICE_NAME]: 'node',
|
|
40
|
+
[semanticConventions.SEMRESATTRS_SERVICE_NAMESPACE]: 'sentry',
|
|
41
|
+
[semanticConventions.SEMRESATTRS_SERVICE_VERSION]: core.SDK_VERSION,
|
|
42
|
+
}),
|
|
43
|
+
forceFlushTimeoutMillis: 500,
|
|
44
|
+
});
|
|
45
|
+
provider.addSpanProcessor(new opentelemetry.SentrySpanProcessor());
|
|
46
|
+
|
|
47
|
+
// Initialize the provider
|
|
48
|
+
provider.register({
|
|
49
|
+
propagator: new opentelemetry.SentryPropagator(),
|
|
50
|
+
contextManager: new contextManager.SentryContextManager(),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return provider;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
exports.initOpenTelemetry = initOpenTelemetry;
|
|
57
|
+
exports.setupOtel = setupOtel;
|
|
58
|
+
//# sourceMappingURL=initOtel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initOtel.js","sources":["../../../src/sdk/initOtel.ts"],"sourcesContent":["import { DiagLogLevel, diag } from '@opentelemetry/api';\nimport { Resource } from '@opentelemetry/resources';\nimport { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';\nimport {\n SEMRESATTRS_SERVICE_NAME,\n SEMRESATTRS_SERVICE_NAMESPACE,\n SEMRESATTRS_SERVICE_VERSION,\n} from '@opentelemetry/semantic-conventions';\nimport { SDK_VERSION } from '@sentry/core';\nimport { SentryPropagator, SentrySampler, SentrySpanProcessor, setupEventContextTrace } from '@sentry/opentelemetry';\nimport { logger } from '@sentry/utils';\n\nimport { SentryContextManager } from '../otel/contextManager';\nimport type { NodeClient } from './client';\n\n/**\n * Initialize OpenTelemetry for Node.\n */\nexport function initOpenTelemetry(client: NodeClient): void {\n if (client.getOptions().debug) {\n const otelLogger = new Proxy(logger as typeof logger & { verbose: (typeof logger)['debug'] }, {\n get(target, prop, receiver) {\n const actualProp = prop === 'verbose' ? 'debug' : prop;\n return Reflect.get(target, actualProp, receiver);\n },\n });\n\n diag.setLogger(otelLogger, DiagLogLevel.DEBUG);\n }\n\n setupEventContextTrace(client);\n\n const provider = setupOtel(client);\n client.traceProvider = provider;\n}\n\n/** Just exported for tests. */\nexport function setupOtel(client: NodeClient): BasicTracerProvider {\n // Create and configure NodeTracerProvider\n const provider = new BasicTracerProvider({\n sampler: new SentrySampler(client),\n resource: new Resource({\n [SEMRESATTRS_SERVICE_NAME]: 'node',\n [SEMRESATTRS_SERVICE_NAMESPACE]: 'sentry',\n [SEMRESATTRS_SERVICE_VERSION]: SDK_VERSION,\n }),\n forceFlushTimeoutMillis: 500,\n });\n provider.addSpanProcessor(new SentrySpanProcessor());\n\n // Initialize the provider\n provider.register({\n propagator: new SentryPropagator(),\n contextManager: new SentryContextManager(),\n });\n\n return provider;\n}\n"],"names":["logger","diag","DiagLogLevel","setupEventContextTrace","BasicTracerProvider","SentrySampler","Resource","SEMRESATTRS_SERVICE_NAME","SEMRESATTRS_SERVICE_NAMESPACE","SEMRESATTRS_SERVICE_VERSION","SDK_VERSION","SentrySpanProcessor","SentryPropagator","SentryCont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CAAC,QAAQ,CAAC;AACpB,IAAI,UAAU,EAAE,IAAIC,8BAAgB,EAAE;AACtC,IAAI,cAAc,EAAE,IAAIC,mCAAoB,EAAE;AAC9C,GAAG,CAAC,CAAA;AACJ;AACA,EAAE,OAAO,QAAQ,CAAA;AACjB;;;;;"}
|
package/cjs/sdk/scope.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
const api = require('@opentelemetry/api');
|
|
4
|
+
const opentelemetry = require('@sentry/opentelemetry');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Update the active isolation scope.
|
|
8
|
+
* Should be used with caution!
|
|
9
|
+
*/
|
|
10
|
+
function setIsolationScope(isolationScope) {
|
|
11
|
+
const scopes = opentelemetry.getScopesFromContext(api.context.active());
|
|
12
|
+
if (scopes) {
|
|
13
|
+
scopes.isolationScope = isolationScope;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.setIsolationScope = setIsolationScope;
|
|
18
|
+
//# sourceMappingURL=scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.js","sources":["../../../src/sdk/scope.ts"],"sourcesContent":["import { context } from '@opentelemetry/api';\nimport { getScopesFromContext } from '@sentry/opentelemetry';\nimport type { Scope } from '@sentry/types';\n\n/**\n * Update the active isolation scope.\n * Should be used with caution!\n */\nexport function setIsolationScope(isolationScope: Scope): void {\n const scopes = getScopesFromContext(context.active());\n if (scopes) {\n scopes.isolationScope = isolationScope;\n }\n}\n"],"names":["getScopesFromContext","context"],"mappings":";;;;;AAIA;AACA;AACA;AACA;AACO,SAAS,iBAAiB,CAAC,cAAc,EAAe;AAC/D,EAAE,MAAM,MAAO,GAAEA,kCAAoB,CAACC,WAAO,CAAC,MAAM,EAAE,CAAC,CAAA;AACvD,EAAE,IAAI,MAAM,EAAE;AACd,IAAI,MAAM,CAAC,cAAe,GAAE,cAAc,CAAA;AAC1C,GAAE;AACF;;;;"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
var {
|
|
2
|
+
_nullishCoalesce
|
|
3
|
+
} = require('@sentry/utils');
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
6
|
+
|
|
7
|
+
const http = require('node:http');
|
|
8
|
+
const https = require('node:https');
|
|
9
|
+
const stream = require('stream');
|
|
10
|
+
const zlib = require('zlib');
|
|
11
|
+
const core = require('@sentry/core');
|
|
12
|
+
const utils = require('@sentry/utils');
|
|
13
|
+
const index = require('../proxy/index.js');
|
|
14
|
+
|
|
15
|
+
// Estimated maximum size for reasonable standalone event
|
|
16
|
+
const GZIP_THRESHOLD = 1024 * 32;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Gets a stream from a Uint8Array or string
|
|
20
|
+
* Readable.from is ideal but was added in node.js v12.3.0 and v10.17.0
|
|
21
|
+
*/
|
|
22
|
+
function streamFromBody(body) {
|
|
23
|
+
return new stream.Readable({
|
|
24
|
+
read() {
|
|
25
|
+
this.push(body);
|
|
26
|
+
this.push(null);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Creates a Transport that uses native the native 'http' and 'https' modules to send events to Sentry.
|
|
33
|
+
*/
|
|
34
|
+
function makeNodeTransport(options) {
|
|
35
|
+
let urlSegments;
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
urlSegments = new URL(options.url);
|
|
39
|
+
} catch (e) {
|
|
40
|
+
utils.consoleSandbox(() => {
|
|
41
|
+
// eslint-disable-next-line no-console
|
|
42
|
+
console.warn(
|
|
43
|
+
'[@sentry/node]: Invalid dsn or tunnel option, will not send any events. The tunnel option must be a full URL when used.',
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
return core.createTransport(options, () => Promise.resolve({}));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const isHttps = urlSegments.protocol === 'https:';
|
|
50
|
+
|
|
51
|
+
// Proxy prioritization: http => `options.proxy` | `process.env.http_proxy`
|
|
52
|
+
// Proxy prioritization: https => `options.proxy` | `process.env.https_proxy` | `process.env.http_proxy`
|
|
53
|
+
const proxy = applyNoProxyOption(
|
|
54
|
+
urlSegments,
|
|
55
|
+
options.proxy || (isHttps ? process.env.https_proxy : undefined) || process.env.http_proxy,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const nativeHttpModule = isHttps ? https : http;
|
|
59
|
+
const keepAlive = options.keepAlive === undefined ? false : options.keepAlive;
|
|
60
|
+
|
|
61
|
+
// TODO(v7): Evaluate if we can set keepAlive to true. This would involve testing for memory leaks in older node
|
|
62
|
+
// versions(>= 8) as they had memory leaks when using it: #2555
|
|
63
|
+
const agent = proxy
|
|
64
|
+
? (new index.HttpsProxyAgent(proxy) )
|
|
65
|
+
: new nativeHttpModule.Agent({ keepAlive, maxSockets: 30, timeout: 2000 });
|
|
66
|
+
|
|
67
|
+
// This ensures we do not generate any spans in OpenTelemetry for the transport
|
|
68
|
+
return core.suppressTracing(() => {
|
|
69
|
+
const requestExecutor = createRequestExecutor(options, _nullishCoalesce(options.httpModule, () => ( nativeHttpModule)), agent);
|
|
70
|
+
return core.createTransport(options, requestExecutor);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Honors the `no_proxy` env variable with the highest priority to allow for hosts exclusion.
|
|
76
|
+
*
|
|
77
|
+
* @param transportUrl The URL the transport intends to send events to.
|
|
78
|
+
* @param proxy The client configured proxy.
|
|
79
|
+
* @returns A proxy the transport should use.
|
|
80
|
+
*/
|
|
81
|
+
function applyNoProxyOption(transportUrlSegments, proxy) {
|
|
82
|
+
const { no_proxy } = process.env;
|
|
83
|
+
|
|
84
|
+
const urlIsExemptFromProxy =
|
|
85
|
+
no_proxy &&
|
|
86
|
+
no_proxy
|
|
87
|
+
.split(',')
|
|
88
|
+
.some(
|
|
89
|
+
exemption => transportUrlSegments.host.endsWith(exemption) || transportUrlSegments.hostname.endsWith(exemption),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
if (urlIsExemptFromProxy) {
|
|
93
|
+
return undefined;
|
|
94
|
+
} else {
|
|
95
|
+
return proxy;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Creates a RequestExecutor to be used with `createTransport`.
|
|
101
|
+
*/
|
|
102
|
+
function createRequestExecutor(
|
|
103
|
+
options,
|
|
104
|
+
httpModule,
|
|
105
|
+
agent,
|
|
106
|
+
) {
|
|
107
|
+
const { hostname, pathname, port, protocol, search } = new URL(options.url);
|
|
108
|
+
return function makeRequest(request) {
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
let body = streamFromBody(request.body);
|
|
111
|
+
|
|
112
|
+
const headers = { ...options.headers };
|
|
113
|
+
|
|
114
|
+
if (request.body.length > GZIP_THRESHOLD) {
|
|
115
|
+
headers['content-encoding'] = 'gzip';
|
|
116
|
+
body = body.pipe(zlib.createGzip());
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const req = httpModule.request(
|
|
120
|
+
{
|
|
121
|
+
method: 'POST',
|
|
122
|
+
agent,
|
|
123
|
+
headers,
|
|
124
|
+
hostname,
|
|
125
|
+
path: `${pathname}${search}`,
|
|
126
|
+
port,
|
|
127
|
+
protocol,
|
|
128
|
+
ca: options.caCerts,
|
|
129
|
+
},
|
|
130
|
+
res => {
|
|
131
|
+
res.on('data', () => {
|
|
132
|
+
// Drain socket
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
res.on('end', () => {
|
|
136
|
+
// Drain socket
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
res.setEncoding('utf8');
|
|
140
|
+
|
|
141
|
+
// "Key-value pairs of header names and values. Header names are lower-cased."
|
|
142
|
+
// https://nodejs.org/api/http.html#http_message_headers
|
|
143
|
+
const retryAfterHeader = _nullishCoalesce(res.headers['retry-after'], () => ( null));
|
|
144
|
+
const rateLimitsHeader = _nullishCoalesce(res.headers['x-sentry-rate-limits'], () => ( null));
|
|
145
|
+
|
|
146
|
+
resolve({
|
|
147
|
+
statusCode: res.statusCode,
|
|
148
|
+
headers: {
|
|
149
|
+
'retry-after': retryAfterHeader,
|
|
150
|
+
'x-sentry-rate-limits': Array.isArray(rateLimitsHeader) ? rateLimitsHeader[0] : rateLimitsHeader,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
req.on('error', reject);
|
|
157
|
+
body.pipe(req);
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
exports.makeNodeTransport = makeNodeTransport;
|
|
163
|
+
//# sourceMappingURL=http.js.map
|