Skip to content

Commit 379a9e5

Browse files
authored
fix(node): Ensure DSC is correctly set in envelope headers (#11628)
This was not correctly set before when we had an active span - the `error-active-span` & `error-active-span-unsampled` scenarios failed before and had no `trace` set on the envelope headers. The fix was to actually fix our `setupEventContextTrace` utility for OTEL, where we now just set the dsc on the event sdkProcessingMetadata, which is picked up when event processing. I also moved this to `preprocessEvent` to ensure this runs before other stuff. This should fix https://github.com/getsentry/sentry-javascript-examples/pull/7/files#r1561220216 which @s1gr1d found in her example app. 🚀
1 parent d5ac938 commit 379a9e5

File tree

14 files changed

+289
-6
lines changed

14 files changed

+289
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
2+
import * as Sentry from '@sentry/node';
3+
4+
Sentry.init({
5+
dsn: 'https://[email protected]/1337',
6+
release: '1.0',
7+
tracePropagationTargets: [/\/v0/, 'v1'],
8+
tracesSampleRate: 0,
9+
integrations: [],
10+
transport: loggingTransport,
11+
});
12+
13+
Sentry.startSpan({ name: 'test span' }, () => {
14+
Sentry.captureException(new Error('foo'));
15+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { createRunner } from '../../../../utils/runner';
2+
3+
test('envelope header for error event during active unsampled span is correct', done => {
4+
createRunner(__dirname, 'scenario.ts')
5+
.ignore('session', 'sessions', 'transaction')
6+
.expectHeader({
7+
event: {
8+
trace: {
9+
trace_id: expect.any(String),
10+
public_key: 'public',
11+
environment: 'production',
12+
release: '1.0',
13+
sampled: 'false',
14+
},
15+
},
16+
})
17+
.start(done);
18+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
2+
import * as Sentry from '@sentry/node';
3+
4+
Sentry.init({
5+
dsn: 'https://[email protected]/1337',
6+
release: '1.0',
7+
tracePropagationTargets: [/\/v0/, 'v1'],
8+
tracesSampleRate: 1,
9+
integrations: [],
10+
transport: loggingTransport,
11+
});
12+
13+
Sentry.startSpan({ name: 'test span' }, () => {
14+
Sentry.captureException(new Error('foo'));
15+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { createRunner } from '../../../../utils/runner';
2+
3+
test('envelope header for error event during active span is correct', done => {
4+
createRunner(__dirname, 'scenario.ts')
5+
.ignore('session', 'sessions', 'transaction')
6+
.expectHeader({
7+
event: {
8+
trace: {
9+
trace_id: expect.any(String),
10+
public_key: 'public',
11+
environment: 'production',
12+
release: '1.0',
13+
sample_rate: '1',
14+
sampled: 'true',
15+
transaction: 'test span',
16+
},
17+
},
18+
})
19+
.start(done);
20+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
2+
import * as Sentry from '@sentry/node';
3+
4+
Sentry.init({
5+
dsn: 'https://[email protected]/1337',
6+
release: '1.0',
7+
tracePropagationTargets: [/\/v0/, 'v1'],
8+
tracesSampleRate: 0,
9+
integrations: [],
10+
transport: loggingTransport,
11+
});
12+
13+
Sentry.captureException(new Error('foo'));
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { createRunner } from '../../../../utils/runner';
2+
3+
test('envelope header for error events is correct', done => {
4+
createRunner(__dirname, 'scenario.ts')
5+
.ignore('session', 'sessions')
6+
.expectHeader({
7+
event: {
8+
trace: {
9+
trace_id: expect.any(String),
10+
environment: 'production',
11+
public_key: 'public',
12+
release: '1.0',
13+
},
14+
},
15+
})
16+
.start(done);
17+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
2+
import * as Sentry from '@sentry/node';
3+
4+
Sentry.init({
5+
dsn: 'https://[email protected]/1337',
6+
release: '1.0',
7+
tracePropagationTargets: [/\/v0/, 'v1'],
8+
tracesSampleRate: 1,
9+
integrations: [],
10+
transport: loggingTransport,
11+
});
12+
13+
Sentry.startSpan(
14+
{
15+
name: 'GET /route',
16+
attributes: {
17+
'http.method': 'GET',
18+
'http.route': '/route',
19+
[Sentry.SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.server',
20+
[Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
21+
},
22+
},
23+
() => {
24+
// noop
25+
},
26+
);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { createRunner } from '../../../../utils/runner';
2+
3+
test('envelope header for transaction event of route correct', done => {
4+
createRunner(__dirname, 'scenario.ts')
5+
.ignore('session', 'sessions')
6+
.expectHeader({
7+
transaction: {
8+
trace: {
9+
trace_id: expect.any(String),
10+
public_key: 'public',
11+
transaction: 'GET /route',
12+
environment: 'production',
13+
release: '1.0',
14+
sample_rate: '1',
15+
sampled: 'true',
16+
},
17+
},
18+
})
19+
.start(done);
20+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
2+
import * as Sentry from '@sentry/node';
3+
4+
Sentry.init({
5+
dsn: 'https://[email protected]/1337',
6+
release: '1.0',
7+
tracePropagationTargets: [/\/v0/, 'v1'],
8+
tracesSampleRate: 1,
9+
integrations: [],
10+
transport: loggingTransport,
11+
});
12+
13+
Sentry.startSpan(
14+
{
15+
name: 'GET /route/1',
16+
attributes: {
17+
'http.method': 'GET',
18+
'http.route': '/route',
19+
[Sentry.SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.server',
20+
[Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
21+
},
22+
},
23+
() => {
24+
// noop
25+
},
26+
);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { createRunner } from '../../../../utils/runner';
2+
3+
test('envelope header for transaction event with source=url correct', done => {
4+
createRunner(__dirname, 'scenario.ts')
5+
.ignore('session', 'sessions')
6+
.expectHeader({
7+
transaction: {
8+
trace: {
9+
trace_id: expect.any(String),
10+
public_key: 'public',
11+
environment: 'production',
12+
release: '1.0',
13+
sample_rate: '1',
14+
sampled: 'true',
15+
},
16+
},
17+
})
18+
.start(done);
19+
});

0 commit comments

Comments
 (0)