Skip to content

Commit 8fa9818

Browse files
committed
fixup! fixup! fixup! fixup! feat(http): portable node:http client instrumentation (#20393)
1 parent eb95b27 commit 8fa9818

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

packages/core/src/integrations/http/client-subscriptions.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,17 @@ export function getHttpClientSubscriptions(options: HttpInstrumentationOptions):
6767
if (!createSpans) {
6868
// Even without spans, set up a response listener for breadcrumbs.
6969
if (breadcrumbs) {
70+
const onRequestError = () => {
71+
addOutgoingRequestBreadcrumb(request, undefined);
72+
};
73+
request.on(errorMonitor, onRequestError);
7074
request.prependListener('response', response => {
75+
// no longer need this, got a response.
76+
request.removeListener(errorMonitor, onRequestError);
7177
if (request.listenerCount('response') <= 1) {
7278
response.resume();
7379
}
7480
response.on('end', () => addOutgoingRequestBreadcrumb(request, response));
75-
// TODO: should we include the response here, even though it errored?
7681
response.on(errorMonitor, () => addOutgoingRequestBreadcrumb(request, undefined));
7782
});
7883
}
@@ -113,6 +118,9 @@ export function getHttpClientSubscriptions(options: HttpInstrumentationOptions):
113118

114119
request.on(errorMonitor, error => {
115120
DEBUG_BUILD && debug.log(LOG_PREFIX, 'outgoingRequest on request error()', error);
121+
if (breadcrumbs) {
122+
addOutgoingRequestBreadcrumb(request, undefined);
123+
}
116124
endSpan({ code: SPAN_STATUS_ERROR });
117125
});
118126

packages/node-core/src/integrations/http/SentryHttpInstrumentation.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ import { errorMonitor } from 'node:events';
2020
import { getRequestOptions } from '../../utils/outgoingHttpRequest';
2121

2222
const FULLY_SUPPORTS_HTTP_DIAGNOSTICS_CHANNEL =
23-
(NODE_VERSION.major === 22 && NODE_VERSION.minor >= 12) ||
24-
(NODE_VERSION.major === 23 && NODE_VERSION.minor >= 2) ||
25-
NODE_VERSION.major >= 24;
23+
(NODE_VERSION.major === 18 && NODE_VERSION.minor >= 7) ||
24+
NODE_VERSION.major >= 20;
2625

2726
export type SentryHttpInstrumentationOptions = InstrumentationConfig & {
2827
/**

0 commit comments

Comments
 (0)