Skip to content

fix(node-experimental): Ignore outgoing Sentry requests #8994

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

Merged
merged 1 commit into from
Sep 11, 2023
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
13 changes: 13 additions & 0 deletions packages/node-experimental/src/integrations/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ export class Http implements Integration {
this._unload = registerInstrumentations({
instrumentations: [
new HttpInstrumentation({
ignoreOutgoingRequestHook: request => {
const host = request.host || request.hostname;
return isSentryHost(host);
},

requireParentforOutgoingSpans: true,
requireParentforIncomingSpans: false,
requestHook: (span, req) => {
Expand Down Expand Up @@ -210,3 +215,11 @@ function getHttpUrl(attributes: Attributes): string | undefined {
const url = attributes[SemanticAttributes.HTTP_URL];
return typeof url === 'string' ? url : undefined;
}

/**
* Checks whether given host points to Sentry server
*/
function isSentryHost(host: string | undefined): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have something like this in a few places. Maybe we can extract into a function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, will move it as a util to @sentry/core (can't be in utils as it needs access to getCurrentHub()!)

const dsn = getCurrentHub().getClient()?.getDsn();
return dsn && host ? host.includes(dsn.host) : false;
}