From 959dc3d24efd44cba164f688757f20133e2096eb Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 11 Sep 2023 13:06:51 +0200 Subject: [PATCH] fix(node-experimental): Ignore outgoing Sentry requests --- packages/node-experimental/src/integrations/http.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/node-experimental/src/integrations/http.ts b/packages/node-experimental/src/integrations/http.ts index d6e6a825d8a1..a64fdca5eab8 100644 --- a/packages/node-experimental/src/integrations/http.ts +++ b/packages/node-experimental/src/integrations/http.ts @@ -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) => { @@ -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 { + const dsn = getCurrentHub().getClient()?.getDsn(); + return dsn && host ? host.includes(dsn.host) : false; +}