@sentry/node 9.20.0 → 9.22.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/build/cjs/integrations/anr/index.js +1 -1
- package/build/cjs/integrations/http/SentryHttpInstrumentation.js +63 -68
- package/build/cjs/integrations/http/SentryHttpInstrumentation.js.map +1 -1
- package/build/cjs/integrations/local-variables/local-variables-async.js +1 -1
- package/build/cjs/integrations/node-fetch/SentryNodeFetchInstrumentation.js +29 -10
- package/build/cjs/integrations/node-fetch/SentryNodeFetchInstrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/fastify/fastify-otel/index.js +489 -0
- package/build/cjs/integrations/tracing/fastify/fastify-otel/index.js.map +1 -0
- package/build/cjs/integrations/tracing/fastify/index.js +2 -2
- package/build/cjs/integrations/tracing/fastify/index.js.map +1 -1
- package/build/esm/integrations/anr/index.js +1 -1
- package/build/esm/integrations/anr/worker-script.js +2 -2
- package/build/esm/integrations/http/SentryHttpInstrumentation.js +64 -69
- package/build/esm/integrations/http/SentryHttpInstrumentation.js.map +1 -1
- package/build/esm/integrations/local-variables/local-variables-async.js +1 -1
- package/build/esm/integrations/local-variables/worker-script.js +2 -2
- package/build/esm/integrations/node-fetch/SentryNodeFetchInstrumentation.js +30 -11
- package/build/esm/integrations/node-fetch/SentryNodeFetchInstrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/fastify/fastify-otel/index.js +487 -0
- package/build/esm/integrations/tracing/fastify/fastify-otel/index.js.map +1 -0
- package/build/esm/integrations/tracing/fastify/index.js +1 -1
- package/build/esm/integrations/tracing/fastify/index.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/types/integrations/http/SentryHttpInstrumentation.d.ts +5 -0
- package/build/types/integrations/http/SentryHttpInstrumentation.d.ts.map +1 -1
- package/build/types/integrations/node-fetch/SentryNodeFetchInstrumentation.d.ts +5 -0
- package/build/types/integrations/node-fetch/SentryNodeFetchInstrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/fastify/index.d.ts.map +1 -1
- package/build/types-ts3.8/integrations/http/SentryHttpInstrumentation.d.ts +5 -0
- package/build/types-ts3.8/integrations/node-fetch/SentryNodeFetchInstrumentation.d.ts +5 -0
- package/package.json +5 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { subscribe, unsubscribe } from 'node:diagnostics_channel';
|
|
2
2
|
import { propagation, context } from '@opentelemetry/api';
|
|
3
|
-
import { VERSION } from '@opentelemetry/core';
|
|
3
|
+
import { VERSION, isTracingSuppressed } from '@opentelemetry/core';
|
|
4
4
|
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
|
|
5
5
|
import { LRUMap, logger, getClient, getTraceData, getIsolationScope, httpRequestToRequestData, stripUrlQueryAndFragment, withIsolationScope, generateSpanId, getCurrentScope, addNonEnumerableProperty, getBreadcrumbLogLevelFromHttpStatusCode, addBreadcrumb, parseUrl, getSanitizedUrlString } from '@sentry/core';
|
|
6
6
|
import { shouldPropagateTraceForUrl } from '@sentry/opentelemetry';
|
|
@@ -32,6 +32,7 @@ class SentryHttpInstrumentation extends InstrumentationBase {
|
|
|
32
32
|
super(INSTRUMENTATION_NAME, VERSION, config);
|
|
33
33
|
|
|
34
34
|
this._propagationDecisionMap = new LRUMap(100);
|
|
35
|
+
this._ignoreOutgoingRequestsMap = new WeakMap();
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
/** @inheritdoc */
|
|
@@ -60,6 +61,37 @@ class SentryHttpInstrumentation extends InstrumentationBase {
|
|
|
60
61
|
this._onOutgoingRequestCreated(data.request);
|
|
61
62
|
}) ;
|
|
62
63
|
|
|
64
|
+
const wrap = (moduleExports) => {
|
|
65
|
+
if (hasRegisteredHandlers) {
|
|
66
|
+
return moduleExports;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
hasRegisteredHandlers = true;
|
|
70
|
+
|
|
71
|
+
subscribe('http.server.request.start', onHttpServerRequestStart);
|
|
72
|
+
subscribe('http.client.response.finish', onHttpClientResponseFinish);
|
|
73
|
+
|
|
74
|
+
// When an error happens, we still want to have a breadcrumb
|
|
75
|
+
// In this case, `http.client.response.finish` is not triggered
|
|
76
|
+
subscribe('http.client.request.error', onHttpClientRequestError);
|
|
77
|
+
|
|
78
|
+
// NOTE: This channel only exist since Node 22
|
|
79
|
+
// Before that, outgoing requests are not patched
|
|
80
|
+
// and trace headers are not propagated, sadly.
|
|
81
|
+
if (this.getConfig().propagateTraceInOutgoingRequests) {
|
|
82
|
+
subscribe('http.client.request.created', onHttpClientRequestCreated);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return moduleExports;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const unwrap = () => {
|
|
89
|
+
unsubscribe('http.server.request.start', onHttpServerRequestStart);
|
|
90
|
+
unsubscribe('http.client.response.finish', onHttpClientResponseFinish);
|
|
91
|
+
unsubscribe('http.client.request.error', onHttpClientRequestError);
|
|
92
|
+
unsubscribe('http.client.request.created', onHttpClientRequestCreated);
|
|
93
|
+
};
|
|
94
|
+
|
|
63
95
|
/**
|
|
64
96
|
* You may be wondering why we register these diagnostics-channel listeners
|
|
65
97
|
* in such a convoluted way (as InstrumentationNodeModuleDefinition...)˝,
|
|
@@ -69,64 +101,8 @@ class SentryHttpInstrumentation extends InstrumentationBase {
|
|
|
69
101
|
* especially the "import-on-top" pattern of setting up ESM applications.
|
|
70
102
|
*/
|
|
71
103
|
return [
|
|
72
|
-
new InstrumentationNodeModuleDefinition(
|
|
73
|
-
|
|
74
|
-
['*'],
|
|
75
|
-
(moduleExports) => {
|
|
76
|
-
if (hasRegisteredHandlers) {
|
|
77
|
-
return moduleExports;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
hasRegisteredHandlers = true;
|
|
81
|
-
|
|
82
|
-
subscribe('http.server.request.start', onHttpServerRequestStart);
|
|
83
|
-
subscribe('http.client.response.finish', onHttpClientResponseFinish);
|
|
84
|
-
|
|
85
|
-
// When an error happens, we still want to have a breadcrumb
|
|
86
|
-
// In this case, `http.client.response.finish` is not triggered
|
|
87
|
-
subscribe('http.client.request.error', onHttpClientRequestError);
|
|
88
|
-
|
|
89
|
-
// NOTE: This channel only exist since Node 23
|
|
90
|
-
// Before that, outgoing requests are not patched
|
|
91
|
-
// and trace headers are not propagated, sadly.
|
|
92
|
-
if (this.getConfig().propagateTraceInOutgoingRequests) {
|
|
93
|
-
subscribe('http.client.request.created', onHttpClientRequestCreated);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return moduleExports;
|
|
97
|
-
},
|
|
98
|
-
() => {
|
|
99
|
-
unsubscribe('http.server.request.start', onHttpServerRequestStart);
|
|
100
|
-
unsubscribe('http.client.response.finish', onHttpClientResponseFinish);
|
|
101
|
-
unsubscribe('http.client.request.error', onHttpClientRequestError);
|
|
102
|
-
unsubscribe('http.client.request.created', onHttpClientRequestCreated);
|
|
103
|
-
},
|
|
104
|
-
),
|
|
105
|
-
new InstrumentationNodeModuleDefinition(
|
|
106
|
-
'https',
|
|
107
|
-
['*'],
|
|
108
|
-
(moduleExports) => {
|
|
109
|
-
if (hasRegisteredHandlers) {
|
|
110
|
-
return moduleExports;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
hasRegisteredHandlers = true;
|
|
114
|
-
|
|
115
|
-
subscribe('http.server.request.start', onHttpServerRequestStart);
|
|
116
|
-
subscribe('http.client.response.finish', onHttpClientResponseFinish);
|
|
117
|
-
|
|
118
|
-
// When an error happens, we still want to have a breadcrumb
|
|
119
|
-
// In this case, `http.client.response.finish` is not triggered
|
|
120
|
-
subscribe('http.client.request.error', onHttpClientRequestError);
|
|
121
|
-
|
|
122
|
-
return moduleExports;
|
|
123
|
-
},
|
|
124
|
-
() => {
|
|
125
|
-
unsubscribe('http.server.request.start', onHttpServerRequestStart);
|
|
126
|
-
unsubscribe('http.client.response.finish', onHttpClientResponseFinish);
|
|
127
|
-
unsubscribe('http.client.request.error', onHttpClientRequestError);
|
|
128
|
-
},
|
|
129
|
-
),
|
|
104
|
+
new InstrumentationNodeModuleDefinition('http', ['*'], wrap, unwrap),
|
|
105
|
+
new InstrumentationNodeModuleDefinition('https', ['*'], wrap, unwrap),
|
|
130
106
|
];
|
|
131
107
|
}
|
|
132
108
|
|
|
@@ -139,13 +115,12 @@ class SentryHttpInstrumentation extends InstrumentationBase {
|
|
|
139
115
|
|
|
140
116
|
const _breadcrumbs = this.getConfig().breadcrumbs;
|
|
141
117
|
const breadCrumbsEnabled = typeof _breadcrumbs === 'undefined' ? true : _breadcrumbs;
|
|
142
|
-
const options = getRequestOptions(request);
|
|
143
118
|
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
|
|
119
|
+
// Note: We cannot rely on the map being set by `_onOutgoingRequestCreated`, because that is not run in Node <22
|
|
120
|
+
const shouldIgnore = this._ignoreOutgoingRequestsMap.get(request) ?? this._shouldIgnoreOutgoingRequest(request);
|
|
121
|
+
this._ignoreOutgoingRequestsMap.set(request, shouldIgnore);
|
|
147
122
|
|
|
148
|
-
if (breadCrumbsEnabled &&
|
|
123
|
+
if (breadCrumbsEnabled && !shouldIgnore) {
|
|
149
124
|
addRequestBreadcrumb(request, response);
|
|
150
125
|
}
|
|
151
126
|
}
|
|
@@ -155,15 +130,16 @@ class SentryHttpInstrumentation extends InstrumentationBase {
|
|
|
155
130
|
* It has access to the request object, and can mutate it before the request is sent.
|
|
156
131
|
*/
|
|
157
132
|
_onOutgoingRequestCreated(request) {
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
const shouldPropagate =
|
|
161
|
-
typeof ignoreOutgoingRequests === 'function' ? !ignoreOutgoingRequests(url, getRequestOptions(request)) : true;
|
|
133
|
+
const shouldIgnore = this._ignoreOutgoingRequestsMap.get(request) ?? this._shouldIgnoreOutgoingRequest(request);
|
|
134
|
+
this._ignoreOutgoingRequestsMap.set(request, shouldIgnore);
|
|
162
135
|
|
|
163
|
-
if (
|
|
136
|
+
if (shouldIgnore) {
|
|
164
137
|
return;
|
|
165
138
|
}
|
|
166
139
|
|
|
140
|
+
// Add trace propagation headers
|
|
141
|
+
const url = getRequestUrl(request);
|
|
142
|
+
|
|
167
143
|
// Manually add the trace headers, if it applies
|
|
168
144
|
// Note: We do not use `propagation.inject()` here, because our propagator relies on an active span
|
|
169
145
|
// Which we do not have in this case
|
|
@@ -279,6 +255,25 @@ class SentryHttpInstrumentation extends InstrumentationBase {
|
|
|
279
255
|
|
|
280
256
|
server.emit = newEmit;
|
|
281
257
|
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Check if the given outgoing request should be ignored.
|
|
261
|
+
*/
|
|
262
|
+
_shouldIgnoreOutgoingRequest(request) {
|
|
263
|
+
if (isTracingSuppressed(context.active())) {
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const ignoreOutgoingRequests = this.getConfig().ignoreOutgoingRequests;
|
|
268
|
+
|
|
269
|
+
if (!ignoreOutgoingRequests) {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const options = getRequestOptions(request);
|
|
274
|
+
const url = getRequestUrl(request);
|
|
275
|
+
return ignoreOutgoingRequests(url, options);
|
|
276
|
+
}
|
|
282
277
|
}
|
|
283
278
|
|
|
284
279
|
/** Add a breadcrumb for outgoing requests. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SentryHttpInstrumentation.js","sources":["../../../../src/integrations/http/SentryHttpInstrumentation.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport type { ChannelListener } from 'node:diagnostics_channel';\nimport { subscribe, unsubscribe } from 'node:diagnostics_channel';\nimport type * as http from 'node:http';\nimport type * as https from 'node:https';\nimport type { EventEmitter } from 'node:stream';\nimport { context, propagation } from '@opentelemetry/api';\nimport { VERSION } from '@opentelemetry/core';\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';\nimport type { AggregationCounts, Client, SanitizedRequestData, Scope } from '@sentry/core';\nimport {\n addBreadcrumb,\n addNonEnumerableProperty,\n generateSpanId,\n getBreadcrumbLogLevelFromHttpStatusCode,\n getClient,\n getCurrentScope,\n getIsolationScope,\n getSanitizedUrlString,\n getTraceData,\n httpRequestToRequestData,\n logger,\n LRUMap,\n parseUrl,\n stripUrlQueryAndFragment,\n withIsolationScope,\n} from '@sentry/core';\nimport { shouldPropagateTraceForUrl } from '@sentry/opentelemetry';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { mergeBaggageHeaders } from '../../utils/baggage';\nimport { getRequestUrl } from '../../utils/getRequestUrl';\n\nconst INSTRUMENTATION_NAME = '@sentry/instrumentation-http';\n\ntype Http = typeof http;\ntype Https = typeof https;\n\nexport type SentryHttpInstrumentationOptions = InstrumentationConfig & {\n /**\n * Whether breadcrumbs should be recorded for requests.\n *\n * @default `true`\n */\n breadcrumbs?: boolean;\n\n /**\n * Whether to extract the trace ID from the `sentry-trace` header for incoming requests.\n * By default this is done by the HttpInstrumentation, but if that is not added (e.g. because tracing is disabled, ...)\n * then this instrumentation can take over.\n *\n * @default `false`\n */\n extractIncomingTraceFromHeader?: boolean;\n\n /**\n * Whether to propagate Sentry trace headers in outgoing requests.\n * By default this is done by the HttpInstrumentation, but if that is not added (e.g. because tracing is disabled)\n * then this instrumentation can take over.\n *\n * @default `false`\n */\n propagateTraceInOutgoingRequests?: boolean;\n\n /**\n * Do not capture breadcrumbs for outgoing HTTP requests to URLs where the given callback returns `true`.\n * For the scope of this instrumentation, this callback only controls breadcrumb creation.\n * The same option can be passed to the top-level httpIntegration where it controls both, breadcrumb and\n * span creation.\n *\n * @param url Contains the entire URL, including query string (if any), protocol, host, etc. of the outgoing request.\n * @param request Contains the {@type RequestOptions} object used to make the outgoing request.\n */\n ignoreOutgoingRequests?: (url: string, request: http.RequestOptions) => boolean;\n\n /**\n * Do not capture the request body for incoming HTTP requests to URLs where the given callback returns `true`.\n * This can be useful for long running requests where the body is not needed and we want to avoid capturing it.\n *\n * @param url Contains the entire URL, including query string (if any), protocol, host, etc. of the outgoing request.\n * @param request Contains the {@type RequestOptions} object used to make the outgoing request.\n */\n ignoreIncomingRequestBody?: (url: string, request: http.RequestOptions) => boolean;\n\n /**\n * Controls the maximum size of incoming HTTP request bodies attached to events.\n *\n * Available options:\n * - 'none': No request bodies will be attached\n * - 'small': Request bodies up to 1,000 bytes will be attached\n * - 'medium': Request bodies up to 10,000 bytes will be attached (default)\n * - 'always': Request bodies will always be attached\n *\n * Note that even with 'always' setting, bodies exceeding 1MB will never be attached\n * for performance and security reasons.\n *\n * @default 'medium'\n */\n maxIncomingRequestBodySize?: 'none' | 'small' | 'medium' | 'always';\n\n /**\n * Whether the integration should create [Sessions](https://docs.sentry.io/product/releases/health/#sessions) for incoming requests to track the health and crash-free rate of your releases in Sentry.\n * Read more about Release Health: https://docs.sentry.io/product/releases/health/\n *\n * Defaults to `true`.\n */\n trackIncomingRequestsAsSessions?: boolean;\n\n /**\n * Number of milliseconds until sessions tracked with `trackIncomingRequestsAsSessions` will be flushed as a session aggregate.\n *\n * Defaults to `60000` (60s).\n */\n sessionFlushingDelayMS?: number;\n};\n\n// We only want to capture request bodies up to 1mb.\nconst MAX_BODY_BYTE_LENGTH = 1024 * 1024;\n\n/**\n * This custom HTTP instrumentation is used to isolate incoming requests and annotate them with additional information.\n * It does not emit any spans.\n *\n * The reason this is isolated from the OpenTelemetry instrumentation is that users may overwrite this,\n * which would lead to Sentry not working as expected.\n *\n * Important note: Contrary to other OTEL instrumentation, this one cannot be unwrapped.\n * It only does minimal things though and does not emit any spans.\n *\n * This is heavily inspired & adapted from:\n * https://github.com/open-telemetry/opentelemetry-js/blob/f8ab5592ddea5cba0a3b33bf8d74f27872c0367f/experimental/packages/opentelemetry-instrumentation-http/src/http.ts\n */\nexport class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpInstrumentationOptions> {\n private _propagationDecisionMap: LRUMap<string, boolean>;\n\n public constructor(config: SentryHttpInstrumentationOptions = {}) {\n super(INSTRUMENTATION_NAME, VERSION, config);\n\n this._propagationDecisionMap = new LRUMap<string, boolean>(100);\n }\n\n /** @inheritdoc */\n public init(): [InstrumentationNodeModuleDefinition, InstrumentationNodeModuleDefinition] {\n // We register handlers when either http or https is instrumented\n // but we only want to register them once, whichever is loaded first\n let hasRegisteredHandlers = false;\n\n const onHttpServerRequestStart = ((_data: unknown) => {\n const data = _data as { server: http.Server };\n this._patchServerEmitOnce(data.server);\n }) satisfies ChannelListener;\n\n const onHttpClientResponseFinish = ((_data: unknown) => {\n const data = _data as { request: http.ClientRequest; response: http.IncomingMessage };\n this._onOutgoingRequestFinish(data.request, data.response);\n }) satisfies ChannelListener;\n\n const onHttpClientRequestError = ((_data: unknown) => {\n const data = _data as { request: http.ClientRequest };\n this._onOutgoingRequestFinish(data.request, undefined);\n }) satisfies ChannelListener;\n\n const onHttpClientRequestCreated = ((_data: unknown) => {\n const data = _data as { request: http.ClientRequest };\n this._onOutgoingRequestCreated(data.request);\n }) satisfies ChannelListener;\n\n /**\n * You may be wondering why we register these diagnostics-channel listeners\n * in such a convoluted way (as InstrumentationNodeModuleDefinition...)˝,\n * instead of simply subscribing to the events once in here.\n * The reason for this is timing semantics: These functions are called once the http or https module is loaded.\n * If we'd subscribe before that, there seem to be conflicts with the OTEL native instrumentation in some scenarios,\n * especially the \"import-on-top\" pattern of setting up ESM applications.\n */\n return [\n new InstrumentationNodeModuleDefinition(\n 'http',\n ['*'],\n (moduleExports: Http): Http => {\n if (hasRegisteredHandlers) {\n return moduleExports;\n }\n\n hasRegisteredHandlers = true;\n\n subscribe('http.server.request.start', onHttpServerRequestStart);\n subscribe('http.client.response.finish', onHttpClientResponseFinish);\n\n // When an error happens, we still want to have a breadcrumb\n // In this case, `http.client.response.finish` is not triggered\n subscribe('http.client.request.error', onHttpClientRequestError);\n\n // NOTE: This channel only exist since Node 23\n // Before that, outgoing requests are not patched\n // and trace headers are not propagated, sadly.\n if (this.getConfig().propagateTraceInOutgoingRequests) {\n subscribe('http.client.request.created', onHttpClientRequestCreated);\n }\n\n return moduleExports;\n },\n () => {\n unsubscribe('http.server.request.start', onHttpServerRequestStart);\n unsubscribe('http.client.response.finish', onHttpClientResponseFinish);\n unsubscribe('http.client.request.error', onHttpClientRequestError);\n unsubscribe('http.client.request.created', onHttpClientRequestCreated);\n },\n ),\n new InstrumentationNodeModuleDefinition(\n 'https',\n ['*'],\n (moduleExports: Https): Https => {\n if (hasRegisteredHandlers) {\n return moduleExports;\n }\n\n hasRegisteredHandlers = true;\n\n subscribe('http.server.request.start', onHttpServerRequestStart);\n subscribe('http.client.response.finish', onHttpClientResponseFinish);\n\n // When an error happens, we still want to have a breadcrumb\n // In this case, `http.client.response.finish` is not triggered\n subscribe('http.client.request.error', onHttpClientRequestError);\n\n return moduleExports;\n },\n () => {\n unsubscribe('http.server.request.start', onHttpServerRequestStart);\n unsubscribe('http.client.response.finish', onHttpClientResponseFinish);\n unsubscribe('http.client.request.error', onHttpClientRequestError);\n },\n ),\n ];\n }\n\n /**\n * This is triggered when an outgoing request finishes.\n * It has access to the final request and response objects.\n */\n private _onOutgoingRequestFinish(request: http.ClientRequest, response?: http.IncomingMessage): void {\n DEBUG_BUILD && logger.log(INSTRUMENTATION_NAME, 'Handling finished outgoing request');\n\n const _breadcrumbs = this.getConfig().breadcrumbs;\n const breadCrumbsEnabled = typeof _breadcrumbs === 'undefined' ? true : _breadcrumbs;\n const options = getRequestOptions(request);\n\n const _ignoreOutgoingRequests = this.getConfig().ignoreOutgoingRequests;\n const shouldCreateBreadcrumb =\n typeof _ignoreOutgoingRequests === 'function' ? !_ignoreOutgoingRequests(getRequestUrl(request), options) : true;\n\n if (breadCrumbsEnabled && shouldCreateBreadcrumb) {\n addRequestBreadcrumb(request, response);\n }\n }\n\n /**\n * This is triggered when an outgoing request is created.\n * It has access to the request object, and can mutate it before the request is sent.\n */\n private _onOutgoingRequestCreated(request: http.ClientRequest): void {\n const url = getRequestUrl(request);\n const ignoreOutgoingRequests = this.getConfig().ignoreOutgoingRequests;\n const shouldPropagate =\n typeof ignoreOutgoingRequests === 'function' ? !ignoreOutgoingRequests(url, getRequestOptions(request)) : true;\n\n if (!shouldPropagate) {\n return;\n }\n\n // Manually add the trace headers, if it applies\n // Note: We do not use `propagation.inject()` here, because our propagator relies on an active span\n // Which we do not have in this case\n const tracePropagationTargets = getClient()?.getOptions().tracePropagationTargets;\n const addedHeaders = shouldPropagateTraceForUrl(url, tracePropagationTargets, this._propagationDecisionMap)\n ? getTraceData()\n : undefined;\n\n if (!addedHeaders) {\n return;\n }\n\n const { 'sentry-trace': sentryTrace, baggage } = addedHeaders;\n\n // We do not want to overwrite existing header here, if it was already set\n if (sentryTrace && !request.getHeader('sentry-trace')) {\n request.setHeader('sentry-trace', sentryTrace);\n logger.log(INSTRUMENTATION_NAME, 'Added sentry-trace header to outgoing request');\n }\n\n if (baggage) {\n // For baggage, we make sure to merge this into a possibly existing header\n const newBaggage = mergeBaggageHeaders(request.getHeader('baggage'), baggage);\n if (newBaggage) {\n request.setHeader('baggage', newBaggage);\n }\n }\n }\n\n /**\n * Patch a server.emit function to handle process isolation for incoming requests.\n * This will only patch the emit function if it was not already patched.\n */\n private _patchServerEmitOnce(server: http.Server): void {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalEmit = server.emit;\n\n // This means it was already patched, do nothing\n if ((originalEmit as { __sentry_patched__?: boolean }).__sentry_patched__) {\n return;\n }\n\n DEBUG_BUILD && logger.log(INSTRUMENTATION_NAME, 'Patching server.emit');\n\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const instrumentation = this;\n const { ignoreIncomingRequestBody, maxIncomingRequestBodySize = 'medium' } = instrumentation.getConfig();\n\n const newEmit = new Proxy(originalEmit, {\n apply(target, thisArg, args: [event: string, ...args: unknown[]]) {\n // Only traces request events\n if (args[0] !== 'request') {\n return target.apply(thisArg, args);\n }\n\n DEBUG_BUILD && logger.log(INSTRUMENTATION_NAME, 'Handling incoming request');\n\n const isolationScope = getIsolationScope().clone();\n const request = args[1] as http.IncomingMessage;\n const response = args[2] as http.OutgoingMessage;\n\n const normalizedRequest = httpRequestToRequestData(request);\n\n // request.ip is non-standard but some frameworks set this\n const ipAddress = (request as { ip?: string }).ip || request.socket?.remoteAddress;\n\n const url = request.url || '/';\n if (!ignoreIncomingRequestBody?.(url, request) && maxIncomingRequestBodySize !== 'none') {\n patchRequestToCaptureBody(request, isolationScope, maxIncomingRequestBodySize);\n }\n\n // Update the isolation scope, isolate this request\n isolationScope.setSDKProcessingMetadata({ normalizedRequest, ipAddress });\n\n // attempt to update the scope's `transactionName` based on the request URL\n // Ideally, framework instrumentations coming after the HttpInstrumentation\n // update the transactionName once we get a parameterized route.\n const httpMethod = (request.method || 'GET').toUpperCase();\n const httpTarget = stripUrlQueryAndFragment(url);\n\n const bestEffortTransactionName = `${httpMethod} ${httpTarget}`;\n\n isolationScope.setTransactionName(bestEffortTransactionName);\n\n if (instrumentation.getConfig().trackIncomingRequestsAsSessions !== false) {\n recordRequestSession({\n requestIsolationScope: isolationScope,\n response,\n sessionFlushingDelayMS: instrumentation.getConfig().sessionFlushingDelayMS ?? 60_000,\n });\n }\n\n return withIsolationScope(isolationScope, () => {\n // Set a new propagationSpanId for this request\n // We rely on the fact that `withIsolationScope()` will implicitly also fork the current scope\n // This way we can save an \"unnecessary\" `withScope()` invocation\n getCurrentScope().getPropagationContext().propagationSpanId = generateSpanId();\n\n // If we don't want to extract the trace from the header, we can skip this\n if (!instrumentation.getConfig().extractIncomingTraceFromHeader) {\n return target.apply(thisArg, args);\n }\n\n const ctx = propagation.extract(context.active(), normalizedRequest.headers);\n return context.with(ctx, () => {\n return target.apply(thisArg, args);\n });\n });\n },\n });\n\n addNonEnumerableProperty(newEmit, '__sentry_patched__', true);\n\n server.emit = newEmit;\n }\n}\n\n/** Add a breadcrumb for outgoing requests. */\nfunction addRequestBreadcrumb(request: http.ClientRequest, response: http.IncomingMessage | undefined): void {\n const data = getBreadcrumbData(request);\n\n const statusCode = response?.statusCode;\n const level = getBreadcrumbLogLevelFromHttpStatusCode(statusCode);\n\n addBreadcrumb(\n {\n category: 'http',\n data: {\n status_code: statusCode,\n ...data,\n },\n type: 'http',\n level,\n },\n {\n event: 'response',\n request,\n response,\n },\n );\n}\n\nfunction getBreadcrumbData(request: http.ClientRequest): Partial<SanitizedRequestData> {\n try {\n // `request.host` does not contain the port, but the host header does\n const host = request.getHeader('host') || request.host;\n const url = new URL(request.path, `${request.protocol}//${host}`);\n const parsedUrl = parseUrl(url.toString());\n\n const data: Partial<SanitizedRequestData> = {\n url: getSanitizedUrlString(parsedUrl),\n 'http.method': request.method || 'GET',\n };\n\n if (parsedUrl.search) {\n data['http.query'] = parsedUrl.search;\n }\n if (parsedUrl.hash) {\n data['http.fragment'] = parsedUrl.hash;\n }\n\n return data;\n } catch {\n return {};\n }\n}\n\n/**\n * This method patches the request object to capture the body.\n * Instead of actually consuming the streamed body ourselves, which has potential side effects,\n * we monkey patch `req.on('data')` to intercept the body chunks.\n * This way, we only read the body if the user also consumes the body, ensuring we do not change any behavior in unexpected ways.\n */\nfunction patchRequestToCaptureBody(\n req: http.IncomingMessage,\n isolationScope: Scope,\n maxIncomingRequestBodySize: 'small' | 'medium' | 'always',\n): void {\n let bodyByteLength = 0;\n const chunks: Buffer[] = [];\n\n DEBUG_BUILD && logger.log(INSTRUMENTATION_NAME, 'Patching request.on');\n\n /**\n * We need to keep track of the original callbacks, in order to be able to remove listeners again.\n * Since `off` depends on having the exact same function reference passed in, we need to be able to map\n * original listeners to our wrapped ones.\n */\n const callbackMap = new WeakMap();\n\n const maxBodySize =\n maxIncomingRequestBodySize === 'small'\n ? 1_000\n : maxIncomingRequestBodySize === 'medium'\n ? 10_000\n : MAX_BODY_BYTE_LENGTH;\n\n try {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n req.on = new Proxy(req.on, {\n apply: (target, thisArg, args: Parameters<typeof req.on>) => {\n const [event, listener, ...restArgs] = args;\n\n if (event === 'data') {\n DEBUG_BUILD &&\n logger.log(INSTRUMENTATION_NAME, `Handling request.on(\"data\") with maximum body size of ${maxBodySize}b`);\n\n const callback = new Proxy(listener, {\n apply: (target, thisArg, args: Parameters<typeof listener>) => {\n try {\n const chunk = args[0] as Buffer | string;\n const bufferifiedChunk = Buffer.from(chunk);\n\n if (bodyByteLength < maxBodySize) {\n chunks.push(bufferifiedChunk);\n bodyByteLength += bufferifiedChunk.byteLength;\n } else if (DEBUG_BUILD) {\n logger.log(\n INSTRUMENTATION_NAME,\n `Dropping request body chunk because maximum body length of ${maxBodySize}b is exceeded.`,\n );\n }\n } catch (err) {\n DEBUG_BUILD && logger.error(INSTRUMENTATION_NAME, 'Encountered error while storing body chunk.');\n }\n\n return Reflect.apply(target, thisArg, args);\n },\n });\n\n callbackMap.set(listener, callback);\n\n return Reflect.apply(target, thisArg, [event, callback, ...restArgs]);\n }\n\n return Reflect.apply(target, thisArg, args);\n },\n });\n\n // Ensure we also remove callbacks correctly\n // eslint-disable-next-line @typescript-eslint/unbound-method\n req.off = new Proxy(req.off, {\n apply: (target, thisArg, args: Parameters<typeof req.off>) => {\n const [, listener] = args;\n\n const callback = callbackMap.get(listener);\n if (callback) {\n callbackMap.delete(listener);\n\n const modifiedArgs = args.slice();\n modifiedArgs[1] = callback;\n return Reflect.apply(target, thisArg, modifiedArgs);\n }\n\n return Reflect.apply(target, thisArg, args);\n },\n });\n\n req.on('end', () => {\n try {\n const body = Buffer.concat(chunks).toString('utf-8');\n if (body) {\n // Using Buffer.byteLength here, because the body may contain characters that are not 1 byte long\n const bodyByteLength = Buffer.byteLength(body, 'utf-8');\n const truncatedBody =\n bodyByteLength > maxBodySize\n ? `${Buffer.from(body)\n .subarray(0, maxBodySize - 3)\n .toString('utf-8')}...`\n : body;\n\n isolationScope.setSDKProcessingMetadata({ normalizedRequest: { data: truncatedBody } });\n }\n } catch (error) {\n if (DEBUG_BUILD) {\n logger.error(INSTRUMENTATION_NAME, 'Error building captured request body', error);\n }\n }\n });\n } catch (error) {\n if (DEBUG_BUILD) {\n logger.error(INSTRUMENTATION_NAME, 'Error patching request to capture body', error);\n }\n }\n}\n\nfunction getRequestOptions(request: http.ClientRequest): http.RequestOptions {\n return {\n method: request.method,\n protocol: request.protocol,\n host: request.host,\n hostname: request.host,\n path: request.path,\n headers: request.getHeaders(),\n };\n}\n\n/**\n * Starts a session and tracks it in the context of a given isolation scope.\n * When the passed response is finished, the session is put into a task and is\n * aggregated with other sessions that may happen in a certain time window\n * (sessionFlushingDelayMs).\n *\n * The sessions are always aggregated by the client that is on the current scope\n * at the time of ending the response (if there is one).\n */\n// Exported for unit tests\nexport function recordRequestSession({\n requestIsolationScope,\n response,\n sessionFlushingDelayMS,\n}: {\n requestIsolationScope: Scope;\n response: EventEmitter;\n sessionFlushingDelayMS?: number;\n}): void {\n requestIsolationScope.setSDKProcessingMetadata({\n requestSession: { status: 'ok' },\n });\n response.once('close', () => {\n // We need to grab the client off the current scope instead of the isolation scope because the isolation scope doesn't hold any client out of the box.\n const client = getClient();\n const requestSession = requestIsolationScope.getScopeData().sdkProcessingMetadata.requestSession;\n\n if (client && requestSession) {\n DEBUG_BUILD && logger.debug(`Recorded request session with status: ${requestSession.status}`);\n\n const roundedDate = new Date();\n roundedDate.setSeconds(0, 0);\n const dateBucketKey = roundedDate.toISOString();\n\n const existingClientAggregate = clientToRequestSessionAggregatesMap.get(client);\n const bucket = existingClientAggregate?.[dateBucketKey] || { exited: 0, crashed: 0, errored: 0 };\n bucket[({ ok: 'exited', crashed: 'crashed', errored: 'errored' } as const)[requestSession.status]]++;\n\n if (existingClientAggregate) {\n existingClientAggregate[dateBucketKey] = bucket;\n } else {\n DEBUG_BUILD && logger.debug('Opened new request session aggregate.');\n const newClientAggregate = { [dateBucketKey]: bucket };\n clientToRequestSessionAggregatesMap.set(client, newClientAggregate);\n\n const flushPendingClientAggregates = (): void => {\n clearTimeout(timeout);\n unregisterClientFlushHook();\n clientToRequestSessionAggregatesMap.delete(client);\n\n const aggregatePayload: AggregationCounts[] = Object.entries(newClientAggregate).map(\n ([timestamp, value]) => ({\n started: timestamp,\n exited: value.exited,\n errored: value.errored,\n crashed: value.crashed,\n }),\n );\n client.sendSession({ aggregates: aggregatePayload });\n };\n\n const unregisterClientFlushHook = client.on('flush', () => {\n DEBUG_BUILD && logger.debug('Sending request session aggregate due to client flush');\n flushPendingClientAggregates();\n });\n const timeout = setTimeout(() => {\n DEBUG_BUILD && logger.debug('Sending request session aggregate due to flushing schedule');\n flushPendingClientAggregates();\n }, sessionFlushingDelayMS).unref();\n }\n }\n });\n}\n\nconst clientToRequestSessionAggregatesMap = new Map<\n Client,\n { [timestampRoundedToSeconds: string]: { exited: number; crashed: number; errored: number } }\n>();\n"],"names":[],"mappings":";;;;;;;;;;AAiCA,MAAM,oBAAA,GAAuB,8BAA8B;;AAmF3D;AACA,MAAM,oBAAqB,GAAE,IAAK,GAAE,IAAI;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,yBAAA,SAAkC,mBAAmB,CAAmC;;AAGrG,GAAS,WAAW,CAAC,MAAM,GAAqC,EAAE,EAAE;AACpE,IAAI,KAAK,CAAC,oBAAoB,EAAE,OAAO,EAAE,MAAM,CAAC;;AAEhD,IAAI,IAAI,CAAC,uBAAwB,GAAE,IAAI,MAAM,CAAkB,GAAG,CAAC;AACnE;;AAEA;AACA,GAAS,IAAI,GAA+E;AAC5F;AACA;AACA,IAAI,IAAI,qBAAsB,GAAE,KAAK;;AAErC,IAAI,MAAM,wBAAyB,IAAG,CAAC,KAAK,KAAc;AAC1D,MAAM,MAAM,IAAK,GAAE,KAAM;AACzB,MAAM,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC;AAC5C,KAAK,CAAE;;AAEP,IAAI,MAAM,0BAA2B,IAAG,CAAC,KAAK,KAAc;AAC5D,MAAM,MAAM,IAAK,GAAE,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AAA,EAAA,CAAA,OAAA,EAAA,MAAA;AACA,UAAA,WAAA,IAAA,MAAA,CAAA,KAAA,CAAA,uDAAA,CAAA;AACA,UAAA,4BAAA,EAAA;AACA,SAAA,CAAA;AACA,QAAA,MAAA,OAAA,GAAA,UAAA,CAAA,MAAA;AACA,UAAA,WAAA,IAAA,MAAA,CAAA,KAAA,CAAA,4DAAA,CAAA;AACA,UAAA,4BAAA,EAAA;AACA,SAAA,EAAA,sBAAA,CAAA,CAAA,KAAA,EAAA;AACA;AACA;AACA,GAAA,CAAA;AACA;;AAEA,MAAA,mCAAA,GAAA,IAAA;;AAGA,EAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"SentryHttpInstrumentation.js","sources":["../../../../src/integrations/http/SentryHttpInstrumentation.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport type { ChannelListener } from 'node:diagnostics_channel';\nimport { subscribe, unsubscribe } from 'node:diagnostics_channel';\nimport type * as http from 'node:http';\nimport type * as https from 'node:https';\nimport type { EventEmitter } from 'node:stream';\nimport { context, propagation } from '@opentelemetry/api';\nimport { isTracingSuppressed, VERSION } from '@opentelemetry/core';\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';\nimport type { AggregationCounts, Client, SanitizedRequestData, Scope } from '@sentry/core';\nimport {\n addBreadcrumb,\n addNonEnumerableProperty,\n generateSpanId,\n getBreadcrumbLogLevelFromHttpStatusCode,\n getClient,\n getCurrentScope,\n getIsolationScope,\n getSanitizedUrlString,\n getTraceData,\n httpRequestToRequestData,\n logger,\n LRUMap,\n parseUrl,\n stripUrlQueryAndFragment,\n withIsolationScope,\n} from '@sentry/core';\nimport { shouldPropagateTraceForUrl } from '@sentry/opentelemetry';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { mergeBaggageHeaders } from '../../utils/baggage';\nimport { getRequestUrl } from '../../utils/getRequestUrl';\n\nconst INSTRUMENTATION_NAME = '@sentry/instrumentation-http';\n\ntype Http = typeof http;\ntype Https = typeof https;\n\nexport type SentryHttpInstrumentationOptions = InstrumentationConfig & {\n /**\n * Whether breadcrumbs should be recorded for requests.\n *\n * @default `true`\n */\n breadcrumbs?: boolean;\n\n /**\n * Whether to extract the trace ID from the `sentry-trace` header for incoming requests.\n * By default this is done by the HttpInstrumentation, but if that is not added (e.g. because tracing is disabled, ...)\n * then this instrumentation can take over.\n *\n * @default `false`\n */\n extractIncomingTraceFromHeader?: boolean;\n\n /**\n * Whether to propagate Sentry trace headers in outgoing requests.\n * By default this is done by the HttpInstrumentation, but if that is not added (e.g. because tracing is disabled)\n * then this instrumentation can take over.\n *\n * @default `false`\n */\n propagateTraceInOutgoingRequests?: boolean;\n\n /**\n * Do not capture breadcrumbs for outgoing HTTP requests to URLs where the given callback returns `true`.\n * For the scope of this instrumentation, this callback only controls breadcrumb creation.\n * The same option can be passed to the top-level httpIntegration where it controls both, breadcrumb and\n * span creation.\n *\n * @param url Contains the entire URL, including query string (if any), protocol, host, etc. of the outgoing request.\n * @param request Contains the {@type RequestOptions} object used to make the outgoing request.\n */\n ignoreOutgoingRequests?: (url: string, request: http.RequestOptions) => boolean;\n\n /**\n * Do not capture the request body for incoming HTTP requests to URLs where the given callback returns `true`.\n * This can be useful for long running requests where the body is not needed and we want to avoid capturing it.\n *\n * @param url Contains the entire URL, including query string (if any), protocol, host, etc. of the outgoing request.\n * @param request Contains the {@type RequestOptions} object used to make the outgoing request.\n */\n ignoreIncomingRequestBody?: (url: string, request: http.RequestOptions) => boolean;\n\n /**\n * Controls the maximum size of incoming HTTP request bodies attached to events.\n *\n * Available options:\n * - 'none': No request bodies will be attached\n * - 'small': Request bodies up to 1,000 bytes will be attached\n * - 'medium': Request bodies up to 10,000 bytes will be attached (default)\n * - 'always': Request bodies will always be attached\n *\n * Note that even with 'always' setting, bodies exceeding 1MB will never be attached\n * for performance and security reasons.\n *\n * @default 'medium'\n */\n maxIncomingRequestBodySize?: 'none' | 'small' | 'medium' | 'always';\n\n /**\n * Whether the integration should create [Sessions](https://docs.sentry.io/product/releases/health/#sessions) for incoming requests to track the health and crash-free rate of your releases in Sentry.\n * Read more about Release Health: https://docs.sentry.io/product/releases/health/\n *\n * Defaults to `true`.\n */\n trackIncomingRequestsAsSessions?: boolean;\n\n /**\n * Number of milliseconds until sessions tracked with `trackIncomingRequestsAsSessions` will be flushed as a session aggregate.\n *\n * Defaults to `60000` (60s).\n */\n sessionFlushingDelayMS?: number;\n};\n\n// We only want to capture request bodies up to 1mb.\nconst MAX_BODY_BYTE_LENGTH = 1024 * 1024;\n\n/**\n * This custom HTTP instrumentation is used to isolate incoming requests and annotate them with additional information.\n * It does not emit any spans.\n *\n * The reason this is isolated from the OpenTelemetry instrumentation is that users may overwrite this,\n * which would lead to Sentry not working as expected.\n *\n * Important note: Contrary to other OTEL instrumentation, this one cannot be unwrapped.\n * It only does minimal things though and does not emit any spans.\n *\n * This is heavily inspired & adapted from:\n * https://github.com/open-telemetry/opentelemetry-js/blob/f8ab5592ddea5cba0a3b33bf8d74f27872c0367f/experimental/packages/opentelemetry-instrumentation-http/src/http.ts\n */\nexport class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpInstrumentationOptions> {\n private _propagationDecisionMap: LRUMap<string, boolean>;\n private _ignoreOutgoingRequestsMap: WeakMap<http.ClientRequest, boolean>;\n\n public constructor(config: SentryHttpInstrumentationOptions = {}) {\n super(INSTRUMENTATION_NAME, VERSION, config);\n\n this._propagationDecisionMap = new LRUMap<string, boolean>(100);\n this._ignoreOutgoingRequestsMap = new WeakMap<http.ClientRequest, boolean>();\n }\n\n /** @inheritdoc */\n public init(): [InstrumentationNodeModuleDefinition, InstrumentationNodeModuleDefinition] {\n // We register handlers when either http or https is instrumented\n // but we only want to register them once, whichever is loaded first\n let hasRegisteredHandlers = false;\n\n const onHttpServerRequestStart = ((_data: unknown) => {\n const data = _data as { server: http.Server };\n this._patchServerEmitOnce(data.server);\n }) satisfies ChannelListener;\n\n const onHttpClientResponseFinish = ((_data: unknown) => {\n const data = _data as { request: http.ClientRequest; response: http.IncomingMessage };\n this._onOutgoingRequestFinish(data.request, data.response);\n }) satisfies ChannelListener;\n\n const onHttpClientRequestError = ((_data: unknown) => {\n const data = _data as { request: http.ClientRequest };\n this._onOutgoingRequestFinish(data.request, undefined);\n }) satisfies ChannelListener;\n\n const onHttpClientRequestCreated = ((_data: unknown) => {\n const data = _data as { request: http.ClientRequest };\n this._onOutgoingRequestCreated(data.request);\n }) satisfies ChannelListener;\n\n const wrap = <T extends Http | Https>(moduleExports: T): T => {\n if (hasRegisteredHandlers) {\n return moduleExports;\n }\n\n hasRegisteredHandlers = true;\n\n subscribe('http.server.request.start', onHttpServerRequestStart);\n subscribe('http.client.response.finish', onHttpClientResponseFinish);\n\n // When an error happens, we still want to have a breadcrumb\n // In this case, `http.client.response.finish` is not triggered\n subscribe('http.client.request.error', onHttpClientRequestError);\n\n // NOTE: This channel only exist since Node 22\n // Before that, outgoing requests are not patched\n // and trace headers are not propagated, sadly.\n if (this.getConfig().propagateTraceInOutgoingRequests) {\n subscribe('http.client.request.created', onHttpClientRequestCreated);\n }\n\n return moduleExports;\n };\n\n const unwrap = (): void => {\n unsubscribe('http.server.request.start', onHttpServerRequestStart);\n unsubscribe('http.client.response.finish', onHttpClientResponseFinish);\n unsubscribe('http.client.request.error', onHttpClientRequestError);\n unsubscribe('http.client.request.created', onHttpClientRequestCreated);\n };\n\n /**\n * You may be wondering why we register these diagnostics-channel listeners\n * in such a convoluted way (as InstrumentationNodeModuleDefinition...)˝,\n * instead of simply subscribing to the events once in here.\n * The reason for this is timing semantics: These functions are called once the http or https module is loaded.\n * If we'd subscribe before that, there seem to be conflicts with the OTEL native instrumentation in some scenarios,\n * especially the \"import-on-top\" pattern of setting up ESM applications.\n */\n return [\n new InstrumentationNodeModuleDefinition('http', ['*'], wrap, unwrap),\n new InstrumentationNodeModuleDefinition('https', ['*'], wrap, unwrap),\n ];\n }\n\n /**\n * This is triggered when an outgoing request finishes.\n * It has access to the final request and response objects.\n */\n private _onOutgoingRequestFinish(request: http.ClientRequest, response?: http.IncomingMessage): void {\n DEBUG_BUILD && logger.log(INSTRUMENTATION_NAME, 'Handling finished outgoing request');\n\n const _breadcrumbs = this.getConfig().breadcrumbs;\n const breadCrumbsEnabled = typeof _breadcrumbs === 'undefined' ? true : _breadcrumbs;\n\n // Note: We cannot rely on the map being set by `_onOutgoingRequestCreated`, because that is not run in Node <22\n const shouldIgnore = this._ignoreOutgoingRequestsMap.get(request) ?? this._shouldIgnoreOutgoingRequest(request);\n this._ignoreOutgoingRequestsMap.set(request, shouldIgnore);\n\n if (breadCrumbsEnabled && !shouldIgnore) {\n addRequestBreadcrumb(request, response);\n }\n }\n\n /**\n * This is triggered when an outgoing request is created.\n * It has access to the request object, and can mutate it before the request is sent.\n */\n private _onOutgoingRequestCreated(request: http.ClientRequest): void {\n const shouldIgnore = this._ignoreOutgoingRequestsMap.get(request) ?? this._shouldIgnoreOutgoingRequest(request);\n this._ignoreOutgoingRequestsMap.set(request, shouldIgnore);\n\n if (shouldIgnore) {\n return;\n }\n\n // Add trace propagation headers\n const url = getRequestUrl(request);\n\n // Manually add the trace headers, if it applies\n // Note: We do not use `propagation.inject()` here, because our propagator relies on an active span\n // Which we do not have in this case\n const tracePropagationTargets = getClient()?.getOptions().tracePropagationTargets;\n const addedHeaders = shouldPropagateTraceForUrl(url, tracePropagationTargets, this._propagationDecisionMap)\n ? getTraceData()\n : undefined;\n\n if (!addedHeaders) {\n return;\n }\n\n const { 'sentry-trace': sentryTrace, baggage } = addedHeaders;\n\n // We do not want to overwrite existing header here, if it was already set\n if (sentryTrace && !request.getHeader('sentry-trace')) {\n request.setHeader('sentry-trace', sentryTrace);\n logger.log(INSTRUMENTATION_NAME, 'Added sentry-trace header to outgoing request');\n }\n\n if (baggage) {\n // For baggage, we make sure to merge this into a possibly existing header\n const newBaggage = mergeBaggageHeaders(request.getHeader('baggage'), baggage);\n if (newBaggage) {\n request.setHeader('baggage', newBaggage);\n }\n }\n }\n\n /**\n * Patch a server.emit function to handle process isolation for incoming requests.\n * This will only patch the emit function if it was not already patched.\n */\n private _patchServerEmitOnce(server: http.Server): void {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalEmit = server.emit;\n\n // This means it was already patched, do nothing\n if ((originalEmit as { __sentry_patched__?: boolean }).__sentry_patched__) {\n return;\n }\n\n DEBUG_BUILD && logger.log(INSTRUMENTATION_NAME, 'Patching server.emit');\n\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const instrumentation = this;\n const { ignoreIncomingRequestBody, maxIncomingRequestBodySize = 'medium' } = instrumentation.getConfig();\n\n const newEmit = new Proxy(originalEmit, {\n apply(target, thisArg, args: [event: string, ...args: unknown[]]) {\n // Only traces request events\n if (args[0] !== 'request') {\n return target.apply(thisArg, args);\n }\n\n DEBUG_BUILD && logger.log(INSTRUMENTATION_NAME, 'Handling incoming request');\n\n const isolationScope = getIsolationScope().clone();\n const request = args[1] as http.IncomingMessage;\n const response = args[2] as http.OutgoingMessage;\n\n const normalizedRequest = httpRequestToRequestData(request);\n\n // request.ip is non-standard but some frameworks set this\n const ipAddress = (request as { ip?: string }).ip || request.socket?.remoteAddress;\n\n const url = request.url || '/';\n if (!ignoreIncomingRequestBody?.(url, request) && maxIncomingRequestBodySize !== 'none') {\n patchRequestToCaptureBody(request, isolationScope, maxIncomingRequestBodySize);\n }\n\n // Update the isolation scope, isolate this request\n isolationScope.setSDKProcessingMetadata({ normalizedRequest, ipAddress });\n\n // attempt to update the scope's `transactionName` based on the request URL\n // Ideally, framework instrumentations coming after the HttpInstrumentation\n // update the transactionName once we get a parameterized route.\n const httpMethod = (request.method || 'GET').toUpperCase();\n const httpTarget = stripUrlQueryAndFragment(url);\n\n const bestEffortTransactionName = `${httpMethod} ${httpTarget}`;\n\n isolationScope.setTransactionName(bestEffortTransactionName);\n\n if (instrumentation.getConfig().trackIncomingRequestsAsSessions !== false) {\n recordRequestSession({\n requestIsolationScope: isolationScope,\n response,\n sessionFlushingDelayMS: instrumentation.getConfig().sessionFlushingDelayMS ?? 60_000,\n });\n }\n\n return withIsolationScope(isolationScope, () => {\n // Set a new propagationSpanId for this request\n // We rely on the fact that `withIsolationScope()` will implicitly also fork the current scope\n // This way we can save an \"unnecessary\" `withScope()` invocation\n getCurrentScope().getPropagationContext().propagationSpanId = generateSpanId();\n\n // If we don't want to extract the trace from the header, we can skip this\n if (!instrumentation.getConfig().extractIncomingTraceFromHeader) {\n return target.apply(thisArg, args);\n }\n\n const ctx = propagation.extract(context.active(), normalizedRequest.headers);\n return context.with(ctx, () => {\n return target.apply(thisArg, args);\n });\n });\n },\n });\n\n addNonEnumerableProperty(newEmit, '__sentry_patched__', true);\n\n server.emit = newEmit;\n }\n\n /**\n * Check if the given outgoing request should be ignored.\n */\n private _shouldIgnoreOutgoingRequest(request: http.ClientRequest): boolean {\n if (isTracingSuppressed(context.active())) {\n return true;\n }\n\n const ignoreOutgoingRequests = this.getConfig().ignoreOutgoingRequests;\n\n if (!ignoreOutgoingRequests) {\n return false;\n }\n\n const options = getRequestOptions(request);\n const url = getRequestUrl(request);\n return ignoreOutgoingRequests(url, options);\n }\n}\n\n/** Add a breadcrumb for outgoing requests. */\nfunction addRequestBreadcrumb(request: http.ClientRequest, response: http.IncomingMessage | undefined): void {\n const data = getBreadcrumbData(request);\n\n const statusCode = response?.statusCode;\n const level = getBreadcrumbLogLevelFromHttpStatusCode(statusCode);\n\n addBreadcrumb(\n {\n category: 'http',\n data: {\n status_code: statusCode,\n ...data,\n },\n type: 'http',\n level,\n },\n {\n event: 'response',\n request,\n response,\n },\n );\n}\n\nfunction getBreadcrumbData(request: http.ClientRequest): Partial<SanitizedRequestData> {\n try {\n // `request.host` does not contain the port, but the host header does\n const host = request.getHeader('host') || request.host;\n const url = new URL(request.path, `${request.protocol}//${host}`);\n const parsedUrl = parseUrl(url.toString());\n\n const data: Partial<SanitizedRequestData> = {\n url: getSanitizedUrlString(parsedUrl),\n 'http.method': request.method || 'GET',\n };\n\n if (parsedUrl.search) {\n data['http.query'] = parsedUrl.search;\n }\n if (parsedUrl.hash) {\n data['http.fragment'] = parsedUrl.hash;\n }\n\n return data;\n } catch {\n return {};\n }\n}\n\n/**\n * This method patches the request object to capture the body.\n * Instead of actually consuming the streamed body ourselves, which has potential side effects,\n * we monkey patch `req.on('data')` to intercept the body chunks.\n * This way, we only read the body if the user also consumes the body, ensuring we do not change any behavior in unexpected ways.\n */\nfunction patchRequestToCaptureBody(\n req: http.IncomingMessage,\n isolationScope: Scope,\n maxIncomingRequestBodySize: 'small' | 'medium' | 'always',\n): void {\n let bodyByteLength = 0;\n const chunks: Buffer[] = [];\n\n DEBUG_BUILD && logger.log(INSTRUMENTATION_NAME, 'Patching request.on');\n\n /**\n * We need to keep track of the original callbacks, in order to be able to remove listeners again.\n * Since `off` depends on having the exact same function reference passed in, we need to be able to map\n * original listeners to our wrapped ones.\n */\n const callbackMap = new WeakMap();\n\n const maxBodySize =\n maxIncomingRequestBodySize === 'small'\n ? 1_000\n : maxIncomingRequestBodySize === 'medium'\n ? 10_000\n : MAX_BODY_BYTE_LENGTH;\n\n try {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n req.on = new Proxy(req.on, {\n apply: (target, thisArg, args: Parameters<typeof req.on>) => {\n const [event, listener, ...restArgs] = args;\n\n if (event === 'data') {\n DEBUG_BUILD &&\n logger.log(INSTRUMENTATION_NAME, `Handling request.on(\"data\") with maximum body size of ${maxBodySize}b`);\n\n const callback = new Proxy(listener, {\n apply: (target, thisArg, args: Parameters<typeof listener>) => {\n try {\n const chunk = args[0] as Buffer | string;\n const bufferifiedChunk = Buffer.from(chunk);\n\n if (bodyByteLength < maxBodySize) {\n chunks.push(bufferifiedChunk);\n bodyByteLength += bufferifiedChunk.byteLength;\n } else if (DEBUG_BUILD) {\n logger.log(\n INSTRUMENTATION_NAME,\n `Dropping request body chunk because maximum body length of ${maxBodySize}b is exceeded.`,\n );\n }\n } catch (err) {\n DEBUG_BUILD && logger.error(INSTRUMENTATION_NAME, 'Encountered error while storing body chunk.');\n }\n\n return Reflect.apply(target, thisArg, args);\n },\n });\n\n callbackMap.set(listener, callback);\n\n return Reflect.apply(target, thisArg, [event, callback, ...restArgs]);\n }\n\n return Reflect.apply(target, thisArg, args);\n },\n });\n\n // Ensure we also remove callbacks correctly\n // eslint-disable-next-line @typescript-eslint/unbound-method\n req.off = new Proxy(req.off, {\n apply: (target, thisArg, args: Parameters<typeof req.off>) => {\n const [, listener] = args;\n\n const callback = callbackMap.get(listener);\n if (callback) {\n callbackMap.delete(listener);\n\n const modifiedArgs = args.slice();\n modifiedArgs[1] = callback;\n return Reflect.apply(target, thisArg, modifiedArgs);\n }\n\n return Reflect.apply(target, thisArg, args);\n },\n });\n\n req.on('end', () => {\n try {\n const body = Buffer.concat(chunks).toString('utf-8');\n if (body) {\n // Using Buffer.byteLength here, because the body may contain characters that are not 1 byte long\n const bodyByteLength = Buffer.byteLength(body, 'utf-8');\n const truncatedBody =\n bodyByteLength > maxBodySize\n ? `${Buffer.from(body)\n .subarray(0, maxBodySize - 3)\n .toString('utf-8')}...`\n : body;\n\n isolationScope.setSDKProcessingMetadata({ normalizedRequest: { data: truncatedBody } });\n }\n } catch (error) {\n if (DEBUG_BUILD) {\n logger.error(INSTRUMENTATION_NAME, 'Error building captured request body', error);\n }\n }\n });\n } catch (error) {\n if (DEBUG_BUILD) {\n logger.error(INSTRUMENTATION_NAME, 'Error patching request to capture body', error);\n }\n }\n}\n\nfunction getRequestOptions(request: http.ClientRequest): http.RequestOptions {\n return {\n method: request.method,\n protocol: request.protocol,\n host: request.host,\n hostname: request.host,\n path: request.path,\n headers: request.getHeaders(),\n };\n}\n\n/**\n * Starts a session and tracks it in the context of a given isolation scope.\n * When the passed response is finished, the session is put into a task and is\n * aggregated with other sessions that may happen in a certain time window\n * (sessionFlushingDelayMs).\n *\n * The sessions are always aggregated by the client that is on the current scope\n * at the time of ending the response (if there is one).\n */\n// Exported for unit tests\nexport function recordRequestSession({\n requestIsolationScope,\n response,\n sessionFlushingDelayMS,\n}: {\n requestIsolationScope: Scope;\n response: EventEmitter;\n sessionFlushingDelayMS?: number;\n}): void {\n requestIsolationScope.setSDKProcessingMetadata({\n requestSession: { status: 'ok' },\n });\n response.once('close', () => {\n // We need to grab the client off the current scope instead of the isolation scope because the isolation scope doesn't hold any client out of the box.\n const client = getClient();\n const requestSession = requestIsolationScope.getScopeData().sdkProcessingMetadata.requestSession;\n\n if (client && requestSession) {\n DEBUG_BUILD && logger.debug(`Recorded request session with status: ${requestSession.status}`);\n\n const roundedDate = new Date();\n roundedDate.setSeconds(0, 0);\n const dateBucketKey = roundedDate.toISOString();\n\n const existingClientAggregate = clientToRequestSessionAggregatesMap.get(client);\n const bucket = existingClientAggregate?.[dateBucketKey] || { exited: 0, crashed: 0, errored: 0 };\n bucket[({ ok: 'exited', crashed: 'crashed', errored: 'errored' } as const)[requestSession.status]]++;\n\n if (existingClientAggregate) {\n existingClientAggregate[dateBucketKey] = bucket;\n } else {\n DEBUG_BUILD && logger.debug('Opened new request session aggregate.');\n const newClientAggregate = { [dateBucketKey]: bucket };\n clientToRequestSessionAggregatesMap.set(client, newClientAggregate);\n\n const flushPendingClientAggregates = (): void => {\n clearTimeout(timeout);\n unregisterClientFlushHook();\n clientToRequestSessionAggregatesMap.delete(client);\n\n const aggregatePayload: AggregationCounts[] = Object.entries(newClientAggregate).map(\n ([timestamp, value]) => ({\n started: timestamp,\n exited: value.exited,\n errored: value.errored,\n crashed: value.crashed,\n }),\n );\n client.sendSession({ aggregates: aggregatePayload });\n };\n\n const unregisterClientFlushHook = client.on('flush', () => {\n DEBUG_BUILD && logger.debug('Sending request session aggregate due to client flush');\n flushPendingClientAggregates();\n });\n const timeout = setTimeout(() => {\n DEBUG_BUILD && logger.debug('Sending request session aggregate due to flushing schedule');\n flushPendingClientAggregates();\n }, sessionFlushingDelayMS).unref();\n }\n }\n });\n}\n\nconst clientToRequestSessionAggregatesMap = new Map<\n Client,\n { [timestampRoundedToSeconds: string]: { exited: number; crashed: number; errored: number } }\n>();\n"],"names":[],"mappings":";;;;;;;;;;AAiCA,MAAM,oBAAA,GAAuB,8BAA8B;;AAmF3D;AACA,MAAM,oBAAqB,GAAE,IAAK,GAAE,IAAI;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,yBAAA,SAAkC,mBAAmB,CAAmC;;AAIrG,GAAS,WAAW,CAAC,MAAM,GAAqC,EAAE,EAAE;AACpE,IAAI,KAAK,CAAC,oBAAoB,EAAE,OAAO,EAAE,MAAM,CAAC;;AAEhD,IAAI,IAAI,CAAC,uBAAwB,GAAE,IAAI,MAAM,CAAkB,GAAG,CAAC;AACnE,IAAI,IAAI,CAAC,0BAAA,GAA6B,IAAI,OAAO,EAA+B;AAChF;;AAEA;AACA,GAAS,IAAI,GAA+E;AAC5F;AACA;AACA,IAAI,IAAI,qBAAsB,GAAE,KAAK;;AAErC,IAAI,MAAM,wBAAyB,IAAG,CAAC,KAAK,KAAc;AAC1D,MAAM,MAAM,IAAK,GAAE,KAAM;AACzB,MAAM,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC;AAC5C,KAAK,CAAE;;AAEP,IAAI,MAAM,0BAA2B,IAAG,CAAC,KAAK,KAAc;AAC5D,MAAM,MAAM,IAAK,GAAE,KAAM;AACzB,MAAM,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC;AAChE,KAAK,CAAE;;AAEP,IAAI,MAAM,wBAAyB,IAAG,CAAC,KAAK,KAAc;AAC1D,MAAM,MAAM,IAAK,GAAE,KAAM;AACzB,MAAM,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC;AAC5D,KAAK,CAAE;;AAEP,IAAI,MAAM,0BAA2B,IAAG,CAAC,KAAK,KAAc;AAC5D,M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4
|
import { LOCAL_VARIABLES_KEY, functionNamesMatch } from './common.js';
|
|
5
5
|
|
|
6
6
|
// This string is a placeholder that gets overwritten with the worker code.
|
|
7
|
-
const base64WorkerScript = '
|
|
7
|
+
const base64WorkerScript = 'LyohIEBzZW50cnkvbm9kZSA5LjIyLjAgKGNjYWJmYzIpIHwgaHR0cHM6Ly9naXRodWIuY29tL2dldHNlbnRyeS9zZW50cnktamF2YXNjcmlwdCAqLwppbXBvcnR7U2Vzc2lvbiBhcyBlfWZyb20ibm9kZTppbnNwZWN0b3IvcHJvbWlzZXMiO2ltcG9ydHt3b3JrZXJEYXRhIGFzIHR9ZnJvbSJub2RlOndvcmtlcl90aHJlYWRzIjtjb25zdCBuPSJ1bmRlZmluZWQiPT10eXBlb2YgX19TRU5UUllfREVCVUdfX3x8X19TRU5UUllfREVCVUdfXyxvPSI5LjIyLjAiLGk9Z2xvYmFsVGhpcztjb25zdCBhPVsiZGVidWciLCJpbmZvIiwid2FybiIsImVycm9yIiwibG9nIiwiYXNzZXJ0IiwidHJhY2UiXSxzPXt9O2Z1bmN0aW9uIGMoZSl7aWYoISgiY29uc29sZSJpbiBpKSlyZXR1cm4gZSgpO2NvbnN0IHQ9aS5jb25zb2xlLG49e30sbz1PYmplY3Qua2V5cyhzKTtvLmZvckVhY2goKGU9Pntjb25zdCBvPXNbZV07bltlXT10W2VdLHRbZV09b30pKTt0cnl7cmV0dXJuIGUoKX1maW5hbGx5e28uZm9yRWFjaCgoZT0+e3RbZV09bltlXX0pKX19IWZ1bmN0aW9uKGUsdCxuPWkpe2NvbnN0IGE9bi5fX1NFTlRSWV9fPW4uX19TRU5UUllfX3x8e30scz1hW29dPWFbb118fHt9O3NbZV18fChzW2VdPXQoKSl9KCJsb2dnZXIiLChmdW5jdGlvbigpe2xldCBlPSExO2NvbnN0IHQ9e2VuYWJsZTooKT0+e2U9ITB9LGRpc2FibGU6KCk9PntlPSExfSxpc0VuYWJsZWQ6KCk9PmV9O3JldHVybiBuP2Eu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0pLG8pe2NvbnN0IGU9dS5tYXhFeGNlcHRpb25zUGVyU2Vjb25kfHw1MDtwPWZ1bmN0aW9uKGUsdCxuKXtsZXQgbz0wLGk9NSxhPTA7cmV0dXJuIHNldEludGVydmFsKCgoKT0+ezA9PT1hP28+ZSYmKGkqPTIsbihpKSxpPjg2NDAwJiYoaT04NjQwMCksYT1pKTooYS09MSwwPT09YSYmdCgpKSxvPTB9KSwxZTMpLnVucmVmKCksKCk9PntvKz0xfX0oZSwoYXN5bmMoKT0+e2woIlJhdGUtbGltaXQgbGlmdGVkLiIpLGF3YWl0IHQucG9zdCgiRGVidWdnZXIuc2V0UGF1c2VPbkV4Y2VwdGlvbnMiLHtzdGF0ZToiYWxsIn0pfSksKGFzeW5jIGU9PntsKGBSYXRlLWxpbWl0IGV4Y2VlZGVkLiBEaXNhYmxpbmcgY2FwdHVyaW5nIG9mIGNhdWdodCBleGNlcHRpb25zIGZvciAke2V9IHNlY29uZHMuYCksYXdhaXQgdC5wb3N0KCJEZWJ1Z2dlci5zZXRQYXVzZU9uRXhjZXB0aW9ucyIse3N0YXRlOiJ1bmNhdWdodCJ9KX0pKX19KSgpLmNhdGNoKChlPT57bCgiRmFpbGVkIHRvIHN0YXJ0IGRlYnVnZ2VyIixlKX0pKSxzZXRJbnRlcnZhbCgoKCk9Pnt9KSwxZTQpOw==';
|
|
8
8
|
|
|
9
9
|
function log(...args) {
|
|
10
10
|
logger.log('[LocalVariables]', ...args);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! @sentry/node 9.
|
|
2
|
-
import{Session as e}from"node:inspector/promises";import{workerData as t}from"node:worker_threads";const n="undefined"==typeof __SENTRY_DEBUG__||__SENTRY_DEBUG__,o="9.
|
|
1
|
+
/*! @sentry/node 9.22.0 (ccabfc2) | https://github.com/getsentry/sentry-javascript */
|
|
2
|
+
import{Session as e}from"node:inspector/promises";import{workerData as t}from"node:worker_threads";const n="undefined"==typeof __SENTRY_DEBUG__||__SENTRY_DEBUG__,o="9.22.0",i=globalThis;const a=["debug","info","warn","error","log","assert","trace"],s={};function c(e){if(!("console"in i))return e();const t=i.console,n={},o=Object.keys(s);o.forEach((e=>{const o=s[e];n[e]=t[e],t[e]=o}));try{return e()}finally{o.forEach((e=>{t[e]=n[e]}))}}!function(e,t,n=i){const a=n.__SENTRY__=n.__SENTRY__||{},s=a[o]=a[o]||{};s[e]||(s[e]=t())}("logger",(function(){let e=!1;const t={enable:()=>{e=!0},disable:()=>{e=!1},isEnabled:()=>e};return n?a.forEach((n=>{t[n]=(...t)=>{e&&c((()=>{i.console[n](`Sentry Logger [${n}]:`,...t)}))}})):a.forEach((e=>{t[e]=()=>{}})),t}));const r="__SENTRY_ERROR_LOCAL_VARIABLES__";const u=t;function l(...e){u.debug&&c((()=>console.log("[LocalVariables Worker]",...e)))}async function f(e,t,n,o){const i=await e.post("Runtime.getProperties",{objectId:t,ownProperties:!0});o[n]=i.result.filter((e=>"length"!==e.name&&!isNaN(parseInt(e.name,10)))).sort(((e,t)=>parseInt(e.name,10)-parseInt(t.name,10))).map((e=>e.value?.value))}async function g(e,t,n,o){const i=await e.post("Runtime.getProperties",{objectId:t,ownProperties:!0});o[n]=i.result.map((e=>[e.name,e.value?.value])).reduce(((e,[t,n])=>(e[t]=n,e)),{})}function d(e,t){e.value&&("value"in e.value?void 0===e.value.value||null===e.value.value?t[e.name]=`<${e.value.value}>`:t[e.name]=e.value.value:"description"in e.value&&"function"!==e.value.type?t[e.name]=`<${e.value.description}>`:"undefined"===e.value.type&&(t[e.name]="<undefined>"))}async function b(e,t){const n=await e.post("Runtime.getProperties",{objectId:t,ownProperties:!0}),o={};for(const t of n.result)if(t.value?.objectId&&"Array"===t.value.className){const n=t.value.objectId;await f(e,n,t.name,o)}else if(t.value?.objectId&&"Object"===t.value.className){const n=t.value.objectId;await g(e,n,t.name,o)}else t.value&&d(t,o);return o}let p;(async function(){const t=new e;t.connectToMainThread(),l("Connected to main thread");let n=!1;t.on("Debugger.resumed",(()=>{n=!1})),t.on("Debugger.paused",(e=>{n=!0,async function(e,{reason:t,data:{objectId:n},callFrames:o}){if("exception"!==t&&"promiseRejection"!==t)return;if(p?.(),null==n)return;const i=[];for(let t=0;t<o.length;t++){const{scopeChain:n,functionName:a,this:s}=o[t],c=n.find((e=>"local"===e.type)),r="global"!==s.className&&s.className?`${s.className}.${a}`:a;if(void 0===c?.object.objectId)i[t]={function:r};else{const n=await b(e,c.object.objectId);i[t]={function:r,vars:n}}}await e.post("Runtime.callFunctionOn",{functionDeclaration:`function() { this.${r} = this.${r} || ${JSON.stringify(i)}; }`,silent:!0,objectId:n}),await e.post("Runtime.releaseObject",{objectId:n})}(t,e.params).then((async()=>{n&&await t.post("Debugger.resume")}),(async e=>{n&&await t.post("Debugger.resume")}))})),await t.post("Debugger.enable");const o=!1!==u.captureAllExceptions;if(await t.post("Debugger.setPauseOnExceptions",{state:o?"all":"uncaught"}),o){const e=u.maxExceptionsPerSecond||50;p=function(e,t,n){let o=0,i=5,a=0;return setInterval((()=>{0===a?o>e&&(i*=2,n(i),i>86400&&(i=86400),a=i):(a-=1,0===a&&t()),o=0}),1e3).unref(),()=>{o+=1}}(e,(async()=>{l("Rate-limit lifted."),await t.post("Debugger.setPauseOnExceptions",{state:"all"})}),(async e=>{l(`Rate-limit exceeded. Disabling capturing of caught exceptions for ${e} seconds.`),await t.post("Debugger.setPauseOnExceptions",{state:"uncaught"})}))}})().catch((e=>{l("Failed to start debugger",e)})),setInterval((()=>{}),1e4);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { context } from '@opentelemetry/api';
|
|
2
|
+
import { VERSION, isTracingSuppressed } from '@opentelemetry/core';
|
|
2
3
|
import { InstrumentationBase } from '@opentelemetry/instrumentation';
|
|
3
4
|
import { LRUMap, getClient, getTraceData, getBreadcrumbLogLevelFromHttpStatusCode, addBreadcrumb, parseUrl, getSanitizedUrlString } from '@sentry/core';
|
|
4
5
|
import { shouldPropagateTraceForUrl } from '@sentry/opentelemetry';
|
|
@@ -30,6 +31,7 @@ class SentryNodeFetchInstrumentation extends InstrumentationBase {
|
|
|
30
31
|
super('@sentry/instrumentation-node-fetch', VERSION, config);
|
|
31
32
|
this._channelSubs = [];
|
|
32
33
|
this._propagationDecisionMap = new LRUMap(100);
|
|
34
|
+
this._ignoreOutgoingRequestsMap = new WeakMap();
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
/** No need to instrument files/modules. */
|
|
@@ -82,15 +84,17 @@ class SentryNodeFetchInstrumentation extends InstrumentationBase {
|
|
|
82
84
|
return;
|
|
83
85
|
}
|
|
84
86
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
const shouldIgnore = this._shouldIgnoreOutgoingRequest(request);
|
|
88
|
+
// We store this decisision for later so we do not need to re-evaluate it
|
|
89
|
+
// Additionally, the active context is not correct in _onResponseHeaders, so we need to make sure it is evaluated here
|
|
90
|
+
this._ignoreOutgoingRequestsMap.set(request, shouldIgnore);
|
|
89
91
|
|
|
90
92
|
if (shouldIgnore) {
|
|
91
93
|
return;
|
|
92
94
|
}
|
|
93
95
|
|
|
96
|
+
const url = getAbsoluteUrl(request.origin, request.path);
|
|
97
|
+
|
|
94
98
|
// Manually add the trace headers, if it applies
|
|
95
99
|
// Note: We do not use `propagation.inject()` here, because our propagator relies on an active span
|
|
96
100
|
// Which we do not have in this case
|
|
@@ -161,13 +165,9 @@ class SentryNodeFetchInstrumentation extends InstrumentationBase {
|
|
|
161
165
|
const _breadcrumbs = config.breadcrumbs;
|
|
162
166
|
const breadCrumbsEnabled = typeof _breadcrumbs === 'undefined' ? true : _breadcrumbs;
|
|
163
167
|
|
|
164
|
-
const
|
|
165
|
-
const shouldCreateBreadcrumb =
|
|
166
|
-
typeof _ignoreOutgoingRequests === 'function'
|
|
167
|
-
? !_ignoreOutgoingRequests(getAbsoluteUrl(request.origin, request.path))
|
|
168
|
-
: true;
|
|
168
|
+
const shouldIgnore = this._ignoreOutgoingRequestsMap.get(request);
|
|
169
169
|
|
|
170
|
-
if (breadCrumbsEnabled &&
|
|
170
|
+
if (breadCrumbsEnabled && !shouldIgnore) {
|
|
171
171
|
addRequestBreadcrumb(request, response);
|
|
172
172
|
}
|
|
173
173
|
}
|
|
@@ -196,6 +196,25 @@ class SentryNodeFetchInstrumentation extends InstrumentationBase {
|
|
|
196
196
|
unsubscribe,
|
|
197
197
|
});
|
|
198
198
|
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Check if the given outgoing request should be ignored.
|
|
202
|
+
*/
|
|
203
|
+
_shouldIgnoreOutgoingRequest(request) {
|
|
204
|
+
if (isTracingSuppressed(context.active())) {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Add trace propagation headers
|
|
209
|
+
const url = getAbsoluteUrl(request.origin, request.path);
|
|
210
|
+
const ignoreOutgoingRequests = this.getConfig().ignoreOutgoingRequests;
|
|
211
|
+
|
|
212
|
+
if (typeof ignoreOutgoingRequests !== 'function' || !url) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return ignoreOutgoingRequests(url);
|
|
217
|
+
}
|
|
199
218
|
}
|
|
200
219
|
|
|
201
220
|
/** Add a breadcrumb for outgoing requests. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SentryNodeFetchInstrumentation.js","sources":["../../../../src/integrations/node-fetch/SentryNodeFetchInstrumentation.ts"],"sourcesContent":["import { VERSION } from '@opentelemetry/core';\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport { InstrumentationBase } from '@opentelemetry/instrumentation';\nimport type { SanitizedRequestData } from '@sentry/core';\nimport {\n addBreadcrumb,\n getBreadcrumbLogLevelFromHttpStatusCode,\n getClient,\n getSanitizedUrlString,\n getTraceData,\n LRUMap,\n parseUrl,\n} from '@sentry/core';\nimport { shouldPropagateTraceForUrl } from '@sentry/opentelemetry';\nimport * as diagch from 'diagnostics_channel';\nimport { NODE_MAJOR, NODE_MINOR } from '../../nodeVersion';\nimport { mergeBaggageHeaders } from '../../utils/baggage';\nimport type { UndiciRequest, UndiciResponse } from './types';\n\nconst SENTRY_TRACE_HEADER = 'sentry-trace';\nconst SENTRY_BAGGAGE_HEADER = 'baggage';\n\n// For baggage, we make sure to merge this into a possibly existing header\nconst BAGGAGE_HEADER_REGEX = /baggage: (.*)\\r\\n/;\n\nexport type SentryNodeFetchInstrumentationOptions = InstrumentationConfig & {\n /**\n * Whether breadcrumbs should be recorded for requests.\n *\n * @default `true`\n */\n breadcrumbs?: boolean;\n\n /**\n * Do not capture breadcrumbs or inject headers for outgoing fetch requests to URLs where the given callback returns `true`.\n * The same option can be passed to the top-level httpIntegration where it controls both, breadcrumb and\n * span creation.\n *\n * @param url Contains the entire URL, including query string (if any), protocol, host, etc. of the outgoing request.\n */\n ignoreOutgoingRequests?: (url: string) => boolean;\n};\n\ninterface ListenerRecord {\n name: string;\n unsubscribe: () => void;\n}\n\n/**\n * This custom node-fetch instrumentation is used to instrument outgoing fetch requests.\n * It does not emit any spans.\n *\n * The reason this is isolated from the OpenTelemetry instrumentation is that users may overwrite this,\n * which would lead to Sentry not working as expected.\n *\n * This is heavily inspired & adapted from:\n * https://github.com/open-telemetry/opentelemetry-js-contrib/blob/28e209a9da36bc4e1f8c2b0db7360170ed46cb80/plugins/node/instrumentation-undici/src/undici.ts\n */\nexport class SentryNodeFetchInstrumentation extends InstrumentationBase<SentryNodeFetchInstrumentationOptions> {\n // Keep ref to avoid https://github.com/nodejs/node/issues/42170 bug and for\n // unsubscribing.\n private _channelSubs: Array<ListenerRecord>;\n private _propagationDecisionMap: LRUMap<string, boolean>;\n\n public constructor(config: SentryNodeFetchInstrumentationOptions = {}) {\n super('@sentry/instrumentation-node-fetch', VERSION, config);\n this._channelSubs = [];\n this._propagationDecisionMap = new LRUMap<string, boolean>(100);\n }\n\n /** No need to instrument files/modules. */\n public init(): void {\n return undefined;\n }\n\n /** Disable the instrumentation. */\n public disable(): void {\n super.disable();\n this._channelSubs.forEach(sub => sub.unsubscribe());\n this._channelSubs = [];\n }\n\n /** Enable the instrumentation. */\n public enable(): void {\n // \"enabled\" handling is currently a bit messy with InstrumentationBase.\n // If constructed with `{enabled: false}`, this `.enable()` is still called,\n // and `this.getConfig().enabled !== this.isEnabled()`, creating confusion.\n //\n // For now, this class will setup for instrumenting if `.enable()` is\n // called, but use `this.getConfig().enabled` to determine if\n // instrumentation should be generated. This covers the more likely common\n // case of config being given a construction time, rather than later via\n // `instance.enable()`, `.disable()`, or `.setConfig()` calls.\n super.enable();\n\n // This method is called by the super-class constructor before ours is\n // called. So we need to ensure the property is initalized.\n this._channelSubs = this._channelSubs || [];\n\n // Avoid to duplicate subscriptions\n if (this._channelSubs.length > 0) {\n return;\n }\n\n this._subscribeToChannel('undici:request:create', this._onRequestCreated.bind(this));\n this._subscribeToChannel('undici:request:headers', this._onResponseHeaders.bind(this));\n }\n\n /**\n * This method is called when a request is created.\n * You can still mutate the request here before it is sent.\n */\n private _onRequestCreated({ request }: { request: UndiciRequest }): void {\n const config = this.getConfig();\n const enabled = config.enabled !== false;\n\n if (!enabled) {\n return;\n }\n\n // Add trace propagation headers\n const url = getAbsoluteUrl(request.origin, request.path);\n const _ignoreOutgoingRequests = config.ignoreOutgoingRequests;\n const shouldIgnore = _ignoreOutgoingRequests && url && _ignoreOutgoingRequests(url);\n\n if (shouldIgnore) {\n return;\n }\n\n // Manually add the trace headers, if it applies\n // Note: We do not use `propagation.inject()` here, because our propagator relies on an active span\n // Which we do not have in this case\n // The propagator _may_ overwrite this, but this should be fine as it is the same data\n const tracePropagationTargets = getClient()?.getOptions().tracePropagationTargets;\n const addedHeaders = shouldPropagateTraceForUrl(url, tracePropagationTargets, this._propagationDecisionMap)\n ? getTraceData()\n : undefined;\n\n if (!addedHeaders) {\n return;\n }\n\n const { 'sentry-trace': sentryTrace, baggage } = addedHeaders;\n\n // We do not want to overwrite existing headers here\n // If the core UndiciInstrumentation is registered, it will already have set the headers\n // We do not want to add any then\n if (Array.isArray(request.headers)) {\n const requestHeaders = request.headers;\n\n // We do not want to overwrite existing header here, if it was already set\n if (sentryTrace && !requestHeaders.includes(SENTRY_TRACE_HEADER)) {\n requestHeaders.push(SENTRY_TRACE_HEADER, sentryTrace);\n }\n\n // For baggage, we make sure to merge this into a possibly existing header\n const existingBaggagePos = requestHeaders.findIndex(header => header === SENTRY_BAGGAGE_HEADER);\n if (baggage && existingBaggagePos === -1) {\n requestHeaders.push(SENTRY_BAGGAGE_HEADER, baggage);\n } else if (baggage) {\n const existingBaggage = requestHeaders[existingBaggagePos + 1];\n const merged = mergeBaggageHeaders(existingBaggage, baggage);\n if (merged) {\n requestHeaders[existingBaggagePos + 1] = merged;\n }\n }\n } else {\n const requestHeaders = request.headers;\n // We do not want to overwrite existing header here, if it was already set\n if (sentryTrace && !requestHeaders.includes(`${SENTRY_TRACE_HEADER}:`)) {\n request.headers += `${SENTRY_TRACE_HEADER}: ${sentryTrace}\\r\\n`;\n }\n\n const existingBaggage = request.headers.match(BAGGAGE_HEADER_REGEX)?.[1];\n if (baggage && !existingBaggage) {\n request.headers += `${SENTRY_BAGGAGE_HEADER}: ${baggage}\\r\\n`;\n } else if (baggage) {\n const merged = mergeBaggageHeaders(existingBaggage, baggage);\n if (merged) {\n request.headers = request.headers.replace(BAGGAGE_HEADER_REGEX, `baggage: ${merged}\\r\\n`);\n }\n }\n }\n }\n\n /**\n * This method is called when a response is received.\n */\n private _onResponseHeaders({ request, response }: { request: UndiciRequest; response: UndiciResponse }): void {\n const config = this.getConfig();\n const enabled = config.enabled !== false;\n\n if (!enabled) {\n return;\n }\n\n const _breadcrumbs = config.breadcrumbs;\n const breadCrumbsEnabled = typeof _breadcrumbs === 'undefined' ? true : _breadcrumbs;\n\n const _ignoreOutgoingRequests = config.ignoreOutgoingRequests;\n const shouldCreateBreadcrumb =\n typeof _ignoreOutgoingRequests === 'function'\n ? !_ignoreOutgoingRequests(getAbsoluteUrl(request.origin, request.path))\n : true;\n\n if (breadCrumbsEnabled && shouldCreateBreadcrumb) {\n addRequestBreadcrumb(request, response);\n }\n }\n\n /** Subscribe to a diagnostics channel. */\n private _subscribeToChannel(\n diagnosticChannel: string,\n onMessage: (message: unknown, name: string | symbol) => void,\n ): void {\n // `diagnostics_channel` had a ref counting bug until v18.19.0.\n // https://github.com/nodejs/node/pull/47520\n const useNewSubscribe = NODE_MAJOR > 18 || (NODE_MAJOR === 18 && NODE_MINOR >= 19);\n\n let unsubscribe: () => void;\n if (useNewSubscribe) {\n diagch.subscribe?.(diagnosticChannel, onMessage);\n unsubscribe = () => diagch.unsubscribe?.(diagnosticChannel, onMessage);\n } else {\n const channel = diagch.channel(diagnosticChannel);\n channel.subscribe(onMessage);\n unsubscribe = () => channel.unsubscribe(onMessage);\n }\n\n this._channelSubs.push({\n name: diagnosticChannel,\n unsubscribe,\n });\n }\n}\n\n/** Add a breadcrumb for outgoing requests. */\nfunction addRequestBreadcrumb(request: UndiciRequest, response: UndiciResponse): void {\n const data = getBreadcrumbData(request);\n\n const statusCode = response.statusCode;\n const level = getBreadcrumbLogLevelFromHttpStatusCode(statusCode);\n\n addBreadcrumb(\n {\n category: 'http',\n data: {\n status_code: statusCode,\n ...data,\n },\n type: 'http',\n level,\n },\n {\n event: 'response',\n request,\n response,\n },\n );\n}\n\nfunction getBreadcrumbData(request: UndiciRequest): Partial<SanitizedRequestData> {\n try {\n const url = getAbsoluteUrl(request.origin, request.path);\n const parsedUrl = parseUrl(url);\n\n const data: Partial<SanitizedRequestData> = {\n url: getSanitizedUrlString(parsedUrl),\n 'http.method': request.method || 'GET',\n };\n\n if (parsedUrl.search) {\n data['http.query'] = parsedUrl.search;\n }\n if (parsedUrl.hash) {\n data['http.fragment'] = parsedUrl.hash;\n }\n\n return data;\n } catch {\n return {};\n }\n}\n\nfunction getAbsoluteUrl(origin: string, path: string = '/'): string {\n try {\n const url = new URL(path, origin);\n return url.toString();\n } catch {\n // fallback: Construct it on our own\n const url = `${origin}`;\n\n if (url.endsWith('/') && path.startsWith('/')) {\n return `${url}${path.slice(1)}`;\n }\n\n if (!url.endsWith('/') && !path.startsWith('/')) {\n return `${url}/${path.slice(1)}`;\n }\n\n return `${url}${path}`;\n }\n}\n"],"names":[],"mappings":";;;;;;;;AAmBA,MAAM,mBAAA,GAAsB,cAAc;AAC1C,MAAM,qBAAA,GAAwB,SAAS;;AAEvC;AACA,MAAM,oBAAA,GAAuB,mBAAmB;;AAyBhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,8BAAA,SAAuC,mBAAmB,CAAwC;AAC/G;AACA;;AAIA,GAAS,WAAW,CAAC,MAAM,GAA0C,EAAE,EAAE;AACzE,IAAI,KAAK,CAAC,oCAAoC,EAAE,OAAO,EAAE,MAAM,CAAC;AAChE,IAAI,IAAI,CAAC,YAAa,GAAE,EAAE;AAC1B,IAAI,IAAI,CAAC,uBAAwB,GAAE,IAAI,MAAM,CAAkB,GAAG,CAAC;AACnE;;AAEA;AACA,GAAS,IAAI,GAAS;AACtB,IAAI,OAAO,SAAS;AACpB;;AAEA;AACA,GAAS,OAAO,GAAS;AACzB,IAAI,KAAK,CAAC,OAAO,EAAE;AACnB,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,GAAI,IAAG,GAAG,CAAC,WAAW,EAAE,CAAC;AACvD,IAAI,IAAI,CAAC,YAAa,GAAE,EAAE;AAC1B;;AAEA;AACA,GAAS,MAAM,GAAS;AACxB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,KAAK,CAAC,MAAM,EAAE;;AAElB;AACA;AACA,IAAI,IAAI,CAAC,YAAa,GAAE,IAAI,CAAC,YAAA,IAAgB,EAAE;;AAE/C;AACA,IAAI,IAAI,IAAI,CAAC,YAAY,CAAC,MAAA,GAAS,CAAC,EAAE;AACtC,MAAM;AACN;;AAEA,IAAI,IAAI,CAAC,mBAAmB,CAAC,uB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EAAA;AACA,MAAA,IAAA,CAAA,YAAA,CAAA,GAAA,SAAA,CAAA,MAAA;AACA;AACA,IAAA,IAAA,SAAA,CAAA,IAAA,EAAA;AACA,MAAA,IAAA,CAAA,eAAA,CAAA,GAAA,SAAA,CAAA,IAAA;AACA;;AAEA,IAAA,OAAA,IAAA;AACA,GAAA,CAAA,MAAA;AACA,IAAA,OAAA,EAAA;AACA;AACA;;AAEA,SAAA,cAAA,CAAA,MAAA,EAAA,IAAA,GAAA,GAAA,EAAA;AACA,EAAA,IAAA;AACA,IAAA,MAAA,GAAA,GAAA,IAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AACA,IAAA,OAAA,GAAA,CAAA,QAAA,EAAA;AACA,GAAA,CAAA,MAAA;AACA;AACA,IAAA,MAAA,GAAA,GAAA,CAAA,EAAA,MAAA,CAAA,CAAA;;AAEA,IAAA,IAAA,GAAA,CAAA,QAAA,CAAA,GAAA,CAAA,IAAA,IAAA,CAAA,UAAA,CAAA,GAAA,CAAA,EAAA;AACA,MAAA,OAAA,CAAA,EAAA,GAAA,CAAA,EAAA,IAAA,CAAA,KAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AACA;;AAEA,IAAA,IAAA,CAAA,GAAA,CAAA,QAAA,CAAA,GAAA,CAAA,IAAA,CAAA,IAAA,CAAA,UAAA,CAAA,GAAA,CAAA,EAAA;AACA,MAAA,OAAA,CAAA,EAAA,GAAA,CAAA,CAAA,EAAA,IAAA,CAAA,KAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AACA;;AAEA,IAAA,OAAA,CAAA,EAAA,GAAA,CAAA,EAAA,IAAA,CAAA,CAAA;AACA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"SentryNodeFetchInstrumentation.js","sources":["../../../../src/integrations/node-fetch/SentryNodeFetchInstrumentation.ts"],"sourcesContent":["import { context } from '@opentelemetry/api';\nimport { isTracingSuppressed, VERSION } from '@opentelemetry/core';\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport { InstrumentationBase } from '@opentelemetry/instrumentation';\nimport type { SanitizedRequestData } from '@sentry/core';\nimport {\n addBreadcrumb,\n getBreadcrumbLogLevelFromHttpStatusCode,\n getClient,\n getSanitizedUrlString,\n getTraceData,\n LRUMap,\n parseUrl,\n} from '@sentry/core';\nimport { shouldPropagateTraceForUrl } from '@sentry/opentelemetry';\nimport * as diagch from 'diagnostics_channel';\nimport { NODE_MAJOR, NODE_MINOR } from '../../nodeVersion';\nimport { mergeBaggageHeaders } from '../../utils/baggage';\nimport type { UndiciRequest, UndiciResponse } from './types';\n\nconst SENTRY_TRACE_HEADER = 'sentry-trace';\nconst SENTRY_BAGGAGE_HEADER = 'baggage';\n\n// For baggage, we make sure to merge this into a possibly existing header\nconst BAGGAGE_HEADER_REGEX = /baggage: (.*)\\r\\n/;\n\nexport type SentryNodeFetchInstrumentationOptions = InstrumentationConfig & {\n /**\n * Whether breadcrumbs should be recorded for requests.\n *\n * @default `true`\n */\n breadcrumbs?: boolean;\n\n /**\n * Do not capture breadcrumbs or inject headers for outgoing fetch requests to URLs where the given callback returns `true`.\n * The same option can be passed to the top-level httpIntegration where it controls both, breadcrumb and\n * span creation.\n *\n * @param url Contains the entire URL, including query string (if any), protocol, host, etc. of the outgoing request.\n */\n ignoreOutgoingRequests?: (url: string) => boolean;\n};\n\ninterface ListenerRecord {\n name: string;\n unsubscribe: () => void;\n}\n\n/**\n * This custom node-fetch instrumentation is used to instrument outgoing fetch requests.\n * It does not emit any spans.\n *\n * The reason this is isolated from the OpenTelemetry instrumentation is that users may overwrite this,\n * which would lead to Sentry not working as expected.\n *\n * This is heavily inspired & adapted from:\n * https://github.com/open-telemetry/opentelemetry-js-contrib/blob/28e209a9da36bc4e1f8c2b0db7360170ed46cb80/plugins/node/instrumentation-undici/src/undici.ts\n */\nexport class SentryNodeFetchInstrumentation extends InstrumentationBase<SentryNodeFetchInstrumentationOptions> {\n // Keep ref to avoid https://github.com/nodejs/node/issues/42170 bug and for\n // unsubscribing.\n private _channelSubs: Array<ListenerRecord>;\n private _propagationDecisionMap: LRUMap<string, boolean>;\n private _ignoreOutgoingRequestsMap: WeakMap<UndiciRequest, boolean>;\n\n public constructor(config: SentryNodeFetchInstrumentationOptions = {}) {\n super('@sentry/instrumentation-node-fetch', VERSION, config);\n this._channelSubs = [];\n this._propagationDecisionMap = new LRUMap<string, boolean>(100);\n this._ignoreOutgoingRequestsMap = new WeakMap<UndiciRequest, boolean>();\n }\n\n /** No need to instrument files/modules. */\n public init(): void {\n return undefined;\n }\n\n /** Disable the instrumentation. */\n public disable(): void {\n super.disable();\n this._channelSubs.forEach(sub => sub.unsubscribe());\n this._channelSubs = [];\n }\n\n /** Enable the instrumentation. */\n public enable(): void {\n // \"enabled\" handling is currently a bit messy with InstrumentationBase.\n // If constructed with `{enabled: false}`, this `.enable()` is still called,\n // and `this.getConfig().enabled !== this.isEnabled()`, creating confusion.\n //\n // For now, this class will setup for instrumenting if `.enable()` is\n // called, but use `this.getConfig().enabled` to determine if\n // instrumentation should be generated. This covers the more likely common\n // case of config being given a construction time, rather than later via\n // `instance.enable()`, `.disable()`, or `.setConfig()` calls.\n super.enable();\n\n // This method is called by the super-class constructor before ours is\n // called. So we need to ensure the property is initalized.\n this._channelSubs = this._channelSubs || [];\n\n // Avoid to duplicate subscriptions\n if (this._channelSubs.length > 0) {\n return;\n }\n\n this._subscribeToChannel('undici:request:create', this._onRequestCreated.bind(this));\n this._subscribeToChannel('undici:request:headers', this._onResponseHeaders.bind(this));\n }\n\n /**\n * This method is called when a request is created.\n * You can still mutate the request here before it is sent.\n */\n private _onRequestCreated({ request }: { request: UndiciRequest }): void {\n const config = this.getConfig();\n const enabled = config.enabled !== false;\n\n if (!enabled) {\n return;\n }\n\n const shouldIgnore = this._shouldIgnoreOutgoingRequest(request);\n // We store this decisision for later so we do not need to re-evaluate it\n // Additionally, the active context is not correct in _onResponseHeaders, so we need to make sure it is evaluated here\n this._ignoreOutgoingRequestsMap.set(request, shouldIgnore);\n\n if (shouldIgnore) {\n return;\n }\n\n const url = getAbsoluteUrl(request.origin, request.path);\n\n // Manually add the trace headers, if it applies\n // Note: We do not use `propagation.inject()` here, because our propagator relies on an active span\n // Which we do not have in this case\n // The propagator _may_ overwrite this, but this should be fine as it is the same data\n const tracePropagationTargets = getClient()?.getOptions().tracePropagationTargets;\n const addedHeaders = shouldPropagateTraceForUrl(url, tracePropagationTargets, this._propagationDecisionMap)\n ? getTraceData()\n : undefined;\n\n if (!addedHeaders) {\n return;\n }\n\n const { 'sentry-trace': sentryTrace, baggage } = addedHeaders;\n\n // We do not want to overwrite existing headers here\n // If the core UndiciInstrumentation is registered, it will already have set the headers\n // We do not want to add any then\n if (Array.isArray(request.headers)) {\n const requestHeaders = request.headers;\n\n // We do not want to overwrite existing header here, if it was already set\n if (sentryTrace && !requestHeaders.includes(SENTRY_TRACE_HEADER)) {\n requestHeaders.push(SENTRY_TRACE_HEADER, sentryTrace);\n }\n\n // For baggage, we make sure to merge this into a possibly existing header\n const existingBaggagePos = requestHeaders.findIndex(header => header === SENTRY_BAGGAGE_HEADER);\n if (baggage && existingBaggagePos === -1) {\n requestHeaders.push(SENTRY_BAGGAGE_HEADER, baggage);\n } else if (baggage) {\n const existingBaggage = requestHeaders[existingBaggagePos + 1];\n const merged = mergeBaggageHeaders(existingBaggage, baggage);\n if (merged) {\n requestHeaders[existingBaggagePos + 1] = merged;\n }\n }\n } else {\n const requestHeaders = request.headers;\n // We do not want to overwrite existing header here, if it was already set\n if (sentryTrace && !requestHeaders.includes(`${SENTRY_TRACE_HEADER}:`)) {\n request.headers += `${SENTRY_TRACE_HEADER}: ${sentryTrace}\\r\\n`;\n }\n\n const existingBaggage = request.headers.match(BAGGAGE_HEADER_REGEX)?.[1];\n if (baggage && !existingBaggage) {\n request.headers += `${SENTRY_BAGGAGE_HEADER}: ${baggage}\\r\\n`;\n } else if (baggage) {\n const merged = mergeBaggageHeaders(existingBaggage, baggage);\n if (merged) {\n request.headers = request.headers.replace(BAGGAGE_HEADER_REGEX, `baggage: ${merged}\\r\\n`);\n }\n }\n }\n }\n\n /**\n * This method is called when a response is received.\n */\n private _onResponseHeaders({ request, response }: { request: UndiciRequest; response: UndiciResponse }): void {\n const config = this.getConfig();\n const enabled = config.enabled !== false;\n\n if (!enabled) {\n return;\n }\n\n const _breadcrumbs = config.breadcrumbs;\n const breadCrumbsEnabled = typeof _breadcrumbs === 'undefined' ? true : _breadcrumbs;\n\n const shouldIgnore = this._ignoreOutgoingRequestsMap.get(request);\n\n if (breadCrumbsEnabled && !shouldIgnore) {\n addRequestBreadcrumb(request, response);\n }\n }\n\n /** Subscribe to a diagnostics channel. */\n private _subscribeToChannel(\n diagnosticChannel: string,\n onMessage: (message: unknown, name: string | symbol) => void,\n ): void {\n // `diagnostics_channel` had a ref counting bug until v18.19.0.\n // https://github.com/nodejs/node/pull/47520\n const useNewSubscribe = NODE_MAJOR > 18 || (NODE_MAJOR === 18 && NODE_MINOR >= 19);\n\n let unsubscribe: () => void;\n if (useNewSubscribe) {\n diagch.subscribe?.(diagnosticChannel, onMessage);\n unsubscribe = () => diagch.unsubscribe?.(diagnosticChannel, onMessage);\n } else {\n const channel = diagch.channel(diagnosticChannel);\n channel.subscribe(onMessage);\n unsubscribe = () => channel.unsubscribe(onMessage);\n }\n\n this._channelSubs.push({\n name: diagnosticChannel,\n unsubscribe,\n });\n }\n\n /**\n * Check if the given outgoing request should be ignored.\n */\n private _shouldIgnoreOutgoingRequest(request: UndiciRequest): boolean {\n if (isTracingSuppressed(context.active())) {\n return true;\n }\n\n // Add trace propagation headers\n const url = getAbsoluteUrl(request.origin, request.path);\n const ignoreOutgoingRequests = this.getConfig().ignoreOutgoingRequests;\n\n if (typeof ignoreOutgoingRequests !== 'function' || !url) {\n return false;\n }\n\n return ignoreOutgoingRequests(url);\n }\n}\n\n/** Add a breadcrumb for outgoing requests. */\nfunction addRequestBreadcrumb(request: UndiciRequest, response: UndiciResponse): void {\n const data = getBreadcrumbData(request);\n\n const statusCode = response.statusCode;\n const level = getBreadcrumbLogLevelFromHttpStatusCode(statusCode);\n\n addBreadcrumb(\n {\n category: 'http',\n data: {\n status_code: statusCode,\n ...data,\n },\n type: 'http',\n level,\n },\n {\n event: 'response',\n request,\n response,\n },\n );\n}\n\nfunction getBreadcrumbData(request: UndiciRequest): Partial<SanitizedRequestData> {\n try {\n const url = getAbsoluteUrl(request.origin, request.path);\n const parsedUrl = parseUrl(url);\n\n const data: Partial<SanitizedRequestData> = {\n url: getSanitizedUrlString(parsedUrl),\n 'http.method': request.method || 'GET',\n };\n\n if (parsedUrl.search) {\n data['http.query'] = parsedUrl.search;\n }\n if (parsedUrl.hash) {\n data['http.fragment'] = parsedUrl.hash;\n }\n\n return data;\n } catch {\n return {};\n }\n}\n\nfunction getAbsoluteUrl(origin: string, path: string = '/'): string {\n try {\n const url = new URL(path, origin);\n return url.toString();\n } catch {\n // fallback: Construct it on our own\n const url = `${origin}`;\n\n if (url.endsWith('/') && path.startsWith('/')) {\n return `${url}${path.slice(1)}`;\n }\n\n if (!url.endsWith('/') && !path.startsWith('/')) {\n return `${url}/${path.slice(1)}`;\n }\n\n return `${url}${path}`;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AAoBA,MAAM,mBAAA,GAAsB,cAAc;AAC1C,MAAM,qBAAA,GAAwB,SAAS;;AAEvC;AACA,MAAM,oBAAA,GAAuB,mBAAmB;;AAyBhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,8BAAA,SAAuC,mBAAmB,CAAwC;AAC/G;AACA;;AAKA,GAAS,WAAW,CAAC,MAAM,GAA0C,EAAE,EAAE;AACzE,IAAI,KAAK,CAAC,oCAAoC,EAAE,OAAO,EAAE,MAAM,CAAC;AAChE,IAAI,IAAI,CAAC,YAAa,GAAE,EAAE;AAC1B,IAAI,IAAI,CAAC,uBAAwB,GAAE,IAAI,MAAM,CAAkB,GAAG,CAAC;AACnE,IAAI,IAAI,CAAC,0BAAA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