Skip to content

Commit c594d6a

Browse files
authored
fix(node): Set transactionName for unsampled spans in httpIntegration (#12071)
We noticed that in http integration, we were only setting `transactionName` when we had a sampled span. We can actually set this based on the request object we get either way, making this more robust for error-only mode.
1 parent 4003f7e commit c594d6a

File tree

4 files changed

+6
-15
lines changed
  • dev-packages
  • packages/node/src/integrations

4 files changed

+6
-15
lines changed

dev-packages/e2e-tests/test-applications/node-express-esm-without-loader/tests/server.test.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ test('Isolates requests', async ({ request }) => {
2929
expect(errorEvent1.tags).toEqual({ 'param-1': 'yes' });
3030
expect(errorEvent2.tags).toEqual({ 'param-2': 'yes' });
3131

32-
// Transaction is not set, since we have no expressIntegration by default
33-
expect(errorEvent1.transaction).toBeUndefined();
34-
expect(errorEvent2.transaction).toBeUndefined();
32+
expect(errorEvent1.transaction).toBe('GET /test-params/1');
33+
expect(errorEvent2.transaction).toBe('GET /test-params/2');
3534
});

dev-packages/node-integration-tests/suites/express/without-tracing/server.ts

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ app.get('/test/isolationScope/:id', (req, res) => {
1818
const id = req.params.id;
1919
Sentry.setTag('isolation-scope', 'tag');
2020
Sentry.setTag(`isolation-scope-${id}`, id);
21-
Sentry.setTag('isolation-scope-transactionName', `${Sentry.getIsolationScope().getScopeData().transactionName}`);
2221

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

dev-packages/node-integration-tests/suites/express/without-tracing/test.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ test('correctly applies isolation scope even without tracing', done => {
99
.ignore('session', 'sessions')
1010
.expect({
1111
event: {
12+
transaction: 'GET /test/isolationScope/1',
1213
tags: {
1314
global: 'tag',
1415
'isolation-scope': 'tag',
1516
'isolation-scope-1': '1',
16-
// We can't properly test non-existance of fields here, so we cast this to a string to test it here
17-
'isolation-scope-transactionName': 'undefined',
1817
},
1918
// Request is correctly set
2019
request: {
@@ -27,12 +26,11 @@ test('correctly applies isolation scope even without tracing', done => {
2726
})
2827
.expect({
2928
event: {
29+
transaction: 'GET /test/isolationScope/2',
3030
tags: {
3131
global: 'tag',
3232
'isolation-scope': 'tag',
3333
'isolation-scope-2': '2',
34-
// We can't properly test non-existance of fields here, so we cast this to a string to test it here
35-
'isolation-scope-transactionName': 'undefined',
3634
},
3735
// Request is correctly set
3836
request: {

packages/node/src/integrations/http.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
getIsolationScope,
1313
isSentryRequestUrl,
1414
setCapturedScopesOnSpan,
15-
spanToJSON,
1615
} from '@sentry/core';
1716
import { getClient, getRequestSpanData, getSpanKind } from '@sentry/opentelemetry';
1817
import type { IntegrationFn } from '@sentry/types';
@@ -121,13 +120,9 @@ const _httpIntegration = ((options: HttpOptions = {}) => {
121120
// attempt to update the scope's `transactionName` based on the request URL
122121
// Ideally, framework instrumentations coming after the HttpInstrumentation
123122
// update the transactionName once we get a parameterized route.
124-
const attributes = spanToJSON(span).data;
125-
if (!attributes) {
126-
return;
127-
}
123+
const httpMethod = (req.method || 'GET').toUpperCase();
124+
const httpTarget = stripUrlQueryAndFragment(req.url || '/');
128125

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

133128
isolationScope.setTransactionName(bestEffortTransactionName);

0 commit comments

Comments
 (0)