From e86eeac2bd0791af444546fcc93506b32af26e32 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Tue, 16 Apr 2024 16:49:13 +0200 Subject: [PATCH] feat(core): Add `server.address` to browser `http.client` spans --- packages/browser/src/tracing/request.ts | 7 ++++++- packages/core/src/fetch.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/browser/src/tracing/request.ts b/packages/browser/src/tracing/request.ts index 2c013fe27232..f85282b6a8a4 100644 --- a/packages/browser/src/tracing/request.ts +++ b/packages/browser/src/tracing/request.ts @@ -4,6 +4,7 @@ import { addXhrInstrumentationHandler, } from '@sentry-internal/browser-utils'; import { + SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SentryNonRecordingSpan, getActiveSpan, @@ -26,6 +27,7 @@ import { browserPerformanceTimeOrigin, dynamicSamplingContextToSentryBaggageHeader, generateSentryTraceHeader, + parseUrl, stringMatchesSomePattern, } from '@sentry/utils'; import { WINDOW } from '../helpers'; @@ -310,6 +312,8 @@ export function xhrCallback( const hasParent = !!getActiveSpan(); + const parsedUrl = parseUrl(sentryXhrData.url); + const span = shouldCreateSpanResult && hasParent ? startInactiveSpan({ @@ -318,9 +322,10 @@ export function xhrCallback( type: 'xhr', 'http.method': sentryXhrData.method, url: sentryXhrData.url, + 'server.address': parsedUrl.host, [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.browser', + [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.client', }, - op: 'http.client', }) : new SentryNonRecordingSpan(); diff --git a/packages/core/src/fetch.ts b/packages/core/src/fetch.ts index f9069b6b6efa..784a790c25fb 100644 --- a/packages/core/src/fetch.ts +++ b/packages/core/src/fetch.ts @@ -4,9 +4,10 @@ import { dynamicSamplingContextToSentryBaggageHeader, generateSentryTraceHeader, isInstanceOf, + parseUrl, } from '@sentry/utils'; import { getClient, getCurrentScope, getIsolationScope } from './currentScopes'; -import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from './semanticAttributes'; +import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from './semanticAttributes'; import { SPAN_STATUS_ERROR, getDynamicSamplingContextFromClient, @@ -83,6 +84,8 @@ export function instrumentFetchRequest( const hasParent = !!getActiveSpan(); + const parsedUrl = parseUrl(url); + const span = shouldCreateSpanResult && hasParent ? startInactiveSpan({ @@ -91,9 +94,10 @@ export function instrumentFetchRequest( url, type: 'fetch', 'http.method': method, + 'server.address': parsedUrl.host, [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: spanOrigin, + [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.client', }, - op: 'http.client', }) : new SentryNonRecordingSpan();