Skip to content

fix(otel): Set root transaction name to be route #6334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ function descriptionForHttpMethod(otelSpan: OtelSpan, httpMethod: AttributeValue

// Ex. description="GET /api/users".
const description = `${httpMethod} ${httpPath}`;
const source: TransactionSource = httpRoute ? 'route' : 'url';

// If `httpPath` is a root path, then we can categorize the transaction source as route.
const source: TransactionSource = httpRoute || httpPath === '/' ? 'route' : 'url';

return { op: opParts.join('.'), description, source };
}
15 changes: 15 additions & 0 deletions packages/opentelemetry-node/test/spanprocessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,21 @@ describe('SentrySpanProcessor', () => {
});
});

it('adds transaction source `route` for root path HTTP_TARGET', async () => {
const tracer = provider.getTracer('default');

tracer.startActiveSpan('GET /', otelSpan => {
const sentrySpan = getSpanForOtelSpan(otelSpan);

otelSpan.setAttribute(SemanticAttributes.HTTP_METHOD, 'GET');
otelSpan.setAttribute(SemanticAttributes.HTTP_TARGET, '/');

otelSpan.end();

expect(sentrySpan?.transaction?.metadata.source).toBe('route');
});
});

it('adds transaction source `url` for HTTP_ROUTE', async () => {
const tracer = provider.getTracer('default');

Expand Down