Skip to content

Commit dd77951

Browse files
authored
fix(spotlight): Use unpatched http.request (#10369)
To avoid capturing our own requests. See getsentry/spotlight#335
1 parent 3cc7057 commit dd77951

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

packages/node/src/integrations/spotlight.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ function connectToSpotlight(client: Client, options: Required<SpotlightConnectio
7171

7272
const serializedEnvelope = serializeEnvelope(envelope);
7373

74-
const req = http.request(
74+
const request = getNativeHttpRequest();
75+
const req = request(
7576
{
7677
method: 'POST',
7778
path: spotlightUrl.pathname,
@@ -110,3 +111,22 @@ function parseSidecarUrl(url: string): URL | undefined {
110111
return undefined;
111112
}
112113
}
114+
115+
type HttpRequestImpl = typeof http.request;
116+
type WrappedHttpRequest = HttpRequestImpl & { __sentry_original__: HttpRequestImpl };
117+
118+
/**
119+
* We want to get an unpatched http request implementation to avoid capturing our own calls.
120+
*/
121+
export function getNativeHttpRequest(): HttpRequestImpl {
122+
const { request } = http;
123+
if (isWrapped(request)) {
124+
return request.__sentry_original__;
125+
}
126+
127+
return request;
128+
}
129+
130+
function isWrapped(impl: HttpRequestImpl): impl is WrappedHttpRequest {
131+
return '__sentry_original__' in impl;
132+
}

0 commit comments

Comments
 (0)