Skip to content

Commit 2972c53

Browse files
authored
fix(otel): Set root transaction name to be route (#6334)
1 parent 1ae2726 commit 2972c53

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/opentelemetry-node/src/utils/parse-otel-span-description.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ function descriptionForHttpMethod(otelSpan: OtelSpan, httpMethod: AttributeValue
9898

9999
// Ex. description="GET /api/users".
100100
const description = `${httpMethod} ${httpPath}`;
101-
const source: TransactionSource = httpRoute ? 'route' : 'url';
101+
102+
// If `httpPath` is a root path, then we can categorize the transaction source as route.
103+
const source: TransactionSource = httpRoute || httpPath === '/' ? 'route' : 'url';
102104

103105
return { op: opParts.join('.'), description, source };
104106
}

packages/opentelemetry-node/test/spanprocessor.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,21 @@ describe('SentrySpanProcessor', () => {
458458
});
459459
});
460460

461+
it('adds transaction source `route` for root path HTTP_TARGET', async () => {
462+
const tracer = provider.getTracer('default');
463+
464+
tracer.startActiveSpan('GET /', otelSpan => {
465+
const sentrySpan = getSpanForOtelSpan(otelSpan);
466+
467+
otelSpan.setAttribute(SemanticAttributes.HTTP_METHOD, 'GET');
468+
otelSpan.setAttribute(SemanticAttributes.HTTP_TARGET, '/');
469+
470+
otelSpan.end();
471+
472+
expect(sentrySpan?.transaction?.metadata.source).toBe('route');
473+
});
474+
});
475+
461476
it('adds transaction source `url` for HTTP_ROUTE', async () => {
462477
const tracer = provider.getTracer('default');
463478

0 commit comments

Comments
 (0)