Skip to content
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

fix(node): Set transactionName for unsampled spans in httpIntegration #12071

Merged
merged 1 commit into from
May 16, 2024
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 @@ -29,7 +29,6 @@ test('Isolates requests', async ({ request }) => {
expect(errorEvent1.tags).toEqual({ 'param-1': 'yes' });
expect(errorEvent2.tags).toEqual({ 'param-2': 'yes' });

// Transaction is not set, since we have no expressIntegration by default
expect(errorEvent1.transaction).toBeUndefined();
expect(errorEvent2.transaction).toBeUndefined();
expect(errorEvent1.transaction).toBe('GET /test-params/1');
expect(errorEvent2.transaction).toBe('GET /test-params/2');
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ app.get('/test/isolationScope/:id', (req, res) => {
const id = req.params.id;
Sentry.setTag('isolation-scope', 'tag');
Sentry.setTag(`isolation-scope-${id}`, id);
Sentry.setTag('isolation-scope-transactionName', `${Sentry.getIsolationScope().getScopeData().transactionName}`);

Sentry.captureException(new Error('This is an exception'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ test('correctly applies isolation scope even without tracing', done => {
.ignore('session', 'sessions')
.expect({
event: {
transaction: 'GET /test/isolationScope/1',
tags: {
global: 'tag',
'isolation-scope': 'tag',
'isolation-scope-1': '1',
// We can't properly test non-existance of fields here, so we cast this to a string to test it here
'isolation-scope-transactionName': 'undefined',
},
// Request is correctly set
request: {
Expand All @@ -27,12 +26,11 @@ test('correctly applies isolation scope even without tracing', done => {
})
.expect({
event: {
transaction: 'GET /test/isolationScope/2',
tags: {
global: 'tag',
'isolation-scope': 'tag',
'isolation-scope-2': '2',
// We can't properly test non-existance of fields here, so we cast this to a string to test it here
'isolation-scope-transactionName': 'undefined',
},
// Request is correctly set
request: {
Expand Down
9 changes: 2 additions & 7 deletions packages/node/src/integrations/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
getIsolationScope,
isSentryRequestUrl,
setCapturedScopesOnSpan,
spanToJSON,
} from '@sentry/core';
import { getClient, getRequestSpanData, getSpanKind } from '@sentry/opentelemetry';
import type { IntegrationFn } from '@sentry/types';
Expand Down Expand Up @@ -121,13 +120,9 @@ const _httpIntegration = ((options: HttpOptions = {}) => {
// attempt to update the scope's `transactionName` based on the request URL
// Ideally, framework instrumentations coming after the HttpInstrumentation
// update the transactionName once we get a parameterized route.
const attributes = spanToJSON(span).data;
if (!attributes) {
return;
}
const httpMethod = (req.method || 'GET').toUpperCase();
const httpTarget = stripUrlQueryAndFragment(req.url || '/');

const httpMethod = String(attributes['http.method']).toUpperCase() || 'GET';
const httpTarget = stripUrlQueryAndFragment(String(attributes['http.target'])) || '/';
const bestEffortTransactionName = `${httpMethod} ${httpTarget}`;

isolationScope.setTransactionName(bestEffortTransactionName);
Expand Down
Loading