Skip to content

Commit 5a488c6

Browse files
committed
fixup! fixup! feat(http): portable node:http client instrumentation (#20393)
1 parent e04cd55 commit 5a488c6

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { context, trace } from '@opentelemetry/api';
44
import { isTracingSuppressed } from '@opentelemetry/core';
55
import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
66
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
7+
import type { ClientRequest, IncomingMessage, ServerResponse } from 'node:http';
78
import type {
89
HttpClientRequest,
910
HttpIncomingMessage,
@@ -16,6 +17,7 @@ import { INSTRUMENTATION_NAME } from './constants';
1617
import { HTTP_ON_CLIENT_REQUEST } from '@sentry/core';
1718
import { NODE_VERSION } from '../../nodeVersion';
1819
import { errorMonitor } from 'node:events';
20+
import { getRequestOptions } from '../../utils/outgoingHttpRequest';
1921

2022
const FULLY_SUPPORTS_HTTP_DIAGNOSTICS_CHANNEL =
2123
(NODE_VERSION.major === 22 && NODE_VERSION.minor >= 12) ||
@@ -74,8 +76,8 @@ export type SentryHttpInstrumentationOptions = InstrumentationConfig & {
7476
* Hooks for outgoing request spans, called when `createSpansForOutgoingRequests` is enabled.
7577
* These mirror the OTEL HttpInstrumentation hooks for backwards compatibility.
7678
*/
77-
outgoingRequestHook?: (span: Span, request: http.ClientRequest | HttpClientRequest) => void;
78-
outgoingResponseHook?: (span: Span, response: http.IncomingMessage | HttpIncomingMessage) => void;
79+
outgoingRequestHook?: (span: Span, request: ClientRequest | HttpClientRequest) => void;
80+
outgoingResponseHook?: (span: Span, response: IncomingMessage | HttpIncomingMessage) => void;
7981
outgoingRequestApplyCustomAttributes?: (
8082
span: Span,
8183
request: HttpClientRequest,
@@ -103,7 +105,7 @@ export type SentryHttpInstrumentationOptions = InstrumentationConfig & {
103105
/**
104106
* @deprecated This no longer does anything.
105107
*/
106-
ignoreSpansForIncomingRequests?: (urlPath: string, request: http.IncomingMessage) => boolean;
108+
ignoreSpansForIncomingRequests?: (urlPath: string, request: IncomingMessage) => boolean;
107109

108110
/**
109111
* @deprecated This no longer does anything.
@@ -124,12 +126,12 @@ export type SentryHttpInstrumentationOptions = InstrumentationConfig & {
124126
* @deprecated This no longer does anything.
125127
*/
126128
instrumentation?: {
127-
requestHook?: (span: Span, req: http.ClientRequest | http.IncomingMessage) => void;
128-
responseHook?: (span: Span, response: http.IncomingMessage | http.ServerResponse) => void;
129+
requestHook?: (span: Span, req: ClientRequest | IncomingMessage) => void;
130+
responseHook?: (span: Span, response: IncomingMessage | ServerResponse) => void;
129131
applyCustomAttributesOnSpan?: (
130132
span: Span,
131-
request: http.ClientRequest | http.IncomingMessage,
132-
response: http.IncomingMessage | http.ServerResponse,
133+
request: ClientRequest | IncomingMessage,
134+
response: IncomingMessage | ServerResponse,
133135
) => void;
134136
};
135137

@@ -169,7 +171,7 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
169171
...options,
170172
spans: options.createSpansForOutgoingRequests ?? options.spans,
171173
ignoreOutgoingRequests(url, request) {
172-
return isTracingSuppressed(context.active()) || !!options.ignoreOutgoingRequests?.(url, request);
174+
return isTracingSuppressed(context.active()) || !!options.ignoreOutgoingRequests?.(url, getRequestOptions(request as ClientRequest));
173175
},
174176
outgoingRequestHook(span, request) {
175177
options.outgoingRequestHook?.(span, request);

0 commit comments

Comments
 (0)