Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}