@sentry/node 8.54.0 → 9.0.0-alpha.1
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/LICENSE +1 -1
- package/build/cjs/cron/common.js +1 -1
- package/build/cjs/cron/cron.js +1 -1
- package/build/cjs/cron/index.js +1 -1
- package/build/cjs/cron/node-cron.js +10 -11
- package/build/cjs/cron/node-cron.js.map +1 -1
- package/build/cjs/cron/node-schedule.js +2 -6
- package/build/cjs/cron/node-schedule.js.map +1 -1
- package/build/cjs/debug-build.js +1 -1
- package/build/cjs/index.js +3 -15
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/integrations/anr/index.js +8 -13
- package/build/cjs/integrations/anr/index.js.map +1 -1
- package/build/cjs/integrations/childProcess.js +19 -24
- package/build/cjs/integrations/childProcess.js.map +1 -1
- package/build/cjs/integrations/console.js +1 -1
- package/build/cjs/integrations/context.js +16 -19
- package/build/cjs/integrations/context.js.map +1 -1
- package/build/cjs/integrations/contextlines.js +6 -10
- package/build/cjs/integrations/contextlines.js.map +1 -1
- package/build/cjs/integrations/fs.js +1 -1
- package/build/cjs/integrations/http/SentryHttpInstrumentation.js +194 -28
- package/build/cjs/integrations/http/SentryHttpInstrumentation.js.map +1 -1
- package/build/cjs/integrations/http/index.js +32 -46
- package/build/cjs/integrations/http/index.js.map +1 -1
- package/build/cjs/integrations/http/vendor/getRequestInfo.js +1 -1
- package/build/cjs/integrations/http/vendor/getRequestInfo.js.map +1 -1
- package/build/cjs/integrations/local-variables/common.js +1 -1
- package/build/cjs/integrations/local-variables/index.js +1 -1
- package/build/cjs/integrations/local-variables/local-variables-async.js +4 -8
- package/build/cjs/integrations/local-variables/local-variables-async.js.map +1 -1
- package/build/cjs/integrations/local-variables/local-variables-sync.js +18 -22
- package/build/cjs/integrations/local-variables/local-variables-sync.js.map +1 -1
- package/build/cjs/integrations/modules.js +2 -2
- package/build/cjs/integrations/modules.js.map +1 -1
- package/build/cjs/integrations/node-fetch.js +3 -7
- package/build/cjs/integrations/node-fetch.js.map +1 -1
- package/build/cjs/integrations/onuncaughtexception.js +1 -1
- package/build/cjs/integrations/onunhandledrejection.js +1 -1
- package/build/cjs/integrations/processSession.js +36 -0
- package/build/cjs/integrations/processSession.js.map +1 -0
- package/build/cjs/integrations/spotlight.js +2 -2
- package/build/cjs/integrations/spotlight.js.map +1 -1
- package/build/cjs/integrations/tracing/amqplib.js +1 -1
- package/build/cjs/integrations/tracing/connect.js +2 -2
- package/build/cjs/integrations/tracing/connect.js.map +1 -1
- package/build/cjs/integrations/tracing/dataloader.js +2 -6
- package/build/cjs/integrations/tracing/dataloader.js.map +1 -1
- package/build/cjs/integrations/tracing/express.js +4 -31
- package/build/cjs/integrations/tracing/express.js.map +1 -1
- package/build/cjs/integrations/tracing/fastify.js +3 -7
- package/build/cjs/integrations/tracing/fastify.js.map +1 -1
- package/build/cjs/integrations/tracing/genericPool.js +1 -1
- package/build/cjs/integrations/tracing/graphql.js +5 -5
- package/build/cjs/integrations/tracing/graphql.js.map +1 -1
- package/build/cjs/integrations/tracing/hapi/index.js +5 -9
- package/build/cjs/integrations/tracing/hapi/index.js.map +1 -1
- package/build/cjs/integrations/tracing/index.js +1 -6
- package/build/cjs/integrations/tracing/index.js.map +1 -1
- package/build/cjs/integrations/tracing/kafka.js +1 -1
- package/build/cjs/integrations/tracing/knex.js +2 -2
- package/build/cjs/integrations/tracing/knex.js.map +1 -1
- package/build/cjs/integrations/tracing/koa.js +4 -8
- package/build/cjs/integrations/tracing/koa.js.map +1 -1
- package/build/cjs/integrations/tracing/lrumemoizer.js +1 -1
- package/build/cjs/integrations/tracing/mongo.js +1 -1
- package/build/cjs/integrations/tracing/mongoose.js +1 -1
- package/build/cjs/integrations/tracing/mysql.js +1 -1
- package/build/cjs/integrations/tracing/mysql2.js +1 -1
- package/build/cjs/integrations/tracing/postgres.js +1 -1
- package/build/cjs/integrations/tracing/prisma.js +22 -27
- package/build/cjs/integrations/tracing/prisma.js.map +1 -1
- package/build/cjs/integrations/tracing/redis.js +4 -8
- package/build/cjs/integrations/tracing/redis.js.map +1 -1
- package/build/cjs/integrations/tracing/tedious.js +3 -7
- package/build/cjs/integrations/tracing/tedious.js.map +1 -1
- package/build/cjs/integrations/tracing/vercelai/index.js +14 -20
- package/build/cjs/integrations/tracing/vercelai/index.js.map +1 -1
- package/build/cjs/integrations/tracing/vercelai/instrumentation.js +1 -1
- package/build/cjs/nodeVersion.js +1 -1
- package/build/cjs/otel/contextManager.js +2 -2
- package/build/cjs/otel/contextManager.js.map +1 -1
- package/build/cjs/otel/instrument.js +1 -1
- package/build/cjs/proxy/base.js +30 -33
- package/build/cjs/proxy/base.js.map +1 -1
- package/build/cjs/proxy/index.js +3 -8
- package/build/cjs/proxy/index.js.map +1 -1
- package/build/cjs/proxy/parse-proxy-response.js +2 -2
- package/build/cjs/proxy/parse-proxy-response.js.map +1 -1
- package/build/cjs/sdk/api.js +2 -2
- package/build/cjs/sdk/api.js.map +1 -1
- package/build/cjs/sdk/client.js +3 -8
- package/build/cjs/sdk/client.js.map +1 -1
- package/build/cjs/sdk/index.js +5 -58
- package/build/cjs/sdk/index.js.map +1 -1
- package/build/cjs/sdk/initOtel.js +8 -22
- package/build/cjs/sdk/initOtel.js.map +1 -1
- package/build/cjs/transports/http.js +10 -16
- package/build/cjs/transports/http.js.map +1 -1
- package/build/cjs/utils/addOriginToSpan.js +1 -1
- package/build/cjs/utils/commonjs.js +1 -1
- package/build/cjs/utils/createMissingInstrumentationContext.js +1 -1
- package/build/cjs/utils/debug.js +1 -1
- package/build/cjs/utils/ensureIsWrapped.js +2 -6
- package/build/cjs/utils/ensureIsWrapped.js.map +1 -1
- package/build/cjs/utils/envToBool.js +2 -2
- package/build/cjs/utils/envToBool.js.map +1 -1
- package/build/cjs/utils/errorhandling.js +2 -3
- package/build/cjs/utils/errorhandling.js.map +1 -1
- package/build/cjs/utils/getRequestUrl.js +1 -1
- package/build/cjs/utils/module.js +1 -1
- package/build/cjs/utils/module.js.map +1 -1
- package/build/cjs/utils/redisCache.js +1 -4
- package/build/cjs/utils/redisCache.js.map +1 -1
- package/build/esm/cron/node-cron.js +9 -7
- package/build/esm/cron/node-cron.js.map +1 -1
- package/build/esm/cron/node-schedule.js +1 -2
- package/build/esm/cron/node-schedule.js.map +1 -1
- package/build/esm/index.js +3 -4
- package/build/esm/index.js.map +1 -1
- package/build/esm/integrations/anr/index.js +8 -9
- package/build/esm/integrations/anr/index.js.map +1 -1
- package/build/esm/integrations/anr/worker-script.js +2 -2
- package/build/esm/integrations/childProcess.js +20 -24
- package/build/esm/integrations/childProcess.js.map +1 -1
- package/build/esm/integrations/context.js +15 -15
- package/build/esm/integrations/context.js.map +1 -1
- package/build/esm/integrations/contextlines.js +5 -6
- package/build/esm/integrations/contextlines.js.map +1 -1
- package/build/esm/integrations/http/SentryHttpInstrumentation.js +194 -29
- package/build/esm/integrations/http/SentryHttpInstrumentation.js.map +1 -1
- package/build/esm/integrations/http/index.js +32 -43
- package/build/esm/integrations/http/index.js.map +1 -1
- package/build/esm/integrations/http/vendor/getRequestInfo.js.map +1 -1
- package/build/esm/integrations/local-variables/local-variables-async.js +3 -4
- package/build/esm/integrations/local-variables/local-variables-async.js.map +1 -1
- package/build/esm/integrations/local-variables/local-variables-sync.js +17 -18
- package/build/esm/integrations/local-variables/local-variables-sync.js.map +1 -1
- package/build/esm/integrations/local-variables/worker-script.js +2 -2
- package/build/esm/integrations/modules.js +1 -1
- package/build/esm/integrations/modules.js.map +1 -1
- package/build/esm/integrations/node-fetch.js +3 -4
- package/build/esm/integrations/node-fetch.js.map +1 -1
- package/build/esm/integrations/processSession.js +34 -0
- package/build/esm/integrations/processSession.js.map +1 -0
- package/build/esm/integrations/spotlight.js +1 -1
- package/build/esm/integrations/spotlight.js.map +1 -1
- package/build/esm/integrations/tracing/connect.js +1 -1
- package/build/esm/integrations/tracing/connect.js.map +1 -1
- package/build/esm/integrations/tracing/dataloader.js +1 -2
- package/build/esm/integrations/tracing/dataloader.js.map +1 -1
- package/build/esm/integrations/tracing/express.js +4 -28
- package/build/esm/integrations/tracing/express.js.map +1 -1
- package/build/esm/integrations/tracing/fastify.js +2 -3
- package/build/esm/integrations/tracing/fastify.js.map +1 -1
- package/build/esm/integrations/tracing/graphql.js +4 -4
- package/build/esm/integrations/tracing/graphql.js.map +1 -1
- package/build/esm/integrations/tracing/hapi/index.js +4 -5
- package/build/esm/integrations/tracing/hapi/index.js.map +1 -1
- package/build/esm/integrations/tracing/index.js +0 -5
- package/build/esm/integrations/tracing/index.js.map +1 -1
- package/build/esm/integrations/tracing/knex.js +1 -1
- package/build/esm/integrations/tracing/knex.js.map +1 -1
- package/build/esm/integrations/tracing/koa.js +3 -4
- package/build/esm/integrations/tracing/koa.js.map +1 -1
- package/build/esm/integrations/tracing/prisma.js +21 -23
- package/build/esm/integrations/tracing/prisma.js.map +1 -1
- package/build/esm/integrations/tracing/redis.js +4 -5
- package/build/esm/integrations/tracing/redis.js.map +1 -1
- package/build/esm/integrations/tracing/tedious.js +2 -3
- package/build/esm/integrations/tracing/tedious.js.map +1 -1
- package/build/esm/integrations/tracing/vercelai/index.js +13 -16
- package/build/esm/integrations/tracing/vercelai/index.js.map +1 -1
- package/build/esm/otel/contextManager.js +1 -1
- package/build/esm/otel/contextManager.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/proxy/base.js +29 -29
- package/build/esm/proxy/base.js.map +1 -1
- package/build/esm/proxy/index.js +2 -3
- package/build/esm/proxy/index.js.map +1 -1
- package/build/esm/proxy/parse-proxy-response.js +1 -1
- package/build/esm/proxy/parse-proxy-response.js.map +1 -1
- package/build/esm/sdk/api.js +1 -1
- package/build/esm/sdk/api.js.map +1 -1
- package/build/esm/sdk/client.js +2 -3
- package/build/esm/sdk/client.js.map +1 -1
- package/build/esm/sdk/index.js +5 -58
- package/build/esm/sdk/index.js.map +1 -1
- package/build/esm/sdk/initOtel.js +7 -18
- package/build/esm/sdk/initOtel.js.map +1 -1
- package/build/esm/transports/http.js +9 -12
- package/build/esm/transports/http.js.map +1 -1
- package/build/esm/utils/ensureIsWrapped.js +1 -2
- package/build/esm/utils/ensureIsWrapped.js.map +1 -1
- package/build/esm/utils/envToBool.js +1 -1
- package/build/esm/utils/envToBool.js.map +1 -1
- package/build/esm/utils/errorhandling.js +1 -2
- package/build/esm/utils/errorhandling.js.map +1 -1
- package/build/esm/utils/module.js.map +1 -1
- package/build/esm/utils/redisCache.js +0 -3
- package/build/esm/utils/redisCache.js.map +1 -1
- package/build/types/cron/node-cron.d.ts +1 -1
- package/build/types/cron/node-cron.d.ts.map +1 -1
- package/build/types/index.d.ts +4 -6
- package/build/types/index.d.ts.map +1 -1
- package/build/types/integrations/childProcess.d.ts +7 -7
- package/build/types/integrations/childProcess.d.ts.map +1 -1
- package/build/types/integrations/http/SentryHttpInstrumentation.d.ts +31 -0
- package/build/types/integrations/http/SentryHttpInstrumentation.d.ts.map +1 -1
- package/build/types/integrations/http/index.d.ts +11 -8
- package/build/types/integrations/http/index.d.ts.map +1 -1
- package/build/types/integrations/processSession.d.ts +5 -0
- package/build/types/integrations/processSession.d.ts.map +1 -0
- package/build/types/integrations/tracing/express.d.ts.map +1 -1
- package/build/types/integrations/tracing/hapi/types.d.ts +1 -0
- package/build/types/integrations/tracing/hapi/types.d.ts.map +1 -1
- package/build/types/integrations/tracing/index.d.ts.map +1 -1
- package/build/types/integrations/tracing/prisma.d.ts +11 -12
- package/build/types/integrations/tracing/prisma.d.ts.map +1 -1
- package/build/types/integrations/tracing/vercelai/index.d.ts.map +1 -1
- package/build/types/otel/contextManager.d.ts +1 -1
- package/build/types/proxy/helpers.d.ts +1 -0
- package/build/types/proxy/helpers.d.ts.map +1 -1
- package/build/types/proxy/parse-proxy-response.d.ts +1 -0
- package/build/types/proxy/parse-proxy-response.d.ts.map +1 -1
- package/build/types/sdk/index.d.ts.map +1 -1
- package/build/types/sdk/initOtel.d.ts +1 -3
- package/build/types/sdk/initOtel.d.ts.map +1 -1
- package/build/types/transports/http-module.d.ts +1 -0
- package/build/types/transports/http-module.d.ts.map +1 -1
- package/build/types/transports/http.d.ts +1 -0
- package/build/types/transports/http.d.ts.map +1 -1
- package/build/types/types.d.ts +9 -48
- package/build/types/types.d.ts.map +1 -1
- package/build/types/utils/errorhandling.d.ts.map +1 -1
- package/build/types-ts3.8/cron/node-cron.d.ts +1 -1
- package/build/types-ts3.8/index.d.ts +4 -6
- package/build/types-ts3.8/integrations/childProcess.d.ts +7 -7
- package/build/types-ts3.8/integrations/http/SentryHttpInstrumentation.d.ts +30 -0
- package/build/types-ts3.8/integrations/http/index.d.ts +11 -8
- package/build/types-ts3.8/integrations/processSession.d.ts +5 -0
- package/build/types-ts3.8/integrations/tracing/prisma.d.ts +11 -12
- package/build/types-ts3.8/otel/contextManager.d.ts +1 -1
- package/build/types-ts3.8/sdk/initOtel.d.ts +1 -3
- package/build/types-ts3.8/types.d.ts +9 -48
- package/package.json +8 -9
- package/build/cjs/integrations/tracing/nest/helpers.js +0 -100
- package/build/cjs/integrations/tracing/nest/helpers.js.map +0 -1
- package/build/cjs/integrations/tracing/nest/nest.js +0 -148
- package/build/cjs/integrations/tracing/nest/nest.js.map +0 -1
- package/build/cjs/integrations/tracing/nest/sentry-nest-event-instrumentation.js +0 -117
- package/build/cjs/integrations/tracing/nest/sentry-nest-event-instrumentation.js.map +0 -1
- package/build/cjs/integrations/tracing/nest/sentry-nest-instrumentation.js +0 -301
- package/build/cjs/integrations/tracing/nest/sentry-nest-instrumentation.js.map +0 -1
- package/build/esm/integrations/tracing/nest/helpers.js +0 -91
- package/build/esm/integrations/tracing/nest/helpers.js.map +0 -1
- package/build/esm/integrations/tracing/nest/nest.js +0 -141
- package/build/esm/integrations/tracing/nest/nest.js.map +0 -1
- package/build/esm/integrations/tracing/nest/sentry-nest-event-instrumentation.js +0 -115
- package/build/esm/integrations/tracing/nest/sentry-nest-event-instrumentation.js.map +0 -1
- package/build/esm/integrations/tracing/nest/sentry-nest-instrumentation.js +0 -295
- package/build/esm/integrations/tracing/nest/sentry-nest-instrumentation.js.map +0 -1
- package/build/types/integrations/tracing/nest/helpers.d.ts +0 -36
- package/build/types/integrations/tracing/nest/helpers.d.ts.map +0 -1
- package/build/types/integrations/tracing/nest/nest.d.ts +0 -19
- package/build/types/integrations/tracing/nest/nest.d.ts.map +0 -1
- package/build/types/integrations/tracing/nest/sentry-nest-event-instrumentation.d.ts +0 -27
- package/build/types/integrations/tracing/nest/sentry-nest-event-instrumentation.d.ts.map +0 -1
- package/build/types/integrations/tracing/nest/sentry-nest-instrumentation.d.ts +0 -37
- package/build/types/integrations/tracing/nest/sentry-nest-instrumentation.d.ts.map +0 -1
- package/build/types/integrations/tracing/nest/types.d.ts +0 -84
- package/build/types/integrations/tracing/nest/types.d.ts.map +0 -1
- package/build/types-ts3.8/integrations/tracing/nest/helpers.d.ts +0 -36
- package/build/types-ts3.8/integrations/tracing/nest/nest.d.ts +0 -19
- package/build/types-ts3.8/integrations/tracing/nest/sentry-nest-event-instrumentation.d.ts +0 -27
- package/build/types-ts3.8/integrations/tracing/nest/sentry-nest-instrumentation.d.ts +0 -37
- package/build/types-ts3.8/integrations/tracing/nest/types.d.ts +0 -84
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { VERSION } from '@opentelemetry/core';
|
|
2
2
|
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
|
|
3
|
-
import { getIsolationScope, httpRequestToRequestData,
|
|
3
|
+
import { LRUMap, getIsolationScope, httpRequestToRequestData, stripUrlQueryAndFragment, withIsolationScope, withScope, generateSpanId, getBreadcrumbLogLevelFromHttpStatusCode, addBreadcrumb, parseUrl, getSanitizedUrlString, logger, getClient, getTraceData, parseBaggageHeader, objectToBaggageHeader } from '@sentry/core';
|
|
4
|
+
import { shouldPropagateTraceForUrl } from '@sentry/opentelemetry';
|
|
4
5
|
import { DEBUG_BUILD } from '../../debug-build.js';
|
|
5
6
|
import { getRequestUrl } from '../../utils/getRequestUrl.js';
|
|
6
7
|
import { getRequestInfo } from './vendor/getRequestInfo.js';
|
|
@@ -22,8 +23,10 @@ const MAX_BODY_BYTE_LENGTH = 1024 * 1024;
|
|
|
22
23
|
* https://github.com/open-telemetry/opentelemetry-js/blob/f8ab5592ddea5cba0a3b33bf8d74f27872c0367f/experimental/packages/opentelemetry-instrumentation-http/src/http.ts
|
|
23
24
|
*/
|
|
24
25
|
class SentryHttpInstrumentation extends InstrumentationBase {
|
|
26
|
+
|
|
25
27
|
constructor(config = {}) {
|
|
26
28
|
super('@sentry/instrumentation-http', VERSION, config);
|
|
29
|
+
this._propagationDecisionMap = new LRUMap(100);
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
/** @inheritdoc */
|
|
@@ -95,24 +98,17 @@ class SentryHttpInstrumentation extends InstrumentationBase {
|
|
|
95
98
|
|
|
96
99
|
const isolationScope = getIsolationScope().clone();
|
|
97
100
|
const request = args[0] ;
|
|
101
|
+
const response = args[1] ;
|
|
98
102
|
|
|
99
103
|
const normalizedRequest = httpRequestToRequestData(request);
|
|
100
104
|
|
|
105
|
+
// request.ip is non-standard but some frameworks set this
|
|
106
|
+
const ipAddress = (request ).ip || request.socket?.remoteAddress;
|
|
107
|
+
|
|
101
108
|
patchRequestToCaptureBody(request, isolationScope);
|
|
102
109
|
|
|
103
110
|
// Update the isolation scope, isolate this request
|
|
104
|
-
|
|
105
|
-
isolationScope.setSDKProcessingMetadata({
|
|
106
|
-
request,
|
|
107
|
-
normalizedRequest,
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
const client = getClient();
|
|
111
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
112
|
-
if (client && client.getOptions().autoSessionTracking) {
|
|
113
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
114
|
-
isolationScope.setRequestSession({ status: 'ok' });
|
|
115
|
-
}
|
|
111
|
+
isolationScope.setSDKProcessingMetadata({ normalizedRequest, ipAddress });
|
|
116
112
|
|
|
117
113
|
// attempt to update the scope's `transactionName` based on the request URL
|
|
118
114
|
// Ideally, framework instrumentations coming after the HttpInstrumentation
|
|
@@ -124,8 +120,20 @@ class SentryHttpInstrumentation extends InstrumentationBase {
|
|
|
124
120
|
|
|
125
121
|
isolationScope.setTransactionName(bestEffortTransactionName);
|
|
126
122
|
|
|
123
|
+
if (instrumentation.getConfig().trackIncomingRequestsAsSessions !== false) {
|
|
124
|
+
recordRequestSession({
|
|
125
|
+
requestIsolationScope: isolationScope,
|
|
126
|
+
response,
|
|
127
|
+
sessionFlushingDelayMS: instrumentation.getConfig().sessionFlushingDelayMS ?? 60000,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
127
131
|
return withIsolationScope(isolationScope, () => {
|
|
128
|
-
return
|
|
132
|
+
return withScope(scope => {
|
|
133
|
+
// Set a new propagationSpanId for this request
|
|
134
|
+
scope.getPropagationContext().propagationSpanId = generateSpanId();
|
|
135
|
+
return original.apply(this, [event, ...args]);
|
|
136
|
+
});
|
|
129
137
|
});
|
|
130
138
|
};
|
|
131
139
|
};
|
|
@@ -144,22 +152,21 @@ class SentryHttpInstrumentation extends InstrumentationBase {
|
|
|
144
152
|
return function outgoingRequest( ...args) {
|
|
145
153
|
instrumentation._diag.debug('http instrumentation for outgoing requests');
|
|
146
154
|
|
|
147
|
-
// Making a copy to avoid mutating the original args array
|
|
148
155
|
// We need to access and reconstruct the request options object passed to `ignoreOutgoingRequests`
|
|
149
156
|
// so that it matches what Otel instrumentation passes to `ignoreOutgoingRequestHook`.
|
|
150
157
|
// @see https://github.com/open-telemetry/opentelemetry-js/blob/7293e69c1e55ca62e15d0724d22605e61bd58952/experimental/packages/opentelemetry-instrumentation-http/src/http.ts#L756-L789
|
|
151
|
-
const
|
|
158
|
+
const requestArgs = [...args] ;
|
|
159
|
+
const options = requestArgs[0];
|
|
160
|
+
const extraOptions = typeof requestArgs[1] === 'object' ? requestArgs[1] : undefined;
|
|
152
161
|
|
|
153
|
-
const
|
|
162
|
+
const { optionsParsed, origin, pathname } = getRequestInfo(instrumentation._diag, options, extraOptions);
|
|
163
|
+
const url = getAbsoluteUrl(origin, pathname);
|
|
154
164
|
|
|
155
|
-
|
|
156
|
-
typeof argsCopy[0] === 'object' && (typeof options === 'string' || options instanceof URL)
|
|
157
|
-
? (argsCopy.shift() )
|
|
158
|
-
: undefined;
|
|
165
|
+
addSentryHeadersToRequestOptions(url, optionsParsed, instrumentation._propagationDecisionMap);
|
|
159
166
|
|
|
160
|
-
const
|
|
167
|
+
const request = original.apply(this, [optionsParsed, ...requestArgs.slice(1)])
|
|
161
168
|
|
|
162
|
-
|
|
169
|
+
;
|
|
163
170
|
|
|
164
171
|
request.prependListener('response', (response) => {
|
|
165
172
|
const _breadcrumbs = instrumentation.getConfig().breadcrumbs;
|
|
@@ -289,7 +296,7 @@ function getBreadcrumbData(request) {
|
|
|
289
296
|
}
|
|
290
297
|
|
|
291
298
|
return data;
|
|
292
|
-
} catch
|
|
299
|
+
} catch {
|
|
293
300
|
return {};
|
|
294
301
|
}
|
|
295
302
|
}
|
|
@@ -323,8 +330,8 @@ function patchRequestToCaptureBody(req, isolationScope) {
|
|
|
323
330
|
if (event === 'data') {
|
|
324
331
|
const callback = new Proxy(listener, {
|
|
325
332
|
apply: (target, thisArg, args) => {
|
|
326
|
-
// If we have already read more than the max body length, we stop
|
|
327
|
-
// To avoid growing the memory indefinitely if a
|
|
333
|
+
// If we have already read more than the max body length, we stop adding chunks
|
|
334
|
+
// To avoid growing the memory indefinitely if a response is e.g. streamed
|
|
328
335
|
if (getChunksSize() < MAX_BODY_BYTE_LENGTH) {
|
|
329
336
|
const chunk = args[0] ;
|
|
330
337
|
chunks.push(chunk);
|
|
@@ -353,7 +360,7 @@ function patchRequestToCaptureBody(req, isolationScope) {
|
|
|
353
360
|
const normalizedRequest = { data: body } ;
|
|
354
361
|
isolationScope.setSDKProcessingMetadata({ normalizedRequest });
|
|
355
362
|
}
|
|
356
|
-
} catch
|
|
363
|
+
} catch {
|
|
357
364
|
// ignore errors here
|
|
358
365
|
}
|
|
359
366
|
|
|
@@ -388,10 +395,168 @@ function patchRequestToCaptureBody(req, isolationScope) {
|
|
|
388
395
|
return Reflect.apply(target, thisArg, args);
|
|
389
396
|
},
|
|
390
397
|
});
|
|
391
|
-
} catch
|
|
398
|
+
} catch {
|
|
392
399
|
// ignore errors if we can't patch stuff
|
|
393
400
|
}
|
|
394
401
|
}
|
|
395
402
|
|
|
396
|
-
|
|
403
|
+
/**
|
|
404
|
+
* Mutates the passed in `options` and adds `sentry-trace` / `baggage` headers, if they are not already set.
|
|
405
|
+
*/
|
|
406
|
+
function addSentryHeadersToRequestOptions(
|
|
407
|
+
url,
|
|
408
|
+
options,
|
|
409
|
+
propagationDecisionMap,
|
|
410
|
+
) {
|
|
411
|
+
// Manually add the trace headers, if it applies
|
|
412
|
+
// Note: We do not use `propagation.inject()` here, because our propagator relies on an active span
|
|
413
|
+
// Which we do not have in this case
|
|
414
|
+
const tracePropagationTargets = getClient()?.getOptions().tracePropagationTargets;
|
|
415
|
+
const addedHeaders = shouldPropagateTraceForUrl(url, tracePropagationTargets, propagationDecisionMap)
|
|
416
|
+
? getTraceData()
|
|
417
|
+
: undefined;
|
|
418
|
+
|
|
419
|
+
if (!addedHeaders) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (!options.headers) {
|
|
424
|
+
options.headers = {};
|
|
425
|
+
}
|
|
426
|
+
const headers = options.headers;
|
|
427
|
+
|
|
428
|
+
const { 'sentry-trace': sentryTrace, baggage } = addedHeaders;
|
|
429
|
+
|
|
430
|
+
// We do not want to overwrite existing header here, if it was already set
|
|
431
|
+
if (sentryTrace && !headers['sentry-trace']) {
|
|
432
|
+
headers['sentry-trace'] = sentryTrace;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// For baggage, we make sure to merge this into a possibly existing header
|
|
436
|
+
if (baggage) {
|
|
437
|
+
headers['baggage'] = mergeBaggageHeaders(headers['baggage'], baggage);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Starts a session and tracks it in the context of a given isolation scope.
|
|
443
|
+
* When the passed response is finished, the session is put into a task and is
|
|
444
|
+
* aggregated with other sessions that may happen in a certain time window
|
|
445
|
+
* (sessionFlushingDelayMs).
|
|
446
|
+
*
|
|
447
|
+
* The sessions are always aggregated by the client that is on the current scope
|
|
448
|
+
* at the time of ending the response (if there is one).
|
|
449
|
+
*/
|
|
450
|
+
// Exported for unit tests
|
|
451
|
+
function recordRequestSession({
|
|
452
|
+
requestIsolationScope,
|
|
453
|
+
response,
|
|
454
|
+
sessionFlushingDelayMS,
|
|
455
|
+
}) {
|
|
456
|
+
requestIsolationScope.setSDKProcessingMetadata({
|
|
457
|
+
requestSession: { status: 'ok' },
|
|
458
|
+
});
|
|
459
|
+
response.once('close', () => {
|
|
460
|
+
// 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.
|
|
461
|
+
const client = getClient();
|
|
462
|
+
const requestSession = requestIsolationScope.getScopeData().sdkProcessingMetadata.requestSession;
|
|
463
|
+
|
|
464
|
+
if (client && requestSession) {
|
|
465
|
+
DEBUG_BUILD && logger.debug(`Recorded request session with status: ${requestSession.status}`);
|
|
466
|
+
|
|
467
|
+
const roundedDate = new Date();
|
|
468
|
+
roundedDate.setSeconds(0, 0);
|
|
469
|
+
const dateBucketKey = roundedDate.toISOString();
|
|
470
|
+
|
|
471
|
+
const existingClientAggregate = clientToRequestSessionAggregatesMap.get(client);
|
|
472
|
+
const bucket = existingClientAggregate?.[dateBucketKey] || { exited: 0, crashed: 0, errored: 0 };
|
|
473
|
+
bucket[({ ok: 'exited', crashed: 'crashed', errored: 'errored' } )[requestSession.status]]++;
|
|
474
|
+
|
|
475
|
+
if (existingClientAggregate) {
|
|
476
|
+
existingClientAggregate[dateBucketKey] = bucket;
|
|
477
|
+
} else {
|
|
478
|
+
DEBUG_BUILD && logger.debug('Opened new request session aggregate.');
|
|
479
|
+
const newClientAggregate = { [dateBucketKey]: bucket };
|
|
480
|
+
clientToRequestSessionAggregatesMap.set(client, newClientAggregate);
|
|
481
|
+
|
|
482
|
+
const flushPendingClientAggregates = () => {
|
|
483
|
+
clearTimeout(timeout);
|
|
484
|
+
unregisterClientFlushHook();
|
|
485
|
+
clientToRequestSessionAggregatesMap.delete(client);
|
|
486
|
+
|
|
487
|
+
const aggregatePayload = Object.entries(newClientAggregate).map(
|
|
488
|
+
([timestamp, value]) => ({
|
|
489
|
+
started: timestamp,
|
|
490
|
+
exited: value.exited,
|
|
491
|
+
errored: value.errored,
|
|
492
|
+
crashed: value.crashed,
|
|
493
|
+
}),
|
|
494
|
+
);
|
|
495
|
+
client.sendSession({ aggregates: aggregatePayload });
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
const unregisterClientFlushHook = client.on('flush', () => {
|
|
499
|
+
DEBUG_BUILD && logger.debug('Sending request session aggregate due to client flush');
|
|
500
|
+
flushPendingClientAggregates();
|
|
501
|
+
});
|
|
502
|
+
const timeout = setTimeout(() => {
|
|
503
|
+
DEBUG_BUILD && logger.debug('Sending request session aggregate due to flushing schedule');
|
|
504
|
+
flushPendingClientAggregates();
|
|
505
|
+
}, sessionFlushingDelayMS).unref();
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
const clientToRequestSessionAggregatesMap = new Map
|
|
512
|
+
|
|
513
|
+
();
|
|
514
|
+
|
|
515
|
+
function getAbsoluteUrl(origin, path = '/') {
|
|
516
|
+
try {
|
|
517
|
+
const url = new URL(path, origin);
|
|
518
|
+
return url.toString();
|
|
519
|
+
} catch {
|
|
520
|
+
// fallback: Construct it on our own
|
|
521
|
+
const url = `${origin}`;
|
|
522
|
+
|
|
523
|
+
if (url.endsWith('/') && path.startsWith('/')) {
|
|
524
|
+
return `${url}${path.slice(1)}`;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
if (!url.endsWith('/') && !path.startsWith('/')) {
|
|
528
|
+
return `${url}/${path.slice(1)}`;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
return `${url}${path}`;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function mergeBaggageHeaders(
|
|
536
|
+
existing,
|
|
537
|
+
baggage,
|
|
538
|
+
) {
|
|
539
|
+
if (!existing) {
|
|
540
|
+
return baggage;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
const existingBaggageEntries = parseBaggageHeader(existing);
|
|
544
|
+
const newBaggageEntries = parseBaggageHeader(baggage);
|
|
545
|
+
|
|
546
|
+
if (!newBaggageEntries) {
|
|
547
|
+
return existing;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// Existing entries take precedence, ensuring order remains stable for minimal changes
|
|
551
|
+
const mergedBaggageEntries = { ...existingBaggageEntries };
|
|
552
|
+
Object.entries(newBaggageEntries).forEach(([key, value]) => {
|
|
553
|
+
if (!mergedBaggageEntries[key]) {
|
|
554
|
+
mergedBaggageEntries[key] = value;
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
return objectToBaggageHeader(mergedBaggageEntries);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
export { SentryHttpInstrumentation, recordRequestSession };
|
|
397
562
|
//# sourceMappingURL=SentryHttpInstrumentation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SentryHttpInstrumentation.js","sources":["../../../../src/integrations/http/SentryHttpInstrumentation.ts"],"sourcesContent":["import type * as http from 'node:http';\nimport type { IncomingMessage, RequestOptions } from 'node:http';\nimport type * as https from 'node:https';\nimport { VERSION } from '@opentelemetry/core';\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';\nimport type { RequestEventData, SanitizedRequestData, Scope } from '@sentry/core';\nimport {\n addBreadcrumb,\n getBreadcrumbLogLevelFromHttpStatusCode,\n getClient,\n getIsolationScope,\n getSanitizedUrlString,\n httpRequestToRequestData,\n logger,\n parseUrl,\n stripUrlQueryAndFragment,\n withIsolationScope,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport type { NodeClient } from '../../sdk/client';\nimport { getRequestUrl } from '../../utils/getRequestUrl';\nimport { getRequestInfo } from './vendor/getRequestInfo';\ntype Http = typeof http;\ntype Https = typeof https;\n\ntype SentryHttpInstrumentationOptions = 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 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: RequestOptions) => boolean;\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 public constructor(config: SentryHttpInstrumentationOptions = {}) {\n super('@sentry/instrumentation-http', VERSION, config);\n }\n\n /** @inheritdoc */\n public init(): [InstrumentationNodeModuleDefinition, InstrumentationNodeModuleDefinition] {\n return [this._getHttpsInstrumentation(), this._getHttpInstrumentation()];\n }\n\n /** Get the instrumentation for the http module. */\n private _getHttpInstrumentation(): InstrumentationNodeModuleDefinition {\n return new InstrumentationNodeModuleDefinition(\n 'http',\n ['*'],\n (moduleExports: Http): Http => {\n // Patch incoming requests for request isolation\n stealthWrap(moduleExports.Server.prototype, 'emit', this._getPatchIncomingRequestFunction());\n\n // Patch outgoing requests for breadcrumbs\n const patchedRequest = stealthWrap(moduleExports, 'request', this._getPatchOutgoingRequestFunction());\n stealthWrap(moduleExports, 'get', this._getPatchOutgoingGetFunction(patchedRequest));\n\n return moduleExports;\n },\n () => {\n // no unwrap here\n },\n );\n }\n\n /** Get the instrumentation for the https module. */\n private _getHttpsInstrumentation(): InstrumentationNodeModuleDefinition {\n return new InstrumentationNodeModuleDefinition(\n 'https',\n ['*'],\n (moduleExports: Https): Https => {\n // Patch incoming requests for request isolation\n stealthWrap(moduleExports.Server.prototype, 'emit', this._getPatchIncomingRequestFunction());\n\n // Patch outgoing requests for breadcrumbs\n const patchedRequest = stealthWrap(moduleExports, 'request', this._getPatchOutgoingRequestFunction());\n stealthWrap(moduleExports, 'get', this._getPatchOutgoingGetFunction(patchedRequest));\n\n return moduleExports;\n },\n () => {\n // no unwrap here\n },\n );\n }\n\n /**\n * Patch the incoming request function for request isolation.\n */\n private _getPatchIncomingRequestFunction(): (\n original: (event: string, ...args: unknown[]) => boolean,\n ) => (this: unknown, event: string, ...args: unknown[]) => boolean {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const instrumentation = this;\n\n return (\n original: (event: string, ...args: unknown[]) => boolean,\n ): ((this: unknown, event: string, ...args: unknown[]) => boolean) => {\n return function incomingRequest(this: unknown, event: string, ...args: unknown[]): boolean {\n // Only traces request events\n if (event !== 'request') {\n return original.apply(this, [event, ...args]);\n }\n\n instrumentation._diag.debug('http instrumentation for incoming request');\n\n const isolationScope = getIsolationScope().clone();\n const request = args[0] as http.IncomingMessage;\n\n const normalizedRequest = httpRequestToRequestData(request);\n\n patchRequestToCaptureBody(request, isolationScope);\n\n // Update the isolation scope, isolate this request\n // TODO(v9): Stop setting `request`, we only rely on normalizedRequest anymore\n isolationScope.setSDKProcessingMetadata({\n request,\n normalizedRequest,\n });\n\n const client = getClient<NodeClient>();\n // eslint-disable-next-line deprecation/deprecation\n if (client && client.getOptions().autoSessionTracking) {\n // eslint-disable-next-line deprecation/deprecation\n isolationScope.setRequestSession({ status: 'ok' });\n }\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(request.url || '/');\n\n const bestEffortTransactionName = `${httpMethod} ${httpTarget}`;\n\n isolationScope.setTransactionName(bestEffortTransactionName);\n\n return withIsolationScope(isolationScope, () => {\n return original.apply(this, [event, ...args]);\n });\n };\n };\n }\n\n /**\n * Patch the outgoing request function for breadcrumbs.\n */\n private _getPatchOutgoingRequestFunction(): (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n original: (...args: any[]) => http.ClientRequest,\n ) => (options: URL | http.RequestOptions | string, ...args: unknown[]) => http.ClientRequest {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const instrumentation = this;\n\n return (original: (...args: unknown[]) => http.ClientRequest): ((...args: unknown[]) => http.ClientRequest) => {\n return function outgoingRequest(this: unknown, ...args: unknown[]): http.ClientRequest {\n instrumentation._diag.debug('http instrumentation for outgoing requests');\n\n // Making a copy to avoid mutating the original args array\n // We need to access and reconstruct the request options object passed to `ignoreOutgoingRequests`\n // so that it matches what Otel instrumentation passes to `ignoreOutgoingRequestHook`.\n // @see https://github.com/open-telemetry/opentelemetry-js/blob/7293e69c1e55ca62e15d0724d22605e61bd58952/experimental/packages/opentelemetry-instrumentation-http/src/http.ts#L756-L789\n const argsCopy = [...args];\n\n const options = argsCopy.shift() as URL | http.RequestOptions | string;\n\n const extraOptions =\n typeof argsCopy[0] === 'object' && (typeof options === 'string' || options instanceof URL)\n ? (argsCopy.shift() as http.RequestOptions)\n : undefined;\n\n const { optionsParsed } = getRequestInfo(instrumentation._diag, options, extraOptions);\n\n const request = original.apply(this, args) as ReturnType<typeof http.request>;\n\n request.prependListener('response', (response: http.IncomingMessage) => {\n const _breadcrumbs = instrumentation.getConfig().breadcrumbs;\n const breadCrumbsEnabled = typeof _breadcrumbs === 'undefined' ? true : _breadcrumbs;\n\n const _ignoreOutgoingRequests = instrumentation.getConfig().ignoreOutgoingRequests;\n const shouldCreateBreadcrumb =\n typeof _ignoreOutgoingRequests === 'function'\n ? !_ignoreOutgoingRequests(getRequestUrl(request), optionsParsed)\n : true;\n\n if (breadCrumbsEnabled && shouldCreateBreadcrumb) {\n addRequestBreadcrumb(request, response);\n }\n });\n\n return request;\n };\n };\n }\n\n /** Path the outgoing get function for breadcrumbs. */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _getPatchOutgoingGetFunction(clientRequest: (...args: any[]) => http.ClientRequest) {\n return (_original: unknown): ((...args: unknown[]) => http.ClientRequest) => {\n // Re-implement http.get. This needs to be done (instead of using\n // getPatchOutgoingRequestFunction to patch it) because we need to\n // set the trace context header before the returned http.ClientRequest is\n // ended. The Node.js docs state that the only differences between\n // request and get are that (1) get defaults to the HTTP GET method and\n // (2) the returned request object is ended immediately. The former is\n // already true (at least in supported Node versions up to v10), so we\n // simply follow the latter. Ref:\n // https://nodejs.org/dist/latest/docs/api/http.html#http_http_get_options_callback\n // https://github.com/googleapis/cloud-trace-nodejs/blob/master/src/instrumentations/instrumentation-http.ts#L198\n return function outgoingGetRequest(...args: unknown[]): http.ClientRequest {\n const req = clientRequest(...args);\n req.end();\n return req;\n };\n };\n }\n}\n\n/**\n * This is a minimal version of `wrap` from shimmer:\n * https://github.com/othiym23/shimmer/blob/master/index.js\n *\n * In contrast to the original implementation, this version does not allow to unwrap,\n * and does not make it clear that the method is wrapped.\n * This is necessary because we want to wrap the http module with our own code,\n * while still allowing to use the HttpInstrumentation from OTEL.\n *\n * Without this, if we'd just use `wrap` from shimmer, the OTEL instrumentation would remove our wrapping,\n * because it only allows any module to be wrapped a single time.\n */\nfunction stealthWrap<Nodule extends object, FieldName extends keyof Nodule>(\n nodule: Nodule,\n name: FieldName,\n wrapper: (original: Nodule[FieldName]) => Nodule[FieldName],\n): Nodule[FieldName] {\n const original = nodule[name];\n const wrapped = wrapper(original);\n\n defineProperty(nodule, name, wrapped);\n return wrapped;\n}\n\n// Sets a property on an object, preserving its enumerability.\nfunction defineProperty<Nodule extends object, FieldName extends keyof Nodule>(\n obj: Nodule,\n name: FieldName,\n value: Nodule[FieldName],\n): void {\n const enumerable = !!obj[name] && Object.prototype.propertyIsEnumerable.call(obj, name);\n\n Object.defineProperty(obj, name, {\n configurable: true,\n enumerable: enumerable,\n writable: true,\n value: value,\n });\n}\n\n/** Add a breadcrumb for outgoing requests. */\nfunction addRequestBreadcrumb(request: http.ClientRequest, response: http.IncomingMessage): 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(req: IncomingMessage, isolationScope: Scope): void {\n const chunks: Buffer[] = [];\n\n function getChunksSize(): number {\n return chunks.reduce((acc, chunk) => acc + chunk.byteLength, 0);\n }\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 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 const callback = new Proxy(listener, {\n apply: (target, thisArg, args: Parameters<typeof listener>) => {\n // If we have already read more than the max body length, we stop addiing chunks\n // To avoid growing the memory indefinitely if a respons is e.g. streamed\n if (getChunksSize() < MAX_BODY_BYTE_LENGTH) {\n const chunk = args[0] as Buffer;\n chunks.push(chunk);\n } else if (DEBUG_BUILD) {\n logger.log(\n `Dropping request body chunk because it maximum body length of ${MAX_BODY_BYTE_LENGTH}b is exceeded.`,\n );\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 if (event === 'end') {\n const callback = new Proxy(listener, {\n apply: (target, thisArg, args) => {\n try {\n const body = Buffer.concat(chunks).toString('utf-8');\n\n if (body) {\n const normalizedRequest = { data: body } satisfies RequestEventData;\n isolationScope.setSDKProcessingMetadata({ normalizedRequest });\n }\n } catch {\n // ignore errors here\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 } catch {\n // ignore errors if we can't patch stuff\n }\n}\n"],"names":[],"mappings":";;;;;;;AA8CA;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;AACrG,GAAS,WAAW,CAAC,MAAM,GAAqC,EAAE,EAAE;AACpE,IAAI,KAAK,CAAC,8BAA8B,EAAE,OAAO,EAAE,MAAM,CAAC;AAC1D;;AAEA;AACA,GAAS,IAAI,GAA+E;AAC5F,IAAI,OAAO,CAAC,IAAI,CAAC,wBAAwB,EAAE,EAAE,IAAI,CAAC,uBAAuB,EAAE,CAAC;AAC5E;;AAEA;AACA,GAAU,uBAAuB,GAAwC;AACzE,IAAI,OAAO,IAAI,mCAAmC;AAClD,MAAM,MAAM;AACZ,MAAM,CAAC,GAAG,CAAC;AACX,MAAM,CAAC,aAAa,KAAiB;AACrC;AACA,QAAQ,WAAW,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,gCAAgC,EAAE,CAAC;;AAEpG;AACA,QAAQ,MAAM,cAAA,GAAiB,WAAW,CAAC,aAAa,EAAE,SAAS,EAAE,IAAI,CAAC,gCAAgC,EAAE,CAAC;AAC7G,QAAQ,WAAW,CAAC,aAAa,EAAE,KAAK,EAAE,IAAI,CAAC,4BAA4B,CAAC,cAAc,CAAC,CAAC;;AAE5F,QAA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CAAA;AACA;;AAEA,QAAA,OAAA,OAAA,CAAA,KAAA,CAAA,MAAA,EAAA,OAAA,EAAA,IAAA,CAAA;AACA,OAAA;AACA,KAAA,CAAA;AACA,GAAA,CAAA,OAAA,EAAA,EAAA;AACA;AACA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"SentryHttpInstrumentation.js","sources":["../../../../src/integrations/http/SentryHttpInstrumentation.ts"],"sourcesContent":["import type * as http from 'node:http';\nimport type { IncomingMessage, RequestOptions } from 'node:http';\nimport type * as https from 'node:https';\nimport type { EventEmitter } from 'node:stream';\n/* eslint-disable max-lines */\nimport { VERSION } from '@opentelemetry/core';\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';\nimport type { AggregationCounts, Client, RequestEventData, SanitizedRequestData, Scope } from '@sentry/core';\nimport {\n LRUMap,\n addBreadcrumb,\n generateSpanId,\n getBreadcrumbLogLevelFromHttpStatusCode,\n getClient,\n getIsolationScope,\n getSanitizedUrlString,\n getTraceData,\n httpRequestToRequestData,\n logger,\n objectToBaggageHeader,\n parseBaggageHeader,\n parseUrl,\n stripUrlQueryAndFragment,\n withIsolationScope,\n withScope,\n} from '@sentry/core';\nimport { shouldPropagateTraceForUrl } from '@sentry/opentelemetry';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { getRequestUrl } from '../../utils/getRequestUrl';\nimport { getRequestInfo } from './vendor/getRequestInfo';\n\ntype Http = typeof http;\ntype Https = typeof https;\n\ntype RequestArgs =\n // eslint-disable-next-line @typescript-eslint/ban-types\n | [url: string | URL, options?: RequestOptions, callback?: Function]\n // eslint-disable-next-line @typescript-eslint/ban-types\n | [options: RequestOptions, callback?: Function];\n\ntype SentryHttpInstrumentationOptions = 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 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: RequestOptions) => boolean;\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('@sentry/instrumentation-http', VERSION, config);\n this._propagationDecisionMap = new LRUMap<string, boolean>(100);\n }\n\n /** @inheritdoc */\n public init(): [InstrumentationNodeModuleDefinition, InstrumentationNodeModuleDefinition] {\n return [this._getHttpsInstrumentation(), this._getHttpInstrumentation()];\n }\n\n /** Get the instrumentation for the http module. */\n private _getHttpInstrumentation(): InstrumentationNodeModuleDefinition {\n return new InstrumentationNodeModuleDefinition(\n 'http',\n ['*'],\n (moduleExports: Http): Http => {\n // Patch incoming requests for request isolation\n stealthWrap(moduleExports.Server.prototype, 'emit', this._getPatchIncomingRequestFunction());\n\n // Patch outgoing requests for breadcrumbs\n const patchedRequest = stealthWrap(moduleExports, 'request', this._getPatchOutgoingRequestFunction());\n stealthWrap(moduleExports, 'get', this._getPatchOutgoingGetFunction(patchedRequest));\n\n return moduleExports;\n },\n () => {\n // no unwrap here\n },\n );\n }\n\n /** Get the instrumentation for the https module. */\n private _getHttpsInstrumentation(): InstrumentationNodeModuleDefinition {\n return new InstrumentationNodeModuleDefinition(\n 'https',\n ['*'],\n (moduleExports: Https): Https => {\n // Patch incoming requests for request isolation\n stealthWrap(moduleExports.Server.prototype, 'emit', this._getPatchIncomingRequestFunction());\n\n // Patch outgoing requests for breadcrumbs\n const patchedRequest = stealthWrap(moduleExports, 'request', this._getPatchOutgoingRequestFunction());\n stealthWrap(moduleExports, 'get', this._getPatchOutgoingGetFunction(patchedRequest));\n\n return moduleExports;\n },\n () => {\n // no unwrap here\n },\n );\n }\n\n /**\n * Patch the incoming request function for request isolation.\n */\n private _getPatchIncomingRequestFunction(): (\n original: (event: string, ...args: unknown[]) => boolean,\n ) => (this: unknown, event: string, ...args: unknown[]) => boolean {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const instrumentation = this;\n\n return (\n original: (event: string, ...args: unknown[]) => boolean,\n ): ((this: unknown, event: string, ...args: unknown[]) => boolean) => {\n return function incomingRequest(this: unknown, event: string, ...args: unknown[]): boolean {\n // Only traces request events\n if (event !== 'request') {\n return original.apply(this, [event, ...args]);\n }\n\n instrumentation._diag.debug('http instrumentation for incoming request');\n\n const isolationScope = getIsolationScope().clone();\n const request = args[0] as http.IncomingMessage;\n const response = args[1] 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 patchRequestToCaptureBody(request, isolationScope);\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(request.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 return withScope(scope => {\n // Set a new propagationSpanId for this request\n scope.getPropagationContext().propagationSpanId = generateSpanId();\n return original.apply(this, [event, ...args]);\n });\n });\n };\n };\n }\n\n /**\n * Patch the outgoing request function for breadcrumbs.\n */\n private _getPatchOutgoingRequestFunction(): (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n original: (...args: any[]) => http.ClientRequest,\n ) => (options: URL | http.RequestOptions | string, ...args: unknown[]) => http.ClientRequest {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const instrumentation = this;\n\n return (original: (...args: unknown[]) => http.ClientRequest): ((...args: unknown[]) => http.ClientRequest) => {\n return function outgoingRequest(this: unknown, ...args: unknown[]): http.ClientRequest {\n instrumentation._diag.debug('http instrumentation for outgoing requests');\n\n // We need to access and reconstruct the request options object passed to `ignoreOutgoingRequests`\n // so that it matches what Otel instrumentation passes to `ignoreOutgoingRequestHook`.\n // @see https://github.com/open-telemetry/opentelemetry-js/blob/7293e69c1e55ca62e15d0724d22605e61bd58952/experimental/packages/opentelemetry-instrumentation-http/src/http.ts#L756-L789\n const requestArgs = [...args] as RequestArgs;\n const options = requestArgs[0];\n const extraOptions = typeof requestArgs[1] === 'object' ? requestArgs[1] : undefined;\n\n const { optionsParsed, origin, pathname } = getRequestInfo(instrumentation._diag, options, extraOptions);\n const url = getAbsoluteUrl(origin, pathname);\n\n addSentryHeadersToRequestOptions(url, optionsParsed, instrumentation._propagationDecisionMap);\n\n const request = original.apply(this, [optionsParsed, ...requestArgs.slice(1)]) as ReturnType<\n typeof http.request\n >;\n\n request.prependListener('response', (response: http.IncomingMessage) => {\n const _breadcrumbs = instrumentation.getConfig().breadcrumbs;\n const breadCrumbsEnabled = typeof _breadcrumbs === 'undefined' ? true : _breadcrumbs;\n\n const _ignoreOutgoingRequests = instrumentation.getConfig().ignoreOutgoingRequests;\n const shouldCreateBreadcrumb =\n typeof _ignoreOutgoingRequests === 'function'\n ? !_ignoreOutgoingRequests(getRequestUrl(request), optionsParsed)\n : true;\n\n if (breadCrumbsEnabled && shouldCreateBreadcrumb) {\n addRequestBreadcrumb(request, response);\n }\n });\n\n return request;\n };\n };\n }\n\n /** Path the outgoing get function for breadcrumbs. */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _getPatchOutgoingGetFunction(clientRequest: (...args: any[]) => http.ClientRequest) {\n return (_original: unknown): ((...args: unknown[]) => http.ClientRequest) => {\n // Re-implement http.get. This needs to be done (instead of using\n // getPatchOutgoingRequestFunction to patch it) because we need to\n // set the trace context header before the returned http.ClientRequest is\n // ended. The Node.js docs state that the only differences between\n // request and get are that (1) get defaults to the HTTP GET method and\n // (2) the returned request object is ended immediately. The former is\n // already true (at least in supported Node versions up to v10), so we\n // simply follow the latter. Ref:\n // https://nodejs.org/dist/latest/docs/api/http.html#http_http_get_options_callback\n // https://github.com/googleapis/cloud-trace-nodejs/blob/master/src/instrumentations/instrumentation-http.ts#L198\n return function outgoingGetRequest(...args: unknown[]): http.ClientRequest {\n const req = clientRequest(...args);\n req.end();\n return req;\n };\n };\n }\n}\n\n/**\n * This is a minimal version of `wrap` from shimmer:\n * https://github.com/othiym23/shimmer/blob/master/index.js\n *\n * In contrast to the original implementation, this version does not allow to unwrap,\n * and does not make it clear that the method is wrapped.\n * This is necessary because we want to wrap the http module with our own code,\n * while still allowing to use the HttpInstrumentation from OTEL.\n *\n * Without this, if we'd just use `wrap` from shimmer, the OTEL instrumentation would remove our wrapping,\n * because it only allows any module to be wrapped a single time.\n */\nfunction stealthWrap<Nodule extends object, FieldName extends keyof Nodule>(\n nodule: Nodule,\n name: FieldName,\n wrapper: (original: Nodule[FieldName]) => Nodule[FieldName],\n): Nodule[FieldName] {\n const original = nodule[name];\n const wrapped = wrapper(original);\n\n defineProperty(nodule, name, wrapped);\n return wrapped;\n}\n\n// Sets a property on an object, preserving its enumerability.\nfunction defineProperty<Nodule extends object, FieldName extends keyof Nodule>(\n obj: Nodule,\n name: FieldName,\n value: Nodule[FieldName],\n): void {\n const enumerable = !!obj[name] && Object.prototype.propertyIsEnumerable.call(obj, name);\n\n Object.defineProperty(obj, name, {\n configurable: true,\n enumerable: enumerable,\n writable: true,\n value: value,\n });\n}\n\n/** Add a breadcrumb for outgoing requests. */\nfunction addRequestBreadcrumb(request: http.ClientRequest, response: http.IncomingMessage): 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(req: IncomingMessage, isolationScope: Scope): void {\n const chunks: Buffer[] = [];\n\n function getChunksSize(): number {\n return chunks.reduce((acc, chunk) => acc + chunk.byteLength, 0);\n }\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 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 const callback = new Proxy(listener, {\n apply: (target, thisArg, args: Parameters<typeof listener>) => {\n // If we have already read more than the max body length, we stop adding chunks\n // To avoid growing the memory indefinitely if a response is e.g. streamed\n if (getChunksSize() < MAX_BODY_BYTE_LENGTH) {\n const chunk = args[0] as Buffer;\n chunks.push(chunk);\n } else if (DEBUG_BUILD) {\n logger.log(\n `Dropping request body chunk because it maximum body length of ${MAX_BODY_BYTE_LENGTH}b is exceeded.`,\n );\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 if (event === 'end') {\n const callback = new Proxy(listener, {\n apply: (target, thisArg, args) => {\n try {\n const body = Buffer.concat(chunks).toString('utf-8');\n\n if (body) {\n const normalizedRequest = { data: body } satisfies RequestEventData;\n isolationScope.setSDKProcessingMetadata({ normalizedRequest });\n }\n } catch {\n // ignore errors here\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 } catch {\n // ignore errors if we can't patch stuff\n }\n}\n\n/**\n * Mutates the passed in `options` and adds `sentry-trace` / `baggage` headers, if they are not already set.\n */\nfunction addSentryHeadersToRequestOptions(\n url: string,\n options: RequestOptions,\n propagationDecisionMap: LRUMap<string, boolean>,\n): void {\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, propagationDecisionMap)\n ? getTraceData()\n : undefined;\n\n if (!addedHeaders) {\n return;\n }\n\n if (!options.headers) {\n options.headers = {};\n }\n const headers = options.headers;\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 && !headers['sentry-trace']) {\n headers['sentry-trace'] = sentryTrace;\n }\n\n // For baggage, we make sure to merge this into a possibly existing header\n if (baggage) {\n headers['baggage'] = mergeBaggageHeaders(headers['baggage'], baggage);\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}: { requestIsolationScope: Scope; response: EventEmitter; sessionFlushingDelayMS?: number }): 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\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\nfunction mergeBaggageHeaders(\n existing: string | string[] | number | undefined,\n baggage: string,\n): string | string[] | number | undefined {\n if (!existing) {\n return baggage;\n }\n\n const existingBaggageEntries = parseBaggageHeader(existing);\n const newBaggageEntries = parseBaggageHeader(baggage);\n\n if (!newBaggageEntries) {\n return existing;\n }\n\n // Existing entries take precedence, ensuring order remains stable for minimal changes\n const mergedBaggageEntries = { ...existingBaggageEntries };\n Object.entries(newBaggageEntries).forEach(([key, value]) => {\n if (!mergedBaggageEntries[key]) {\n mergedBaggageEntries[key] = value;\n }\n });\n\n return objectToBaggageHeader(mergedBaggageEntries);\n}\n"],"names":[],"mappings":";;;;;;;;AA4EA;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,8BAA8B,EAAE,OAAO,EAAE,MAAM,CAAC;AAC1D,IAAI,IAAI,CAAC,uBAAwB,GAAE,IAAI,MAAM,CAAkB,GAAG,CAAC;AACnE;;AAEA;AACA,GAAS,IAAI,GAA+E;AAC5F,IAAI,OAAO,CAAC,IAAI,CAAC,wBAAwB,EAAE,EAAE,IAAI,CAAC,uBAAuB,EAAE,CAAC;AAC5E;;AAEA;AACA,GAAU,uBAAuB,GAAwC;AACzE,IAAI,OAAO,IAAI,mCAAmC;AACl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;;AAEA,SAAA,mBAAA;AACA,EAAA,QAAA;AACA,EAAA,OAAA;AACA,EAAA;AACA,EAAA,IAAA,CAAA,QAAA,EAAA;AACA,IAAA,OAAA,OAAA;AACA;;AAEA,EAAA,MAAA,sBAAA,GAAA,kBAAA,CAAA,QAAA,CAAA;AACA,EAAA,MAAA,iBAAA,GAAA,kBAAA,CAAA,OAAA,CAAA;;AAEA,EAAA,IAAA,CAAA,iBAAA,EAAA;AACA,IAAA,OAAA,QAAA;AACA;;AAEA;AACA,EAAA,MAAA,oBAAA,GAAA,EAAA,GAAA,sBAAA,EAAA;AACA,EAAA,MAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,CAAA,OAAA,CAAA,CAAA,CAAA,GAAA,EAAA,KAAA,CAAA,KAAA;AACA,IAAA,IAAA,CAAA,oBAAA,CAAA,GAAA,CAAA,EAAA;AACA,MAAA,oBAAA,CAAA,GAAA,CAAA,GAAA,KAAA;AACA;AACA,GAAA,CAAA;;AAEA,EAAA,OAAA,qBAAA,CAAA,oBAAA,CAAA;AACA;;;;"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { _optionalChain } from '@sentry/core';
|
|
2
1
|
import { diag } from '@opentelemetry/api';
|
|
3
2
|
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
|
|
4
|
-
import { defineIntegration } from '@sentry/core';
|
|
5
|
-
import { getClient } from '@sentry/opentelemetry';
|
|
3
|
+
import { defineIntegration, getClient } from '@sentry/core';
|
|
6
4
|
import { generateInstrumentOnce } from '../../otel/instrument.js';
|
|
7
5
|
import { addOriginToSpan } from '../../utils/addOriginToSpan.js';
|
|
8
6
|
import { getRequestUrl } from '../../utils/getRequestUrl.js';
|
|
@@ -16,8 +14,10 @@ const instrumentSentryHttp = generateInstrumentOnce
|
|
|
16
14
|
|
|
17
15
|
(`${INTEGRATION_NAME}.sentry`, options => {
|
|
18
16
|
return new SentryHttpInstrumentation({
|
|
19
|
-
breadcrumbs:
|
|
20
|
-
ignoreOutgoingRequests:
|
|
17
|
+
breadcrumbs: options?.breadcrumbs,
|
|
18
|
+
ignoreOutgoingRequests: options?.ignoreOutgoingRequests,
|
|
19
|
+
trackIncomingRequestsAsSessions: options?.trackIncomingRequestsAsSessions,
|
|
20
|
+
sessionFlushingDelayMS: options?.sessionFlushingDelayMS,
|
|
21
21
|
});
|
|
22
22
|
});
|
|
23
23
|
|
|
@@ -31,28 +31,19 @@ const instrumentOtelHttp = generateInstrumentOnce(INTEGRATION_NAME, config => {
|
|
|
31
31
|
});
|
|
32
32
|
// @ts-expect-error We are writing a read-only property here...
|
|
33
33
|
instrumentation.instrumentationName = INSTRUMENTATION_NAME;
|
|
34
|
-
} catch
|
|
34
|
+
} catch {
|
|
35
35
|
// ignore errors here...
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
return instrumentation;
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const instrumentationConfig = getConfigWithDefaults(options);
|
|
48
|
-
instrumentOtelHttp(instrumentationConfig);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// This is the Sentry-specific instrumentation that isolates requests & creates breadcrumbs
|
|
52
|
-
// Note that this _has_ to be wrapped after the OTEL instrumentation,
|
|
53
|
-
// otherwise the isolation will not work correctly
|
|
54
|
-
instrumentSentryHttp(options);
|
|
55
|
-
};
|
|
41
|
+
/** Exported only for tests. */
|
|
42
|
+
function _shouldInstrumentSpans(options, clientOptions = {}) {
|
|
43
|
+
// If `spans` is passed in, it takes precedence
|
|
44
|
+
// Else, we by default emit spans, unless `skipOpenTelemetrySetup` is set to `true`
|
|
45
|
+
return typeof options.spans === 'boolean' ? options.spans : !clientOptions.skipOpenTelemetrySetup;
|
|
46
|
+
}
|
|
56
47
|
|
|
57
48
|
/**
|
|
58
49
|
* The http integration instruments Node's internal http and https modules.
|
|
@@ -62,7 +53,18 @@ const httpIntegration = defineIntegration((options = {}) => {
|
|
|
62
53
|
return {
|
|
63
54
|
name: INTEGRATION_NAME,
|
|
64
55
|
setupOnce() {
|
|
65
|
-
|
|
56
|
+
const instrumentSpans = _shouldInstrumentSpans(options, getClient()?.getOptions());
|
|
57
|
+
|
|
58
|
+
// This is the "regular" OTEL instrumentation that emits spans
|
|
59
|
+
if (instrumentSpans) {
|
|
60
|
+
const instrumentationConfig = getConfigWithDefaults(options);
|
|
61
|
+
instrumentOtelHttp(instrumentationConfig);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// This is the Sentry-specific instrumentation that isolates requests & creates breadcrumbs
|
|
65
|
+
// Note that this _has_ to be wrapped after the OTEL instrumentation,
|
|
66
|
+
// otherwise the isolation will not work correctly
|
|
67
|
+
instrumentSentryHttp(options);
|
|
66
68
|
},
|
|
67
69
|
};
|
|
68
70
|
});
|
|
@@ -86,7 +88,7 @@ function isKnownPrefetchRequest(req) {
|
|
|
86
88
|
|
|
87
89
|
function getConfigWithDefaults(options = {}) {
|
|
88
90
|
const instrumentationConfig = {
|
|
89
|
-
...
|
|
91
|
+
...options.instrumentation?._experimentalConfig,
|
|
90
92
|
|
|
91
93
|
disableIncomingRequestInstrumentation: options.disableIncomingRequestSpans,
|
|
92
94
|
|
|
@@ -98,7 +100,7 @@ function getConfigWithDefaults(options = {}) {
|
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
const _ignoreOutgoingRequests = options.ignoreOutgoingRequests;
|
|
101
|
-
if (_ignoreOutgoingRequests
|
|
103
|
+
if (_ignoreOutgoingRequests?.(url, request)) {
|
|
102
104
|
return true;
|
|
103
105
|
}
|
|
104
106
|
|
|
@@ -110,14 +112,14 @@ function getConfigWithDefaults(options = {}) {
|
|
|
110
112
|
// it only consists of the URL path and query string (if any)
|
|
111
113
|
const urlPath = request.url;
|
|
112
114
|
|
|
113
|
-
const method =
|
|
115
|
+
const method = request.method?.toUpperCase();
|
|
114
116
|
// We do not capture OPTIONS/HEAD requests as transactions
|
|
115
117
|
if (method === 'OPTIONS' || method === 'HEAD') {
|
|
116
118
|
return true;
|
|
117
119
|
}
|
|
118
120
|
|
|
119
121
|
const _ignoreIncomingRequests = options.ignoreIncomingRequests;
|
|
120
|
-
if (urlPath && _ignoreIncomingRequests
|
|
122
|
+
if (urlPath && _ignoreIncomingRequests?.(urlPath, request)) {
|
|
121
123
|
return true;
|
|
122
124
|
}
|
|
123
125
|
|
|
@@ -132,35 +134,22 @@ function getConfigWithDefaults(options = {}) {
|
|
|
132
134
|
span.setAttribute('sentry.http.prefetch', true);
|
|
133
135
|
}
|
|
134
136
|
|
|
135
|
-
|
|
137
|
+
options.instrumentation?.requestHook?.(span, req);
|
|
136
138
|
},
|
|
137
139
|
responseHook: (span, res) => {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (
|
|
141
|
-
client &&
|
|
142
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
143
|
-
client.getOptions().autoSessionTracking !== false &&
|
|
144
|
-
options.trackIncomingRequestsAsSessions !== false
|
|
145
|
-
) {
|
|
146
|
-
setImmediate(() => {
|
|
147
|
-
client['_captureRequestSession']();
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
_optionalChain([options, 'access', _11 => _11.instrumentation, 'optionalAccess', _12 => _12.responseHook, 'optionalCall', _13 => _13(span, res)]);
|
|
140
|
+
options.instrumentation?.responseHook?.(span, res);
|
|
152
141
|
},
|
|
153
142
|
applyCustomAttributesOnSpan: (
|
|
154
143
|
span,
|
|
155
144
|
request,
|
|
156
145
|
response,
|
|
157
146
|
) => {
|
|
158
|
-
|
|
147
|
+
options.instrumentation?.applyCustomAttributesOnSpan?.(span, request, response);
|
|
159
148
|
},
|
|
160
149
|
} ;
|
|
161
150
|
|
|
162
151
|
return instrumentationConfig;
|
|
163
152
|
}
|
|
164
153
|
|
|
165
|
-
export { httpIntegration, instrumentOtelHttp
|
|
154
|
+
export { _shouldInstrumentSpans, httpIntegration, instrumentOtelHttp };
|
|
166
155
|
//# sourceMappingURL=index.js.map
|