Skip to content

Commit f0d206c

Browse files
committed
set url source
1 parent 5615968 commit f0d206c

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

packages/core/src/tracing/spans/captureSpan.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ function inferHttpSpanData(
248248
if (typeof httpRoute === 'string') {
249249
spanJSON.name = `${httpMethod} ${httpRoute}`;
250250
safeSetSpanJSONAttributes(spanJSON, { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route' });
251+
} else {
252+
// Fallback: set source to 'url' for HTTP spans without a route.
253+
// The spec requires sentry.span.source on segment spans, and the non-streamed exporter
254+
// always sets this — so we need to ensure it's present for streamed spans too.
255+
safeSetSpanJSONAttributes(spanJSON, { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url' });
251256
}
252257
}
253258

packages/core/test/lib/tracing/spans/captureSpan.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,11 @@ describe('inferSpanDataFromOtelAttributes', () => {
530530
expect(spanJSON.attributes?.['sentry.source']).toBe('route');
531531
});
532532

533-
it('does not overwrite name when no http.route', () => {
533+
it('does not overwrite name when no http.route but sets source to url', () => {
534534
const spanJSON = makeSpanJSON('GET', { 'http.request.method': 'GET', 'url.full': 'http://example.com/api' });
535535
inferSpanDataFromOtelAttributes(spanJSON, 2);
536536
expect(spanJSON.name).toBe('GET');
537+
expect(spanJSON.attributes?.['sentry.source']).toBe('url');
537538
});
538539

539540
it('does not overwrite sentry.op if already set', () => {

0 commit comments

Comments
 (0)