Skip to content

Commit

Permalink
fix(spotlight): Use unpatched http.request (#10369)
Browse files Browse the repository at this point in the history
To avoid capturing our own requests.

See getsentry/spotlight#335
  • Loading branch information
mydea committed Jan 26, 2024
1 parent 3cc7057 commit dd77951
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/node/src/integrations/spotlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ function connectToSpotlight(client: Client, options: Required<SpotlightConnectio

const serializedEnvelope = serializeEnvelope(envelope);

const req = http.request(
const request = getNativeHttpRequest();
const req = request(
{
method: 'POST',
path: spotlightUrl.pathname,
Expand Down Expand Up @@ -110,3 +111,22 @@ function parseSidecarUrl(url: string): URL | undefined {
return undefined;
}
}

type HttpRequestImpl = typeof http.request;
type WrappedHttpRequest = HttpRequestImpl & { __sentry_original__: HttpRequestImpl };

/**
* We want to get an unpatched http request implementation to avoid capturing our own calls.
*/
export function getNativeHttpRequest(): HttpRequestImpl {
const { request } = http;
if (isWrapped(request)) {
return request.__sentry_original__;
}

return request;
}

function isWrapped(impl: HttpRequestImpl): impl is WrappedHttpRequest {
return '__sentry_original__' in impl;
}

0 comments on commit dd77951

Please sign in to comment.