Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(spotlight): Use unpatched http.request #10369

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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