@sentry/node 9.15.0 → 9.16.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/context.js +1 -0
- package/build/cjs/integrations/context.js.map +1 -1
- package/build/cjs/integrations/http/SentryHttpInstrumentation.js +130 -126
- package/build/cjs/integrations/http/SentryHttpInstrumentation.js.map +1 -1
- package/build/cjs/integrations/http/SentryHttpInstrumentationBeforeOtel.js +50 -44
- package/build/cjs/integrations/http/SentryHttpInstrumentationBeforeOtel.js.map +1 -1
- package/build/cjs/integrations/http/index.js +31 -7
- package/build/cjs/integrations/http/index.js.map +1 -1
- package/build/cjs/integrations/local-variables/local-variables-async.js +1 -1
- package/build/cjs/integrations/tracing/express-v5/instrumentation.js +4 -2
- package/build/cjs/integrations/tracing/express-v5/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/index.js +2 -4
- package/build/cjs/integrations/tracing/index.js.map +1 -1
- package/build/cjs/integrations/tracing/prisma.js +2 -7
- package/build/cjs/integrations/tracing/prisma.js.map +1 -1
- package/build/cjs/integrations/winston.js +2 -2
- package/build/cjs/integrations/winston.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/context.js +1 -0
- package/build/esm/integrations/context.js.map +1 -1
- package/build/esm/integrations/http/SentryHttpInstrumentation.js +131 -127
- package/build/esm/integrations/http/SentryHttpInstrumentation.js.map +1 -1
- package/build/esm/integrations/http/SentryHttpInstrumentationBeforeOtel.js +51 -45
- package/build/esm/integrations/http/SentryHttpInstrumentationBeforeOtel.js.map +1 -1
- package/build/esm/integrations/http/index.js +31 -7
- package/build/esm/integrations/http/index.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/tracing/express-v5/instrumentation.js +4 -2
- package/build/esm/integrations/tracing/express-v5/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/index.js +2 -4
- package/build/esm/integrations/tracing/index.js.map +1 -1
- package/build/esm/integrations/tracing/prisma.js +2 -7
- package/build/esm/integrations/tracing/prisma.js.map +1 -1
- package/build/esm/integrations/winston.js +2 -2
- package/build/esm/integrations/winston.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/types/integrations/context.d.ts.map +1 -1
- package/build/types/integrations/http/SentryHttpInstrumentation.d.ts +9 -13
- package/build/types/integrations/http/SentryHttpInstrumentation.d.ts.map +1 -1
- package/build/types/integrations/http/SentryHttpInstrumentationBeforeOtel.d.ts.map +1 -1
- package/build/types/integrations/http/index.d.ts +8 -0
- package/build/types/integrations/http/index.d.ts.map +1 -1
- package/build/types/integrations/tracing/express-v5/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/index.d.ts.map +1 -1
- package/build/types/integrations/tracing/prisma.d.ts.map +1 -1
- package/build/types/integrations/winston.d.ts +3 -3
- package/build/types-ts3.8/integrations/http/SentryHttpInstrumentation.d.ts +9 -13
- package/build/types-ts3.8/integrations/http/index.d.ts +11 -0
- package/build/types-ts3.8/integrations/winston.d.ts +3 -3
- package/package.json +4 -4
- package/build/cjs/integrations/http/vendor/getRequestInfo.js +0 -130
- package/build/cjs/integrations/http/vendor/getRequestInfo.js.map +0 -1
- package/build/esm/integrations/http/vendor/getRequestInfo.js +0 -128
- package/build/esm/integrations/http/vendor/getRequestInfo.js.map +0 -1
- package/build/types/integrations/http/vendor/getRequestInfo.d.ts +0 -21
- package/build/types/integrations/http/vendor/getRequestInfo.d.ts.map +0 -1
- package/build/types-ts3.8/integrations/http/vendor/getRequestInfo.d.ts +0 -21
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
+
const diagnosticsChannel = require('node:diagnostics_channel');
|
|
3
4
|
const api = require('@opentelemetry/api');
|
|
4
5
|
const core = require('@opentelemetry/core');
|
|
5
6
|
const instrumentation = require('@opentelemetry/instrumentation');
|
|
6
7
|
const core$1 = require('@sentry/core');
|
|
7
8
|
const debugBuild = require('../../debug-build.js');
|
|
8
9
|
const getRequestUrl = require('../../utils/getRequestUrl.js');
|
|
9
|
-
const utils = require('./utils.js');
|
|
10
|
-
const getRequestInfo = require('./vendor/getRequestInfo.js');
|
|
11
10
|
|
|
12
11
|
const INSTRUMENTATION_NAME = '@sentry/instrumentation-http';
|
|
13
12
|
|
|
@@ -34,71 +33,134 @@ class SentryHttpInstrumentation extends instrumentation.InstrumentationBase {
|
|
|
34
33
|
|
|
35
34
|
/** @inheritdoc */
|
|
36
35
|
init() {
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
// We register handlers when either http or https is instrumented
|
|
37
|
+
// but we only want to register them once, whichever is loaded first
|
|
38
|
+
let hasRegisteredHandlers = false;
|
|
39
|
+
|
|
40
|
+
const onHttpServerRequestStart = ((_data) => {
|
|
41
|
+
const data = _data ;
|
|
42
|
+
this._patchServerEmitOnce(data.server);
|
|
43
|
+
}) ;
|
|
44
|
+
|
|
45
|
+
const onHttpClientResponseFinish = ((_data) => {
|
|
46
|
+
const data = _data ;
|
|
47
|
+
this._onOutgoingRequestFinish(data.request, data.response);
|
|
48
|
+
}) ;
|
|
49
|
+
|
|
50
|
+
const onHttpClientRequestError = ((_data) => {
|
|
51
|
+
const data = _data ;
|
|
52
|
+
this._onOutgoingRequestFinish(data.request, undefined);
|
|
53
|
+
}) ;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* You may be wondering why we register these diagnostics-channel listeners
|
|
57
|
+
* in such a convoluted way (as InstrumentationNodeModuleDefinition...)˝,
|
|
58
|
+
* instead of simply subscribing to the events once in here.
|
|
59
|
+
* The reason for this is timing semantics: These functions are called once the http or https module is loaded.
|
|
60
|
+
* If we'd subscribe before that, there seem to be conflicts with the OTEL native instrumentation in some scenarios,
|
|
61
|
+
* especially the "import-on-top" pattern of setting up ESM applications.
|
|
62
|
+
*/
|
|
63
|
+
return [
|
|
64
|
+
new instrumentation.InstrumentationNodeModuleDefinition(
|
|
65
|
+
'http',
|
|
66
|
+
['*'],
|
|
67
|
+
(moduleExports) => {
|
|
68
|
+
if (hasRegisteredHandlers) {
|
|
69
|
+
return moduleExports;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
hasRegisteredHandlers = true;
|
|
73
|
+
|
|
74
|
+
diagnosticsChannel.subscribe('http.server.request.start', onHttpServerRequestStart);
|
|
75
|
+
diagnosticsChannel.subscribe('http.client.response.finish', onHttpClientResponseFinish);
|
|
76
|
+
|
|
77
|
+
// When an error happens, we still want to have a breadcrumb
|
|
78
|
+
// In this case, `http.client.response.finish` is not triggered
|
|
79
|
+
diagnosticsChannel.subscribe('http.client.request.error', onHttpClientRequestError);
|
|
80
|
+
|
|
81
|
+
return moduleExports;
|
|
82
|
+
},
|
|
83
|
+
() => {
|
|
84
|
+
diagnosticsChannel.unsubscribe('http.server.request.start', onHttpServerRequestStart);
|
|
85
|
+
diagnosticsChannel.unsubscribe('http.client.response.finish', onHttpClientResponseFinish);
|
|
86
|
+
diagnosticsChannel.unsubscribe('http.client.request.error', onHttpClientRequestError);
|
|
87
|
+
},
|
|
88
|
+
),
|
|
89
|
+
new instrumentation.InstrumentationNodeModuleDefinition(
|
|
90
|
+
'https',
|
|
91
|
+
['*'],
|
|
92
|
+
(moduleExports) => {
|
|
93
|
+
if (hasRegisteredHandlers) {
|
|
94
|
+
return moduleExports;
|
|
95
|
+
}
|
|
39
96
|
|
|
40
|
-
|
|
41
|
-
_getHttpInstrumentation() {
|
|
42
|
-
return new instrumentation.InstrumentationNodeModuleDefinition(
|
|
43
|
-
'http',
|
|
44
|
-
['*'],
|
|
45
|
-
(moduleExports) => {
|
|
46
|
-
// Patch incoming requests for request isolation
|
|
47
|
-
utils.stealthWrap(moduleExports.Server.prototype, 'emit', this._getPatchIncomingRequestFunction());
|
|
97
|
+
hasRegisteredHandlers = true;
|
|
48
98
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
utils.stealthWrap(moduleExports, 'get', this._getPatchOutgoingGetFunction(patchedRequest));
|
|
99
|
+
diagnosticsChannel.subscribe('http.server.request.start', onHttpServerRequestStart);
|
|
100
|
+
diagnosticsChannel.subscribe('http.client.response.finish', onHttpClientResponseFinish);
|
|
52
101
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
102
|
+
// When an error happens, we still want to have a breadcrumb
|
|
103
|
+
// In this case, `http.client.response.finish` is not triggered
|
|
104
|
+
diagnosticsChannel.subscribe('http.client.request.error', onHttpClientRequestError);
|
|
105
|
+
|
|
106
|
+
return moduleExports;
|
|
107
|
+
},
|
|
108
|
+
() => {
|
|
109
|
+
diagnosticsChannel.unsubscribe('http.server.request.start', onHttpServerRequestStart);
|
|
110
|
+
diagnosticsChannel.unsubscribe('http.client.response.finish', onHttpClientResponseFinish);
|
|
111
|
+
diagnosticsChannel.unsubscribe('http.client.request.error', onHttpClientRequestError);
|
|
112
|
+
},
|
|
113
|
+
),
|
|
114
|
+
];
|
|
59
115
|
}
|
|
60
116
|
|
|
61
|
-
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
117
|
+
/**
|
|
118
|
+
* This is triggered when an outgoing request finishes.
|
|
119
|
+
* It has access to the final request and response objects.
|
|
120
|
+
*/
|
|
121
|
+
_onOutgoingRequestFinish(request, response) {
|
|
122
|
+
debugBuild.DEBUG_BUILD && core$1.logger.log(INSTRUMENTATION_NAME, 'Handling finished outgoing request');
|
|
123
|
+
|
|
124
|
+
const _breadcrumbs = this.getConfig().breadcrumbs;
|
|
125
|
+
const breadCrumbsEnabled = typeof _breadcrumbs === 'undefined' ? true : _breadcrumbs;
|
|
126
|
+
const options = getRequestOptions(request);
|
|
69
127
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
128
|
+
const _ignoreOutgoingRequests = this.getConfig().ignoreOutgoingRequests;
|
|
129
|
+
const shouldCreateBreadcrumb =
|
|
130
|
+
typeof _ignoreOutgoingRequests === 'function' ? !_ignoreOutgoingRequests(getRequestUrl.getRequestUrl(request), options) : true;
|
|
73
131
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
// no unwrap here
|
|
78
|
-
},
|
|
79
|
-
);
|
|
132
|
+
if (breadCrumbsEnabled && shouldCreateBreadcrumb) {
|
|
133
|
+
addRequestBreadcrumb(request, response);
|
|
134
|
+
}
|
|
80
135
|
}
|
|
81
136
|
|
|
82
137
|
/**
|
|
83
|
-
* Patch
|
|
138
|
+
* Patch a server.emit function to handle process isolation for incoming requests.
|
|
139
|
+
* This will only patch the emit function if it was not already patched.
|
|
84
140
|
*/
|
|
85
|
-
|
|
141
|
+
_patchServerEmitOnce(server) {
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
143
|
+
const originalEmit = server.emit;
|
|
144
|
+
|
|
145
|
+
// This means it was already patched, do nothing
|
|
146
|
+
if ((originalEmit ).__sentry_patched__) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
debugBuild.DEBUG_BUILD && core$1.logger.log(INSTRUMENTATION_NAME, 'Patching server.emit');
|
|
86
151
|
|
|
87
|
-
{
|
|
88
152
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
89
153
|
const instrumentation = this;
|
|
90
154
|
const { ignoreIncomingRequestBody } = instrumentation.getConfig();
|
|
91
155
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
) => {
|
|
95
|
-
return function incomingRequest( ...args) {
|
|
156
|
+
const newEmit = new Proxy(originalEmit, {
|
|
157
|
+
apply(target, thisArg, args) {
|
|
96
158
|
// Only traces request events
|
|
97
159
|
if (args[0] !== 'request') {
|
|
98
|
-
return
|
|
160
|
+
return target.apply(thisArg, args);
|
|
99
161
|
}
|
|
100
162
|
|
|
101
|
-
|
|
163
|
+
debugBuild.DEBUG_BUILD && core$1.logger.log(INSTRUMENTATION_NAME, 'Handling incoming request');
|
|
102
164
|
|
|
103
165
|
const isolationScope = core$1.getIsolationScope().clone();
|
|
104
166
|
const request = args[1] ;
|
|
@@ -143,88 +205,20 @@ class SentryHttpInstrumentation extends instrumentation.InstrumentationBase {
|
|
|
143
205
|
|
|
144
206
|
// If we don't want to extract the trace from the header, we can skip this
|
|
145
207
|
if (!instrumentation.getConfig().extractIncomingTraceFromHeader) {
|
|
146
|
-
return
|
|
208
|
+
return target.apply(thisArg, args);
|
|
147
209
|
}
|
|
148
210
|
|
|
149
211
|
const ctx = api.propagation.extract(api.context.active(), normalizedRequest.headers);
|
|
150
212
|
return api.context.with(ctx, () => {
|
|
151
|
-
return
|
|
213
|
+
return target.apply(thisArg, args);
|
|
152
214
|
});
|
|
153
215
|
});
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Patch the outgoing request function for breadcrumbs.
|
|
160
|
-
*/
|
|
161
|
-
_getPatchOutgoingRequestFunction()
|
|
162
|
-
|
|
163
|
-
{
|
|
164
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
165
|
-
const instrumentation = this;
|
|
166
|
-
|
|
167
|
-
return (original) => {
|
|
168
|
-
return function outgoingRequest( ...args) {
|
|
169
|
-
instrumentation._diag.debug('http instrumentation for outgoing requests');
|
|
170
|
-
|
|
171
|
-
// Making a copy to avoid mutating the original args array
|
|
172
|
-
// We need to access and reconstruct the request options object passed to `ignoreOutgoingRequests`
|
|
173
|
-
// so that it matches what Otel instrumentation passes to `ignoreOutgoingRequestHook`.
|
|
174
|
-
// @see https://github.com/open-telemetry/opentelemetry-js/blob/7293e69c1e55ca62e15d0724d22605e61bd58952/experimental/packages/opentelemetry-instrumentation-http/src/http.ts#L756-L789
|
|
175
|
-
const argsCopy = [...args];
|
|
176
|
-
|
|
177
|
-
const options = argsCopy.shift() ;
|
|
178
|
-
|
|
179
|
-
const extraOptions =
|
|
180
|
-
typeof argsCopy[0] === 'object' && (typeof options === 'string' || options instanceof URL)
|
|
181
|
-
? (argsCopy.shift() )
|
|
182
|
-
: undefined;
|
|
183
|
-
|
|
184
|
-
const { optionsParsed } = getRequestInfo.getRequestInfo(instrumentation._diag, options, extraOptions);
|
|
185
|
-
|
|
186
|
-
const request = original.apply(this, args) ;
|
|
187
|
-
|
|
188
|
-
request.prependListener('response', (response) => {
|
|
189
|
-
const _breadcrumbs = instrumentation.getConfig().breadcrumbs;
|
|
190
|
-
const breadCrumbsEnabled = typeof _breadcrumbs === 'undefined' ? true : _breadcrumbs;
|
|
191
|
-
|
|
192
|
-
const _ignoreOutgoingRequests = instrumentation.getConfig().ignoreOutgoingRequests;
|
|
193
|
-
const shouldCreateBreadcrumb =
|
|
194
|
-
typeof _ignoreOutgoingRequests === 'function'
|
|
195
|
-
? !_ignoreOutgoingRequests(getRequestUrl.getRequestUrl(request), optionsParsed)
|
|
196
|
-
: true;
|
|
197
|
-
|
|
198
|
-
if (breadCrumbsEnabled && shouldCreateBreadcrumb) {
|
|
199
|
-
addRequestBreadcrumb(request, response);
|
|
200
|
-
}
|
|
201
|
-
});
|
|
216
|
+
},
|
|
217
|
+
});
|
|
202
218
|
|
|
203
|
-
|
|
204
|
-
};
|
|
205
|
-
};
|
|
206
|
-
}
|
|
219
|
+
core$1.addNonEnumerableProperty(newEmit, '__sentry_patched__', true);
|
|
207
220
|
|
|
208
|
-
|
|
209
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
210
|
-
_getPatchOutgoingGetFunction(clientRequest) {
|
|
211
|
-
return (_original) => {
|
|
212
|
-
// Re-implement http.get. This needs to be done (instead of using
|
|
213
|
-
// getPatchOutgoingRequestFunction to patch it) because we need to
|
|
214
|
-
// set the trace context header before the returned http.ClientRequest is
|
|
215
|
-
// ended. The Node.js docs state that the only differences between
|
|
216
|
-
// request and get are that (1) get defaults to the HTTP GET method and
|
|
217
|
-
// (2) the returned request object is ended immediately. The former is
|
|
218
|
-
// already true (at least in supported Node versions up to v10), so we
|
|
219
|
-
// simply follow the latter. Ref:
|
|
220
|
-
// https://nodejs.org/dist/latest/docs/api/http.html#http_http_get_options_callback
|
|
221
|
-
// https://github.com/googleapis/cloud-trace-nodejs/blob/master/src/instrumentations/instrumentation-http.ts#L198
|
|
222
|
-
return function outgoingGetRequest(...args) {
|
|
223
|
-
const req = clientRequest(...args);
|
|
224
|
-
req.end();
|
|
225
|
-
return req;
|
|
226
|
-
};
|
|
227
|
-
};
|
|
221
|
+
server.emit = newEmit;
|
|
228
222
|
}
|
|
229
223
|
}
|
|
230
224
|
|
|
@@ -232,7 +226,7 @@ class SentryHttpInstrumentation extends instrumentation.InstrumentationBase {
|
|
|
232
226
|
function addRequestBreadcrumb(request, response) {
|
|
233
227
|
const data = getBreadcrumbData(request);
|
|
234
228
|
|
|
235
|
-
const statusCode = response
|
|
229
|
+
const statusCode = response?.statusCode;
|
|
236
230
|
const level = core$1.getBreadcrumbLogLevelFromHttpStatusCode(statusCode);
|
|
237
231
|
|
|
238
232
|
core$1.addBreadcrumb(
|
|
@@ -288,6 +282,8 @@ function patchRequestToCaptureBody(req, isolationScope) {
|
|
|
288
282
|
let bodyByteLength = 0;
|
|
289
283
|
const chunks = [];
|
|
290
284
|
|
|
285
|
+
debugBuild.DEBUG_BUILD && core$1.logger.log(INSTRUMENTATION_NAME, 'Patching request.on');
|
|
286
|
+
|
|
291
287
|
/**
|
|
292
288
|
* We need to keep track of the original callbacks, in order to be able to remove listeners again.
|
|
293
289
|
* Since `off` depends on having the exact same function reference passed in, we need to be able to map
|
|
@@ -301,11 +297,8 @@ function patchRequestToCaptureBody(req, isolationScope) {
|
|
|
301
297
|
apply: (target, thisArg, args) => {
|
|
302
298
|
const [event, listener, ...restArgs] = args;
|
|
303
299
|
|
|
304
|
-
if (debugBuild.DEBUG_BUILD) {
|
|
305
|
-
core$1.logger.log(INSTRUMENTATION_NAME, 'Patching request.on', event);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
300
|
if (event === 'data') {
|
|
301
|
+
debugBuild.DEBUG_BUILD && core$1.logger.log(INSTRUMENTATION_NAME, 'Handling request.on("data")');
|
|
309
302
|
const callback = new Proxy(listener, {
|
|
310
303
|
apply: (target, thisArg, args) => {
|
|
311
304
|
try {
|
|
@@ -376,6 +369,17 @@ function patchRequestToCaptureBody(req, isolationScope) {
|
|
|
376
369
|
}
|
|
377
370
|
}
|
|
378
371
|
|
|
372
|
+
function getRequestOptions(request) {
|
|
373
|
+
return {
|
|
374
|
+
method: request.method,
|
|
375
|
+
protocol: request.protocol,
|
|
376
|
+
host: request.host,
|
|
377
|
+
hostname: request.host,
|
|
378
|
+
path: request.path,
|
|
379
|
+
headers: request.getHeaders(),
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
|
|
379
383
|
/**
|
|
380
384
|
* Starts a session and tracks it in the context of a given isolation scope.
|
|
381
385
|
* When the passed response is finished, the session is put into a task and is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SentryHttpInstrumentation.js","sources":["../../../../src/integrations/http/SentryHttpInstrumentation.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport 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';\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 generateSpanId,\n getBreadcrumbLogLevelFromHttpStatusCode,\n getClient,\n getCurrentScope,\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 { getRequestUrl } from '../../utils/getRequestUrl';\nimport { stealthWrap } from './utils';\nimport { getRequestInfo } from './vendor/getRequestInfo';\n\ntype Http = typeof http;\ntype Https = typeof https;\n\nconst INSTRUMENTATION_NAME = '@sentry/instrumentation-http';\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 * 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 * 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: 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 public constructor(config: SentryHttpInstrumentationOptions = {}) {\n super(INSTRUMENTATION_NAME, 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 const { ignoreIncomingRequestBody } = instrumentation.getConfig();\n\n return (\n original: (event: string, ...args: unknown[]) => boolean,\n ): ((this: unknown, event: string, ...args: unknown[]) => boolean) => {\n return function incomingRequest(this: unknown, ...args: [event: string, ...args: unknown[]]): boolean {\n // Only traces request events\n if (args[0] !== 'request') {\n return original.apply(this, args);\n }\n\n instrumentation._diag.debug('http instrumentation for 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)) {\n patchRequestToCaptureBody(request, isolationScope);\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 original.apply(this, args);\n }\n\n const ctx = propagation.extract(context.active(), normalizedRequest.headers);\n return context.with(ctx, () => {\n return original.apply(this, 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 // 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/** 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 let bodyByteLength = 0;\n const chunks: Buffer[] = [];\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 (DEBUG_BUILD) {\n logger.log(INSTRUMENTATION_NAME, 'Patching request.on', event);\n }\n\n if (event === 'data') {\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 < MAX_BODY_BYTE_LENGTH) {\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 ${MAX_BODY_BYTE_LENGTH}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 isolationScope.setSDKProcessingMetadata({ normalizedRequest: { data: body } });\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\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":["InstrumentationBase","VERSION","InstrumentationNodeModuleDefinition","stealthWrap","getIsolationScope","httpRequestToRequestData","stripUrlQueryAndFragment","withIsolationScope","getCurrentScope","generateSpanId","propagation","context","getRequestInfo","getRequestUrl","getBreadcrumbLogLevelFromHttpStatusCode","addBreadcrumb","parseUrl","getSanitizedUrlString","DEBUG_BUILD","logger","getClient"],"mappings":";;;;;;;;;;;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,kBAAA,CAAA;;AAEA,QAAA,MAAA,4BAAA,GAAA,MAAA;AACA,UAAA,YAAA,CAAA,OAAA,CAAA;AACA,UAAA,yBAAA,EAAA;AACA,UAAA,mCAAA,CAAA,MAAA,CAAA,MAAA,CAAA;;AAEA,UAAA,MAAA,gBAAA,GAAA,MAAA,CAAA,OAAA,CAAA,kBAAA,CAAA,CAAA,GAAA;AACA,YAAA,CAAA,CAAA,SAAA,EAAA,KAAA,CAAA,MAAA;AACA,cAAA,OAAA,EAAA,SAAA;AACA,cAAA,MAAA,EAAA,KAAA,CAAA,MAAA;AACA,cAAA,OAAA,EAAA,KAAA,CAAA,OAAA;AACA,cAAA,OAAA,EAAA,KAAA,CAAA,OAAA;AACA,aAAA,CAAA;AACA,WAAA;AACA,UAAA,MAAA,CAAA,WAAA,CAAA,EAAA,UAAA,EAAA,gBAAA,EAAA,CAAA;AACA,SAAA;;AAEA,QAAA,MAAA,yBAAA,GAAA,MAAA,CAAA,EAAA,CAAA,OAAA,EAAA,MAAA;AACA,UAAAD,sBAAA,IAAAC,aAAA,CAAA,KAAA,CAAA,uDAAA,CAAA;AACA,UAAA,4BAAA,EAAA;AACA,SAAA,CAAA;AACA,QAAA,MAAA,OAAA,GAAA,UAAA,CAAA,MAAA;AACA,UAAAD,sBAAA,IAAAC,aAAA,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 { 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 httpRequestToRequestData,\n logger,\n parseUrl,\n stripUrlQueryAndFragment,\n withIsolationScope,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\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 * 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 * 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 public constructor(config: SentryHttpInstrumentationOptions = {}) {\n super(INSTRUMENTATION_NAME, VERSION, config);\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 /**\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 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 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 * 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 } = 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)) {\n patchRequestToCaptureBody(request, isolationScope);\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(req: http.IncomingMessage, isolationScope: Scope): 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 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 && logger.log(INSTRUMENTATION_NAME, 'Handling request.on(\"data\")');\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 < MAX_BODY_BYTE_LENGTH) {\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 ${MAX_BODY_BYTE_LENGTH}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 isolationScope.setSDKProcessingMetadata({ normalizedRequest: { data: body } });\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":["InstrumentationBase","VERSION","InstrumentationNodeModuleDefinition","subscribe","unsubscribe","DEBUG_BUILD","logger","getRequestUrl","getIsolationScope","httpRequestToRequestData","stripUrlQueryAndFragment","withIsolationScope","getCurrentScope","generateSpanId","propagation","context","addNonEnumerableProperty","getBreadcrumbLogLevelFromHttpStatusCode","addB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uDAAA,CAAA;AACA,UAAA,4BAAA,EAAA;AACA,SAAA,CAAA;AACA,QAAA,MAAA,OAAA,GAAA,UAAA,CAAA,MAAA;AACA,UAAAD,sBAAA,IAAAC,aAAA,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;;;;;"}
|
|
@@ -65,8 +65,7 @@ class SentryHttpInstrumentationBeforeOtel extends instrumentation.Instrumentatio
|
|
|
65
65
|
return original.apply(this, args);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
const response = args[
|
|
69
|
-
|
|
68
|
+
const response = args[2] ;
|
|
70
69
|
patchResponseToFlushOnServerlessPlatforms(response);
|
|
71
70
|
|
|
72
71
|
return original.apply(this, args);
|
|
@@ -78,51 +77,58 @@ class SentryHttpInstrumentationBeforeOtel extends instrumentation.Instrumentatio
|
|
|
78
77
|
function patchResponseToFlushOnServerlessPlatforms(res) {
|
|
79
78
|
// Freely extend this function with other platforms if necessary
|
|
80
79
|
if (process.env.VERCEL) {
|
|
80
|
+
debugBuild.DEBUG_BUILD && core$1.logger.log('Patching response to flush on Vercel');
|
|
81
|
+
|
|
81
82
|
// In some cases res.end does not seem to be defined leading to errors if passed to Proxy
|
|
82
83
|
// https://github.com/getsentry/sentry-javascript/issues/15759
|
|
83
|
-
if (typeof res.end
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
markOnEndDone = res;
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
res.on('close', () => {
|
|
90
|
-
markOnEndDone();
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
94
|
-
res.end = new Proxy(res.end, {
|
|
95
|
-
apply(target, thisArg, argArray) {
|
|
96
|
-
core$1.vercelWaitUntil(
|
|
97
|
-
new Promise(finishWaitUntil => {
|
|
98
|
-
// Define a timeout that unblocks the lambda just to be safe so we're not indefinitely keeping it alive, exploding server bills
|
|
99
|
-
const timeout = setTimeout(() => {
|
|
100
|
-
finishWaitUntil();
|
|
101
|
-
}, 2000);
|
|
102
|
-
|
|
103
|
-
onEndDonePromise
|
|
104
|
-
.then(() => {
|
|
105
|
-
debugBuild.DEBUG_BUILD && core$1.logger.log('Flushing events before Vercel Lambda freeze');
|
|
106
|
-
return core$1.flush(2000);
|
|
107
|
-
})
|
|
108
|
-
.then(
|
|
109
|
-
() => {
|
|
110
|
-
clearTimeout(timeout);
|
|
111
|
-
finishWaitUntil();
|
|
112
|
-
},
|
|
113
|
-
e => {
|
|
114
|
-
clearTimeout(timeout);
|
|
115
|
-
debugBuild.DEBUG_BUILD && core$1.logger.log('Error while flushing events for Vercel:\n', e);
|
|
116
|
-
finishWaitUntil();
|
|
117
|
-
},
|
|
118
|
-
);
|
|
119
|
-
}),
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
return target.apply(thisArg, argArray);
|
|
123
|
-
},
|
|
124
|
-
});
|
|
84
|
+
if (typeof res.end !== 'function') {
|
|
85
|
+
debugBuild.DEBUG_BUILD && core$1.logger.warn('res.end is not a function, skipping patch...');
|
|
86
|
+
return;
|
|
125
87
|
}
|
|
88
|
+
|
|
89
|
+
let markOnEndDone = () => undefined;
|
|
90
|
+
const onEndDonePromise = new Promise(res => {
|
|
91
|
+
markOnEndDone = res;
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
res.on('close', () => {
|
|
95
|
+
markOnEndDone();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
core$1.logger.log('Patching res.end()');
|
|
99
|
+
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
101
|
+
res.end = new Proxy(res.end, {
|
|
102
|
+
apply(target, thisArg, argArray) {
|
|
103
|
+
core$1.vercelWaitUntil(
|
|
104
|
+
new Promise(finishWaitUntil => {
|
|
105
|
+
// Define a timeout that unblocks the lambda just to be safe so we're not indefinitely keeping it alive, exploding server bills
|
|
106
|
+
const timeout = setTimeout(() => {
|
|
107
|
+
finishWaitUntil();
|
|
108
|
+
}, 2000);
|
|
109
|
+
|
|
110
|
+
onEndDonePromise
|
|
111
|
+
.then(() => {
|
|
112
|
+
debugBuild.DEBUG_BUILD && core$1.logger.log('Flushing events before Vercel Lambda freeze');
|
|
113
|
+
return core$1.flush(2000);
|
|
114
|
+
})
|
|
115
|
+
.then(
|
|
116
|
+
() => {
|
|
117
|
+
clearTimeout(timeout);
|
|
118
|
+
finishWaitUntil();
|
|
119
|
+
},
|
|
120
|
+
e => {
|
|
121
|
+
clearTimeout(timeout);
|
|
122
|
+
debugBuild.DEBUG_BUILD && core$1.logger.log('Error while flushing events for Vercel:\n', e);
|
|
123
|
+
finishWaitUntil();
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
}),
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
return target.apply(thisArg, argArray);
|
|
130
|
+
},
|
|
131
|
+
});
|
|
126
132
|
}
|
|
127
133
|
}
|
|
128
134
|
|