Skip to content

Commit

Permalink
feat(core): Add server.address to browser http.client spans
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Apr 16, 2024
1 parent f1c4611 commit 5642fad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/browser/src/tracing/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
addXhrInstrumentationHandler,
} from '@sentry-internal/browser-utils';
import {
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SentryNonRecordingSpan,
getActiveSpan,
Expand All @@ -26,6 +27,7 @@ import {
browserPerformanceTimeOrigin,
dynamicSamplingContextToSentryBaggageHeader,
generateSentryTraceHeader,
parseUrl,
stringMatchesSomePattern,
} from '@sentry/utils';
import { WINDOW } from '../helpers';
Expand Down Expand Up @@ -310,6 +312,8 @@ export function xhrCallback(

const hasParent = !!getActiveSpan();

const parsedUrl = parseUrl(sentryXhrData.url);

const span =
shouldCreateSpanResult && hasParent
? startInactiveSpan({
Expand All @@ -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();

Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -83,6 +84,8 @@ export function instrumentFetchRequest(

const hasParent = !!getActiveSpan();

const parsedUrl = parseUrl(url);

const span =
shouldCreateSpanResult && hasParent
? startInactiveSpan({
Expand All @@ -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();

Expand Down

0 comments on commit 5642fad

Please sign in to comment.