Skip to content

Commit 7aa618c

Browse files
committed
adjust tests for new paradigm
1 parent 95fb283 commit 7aa618c

8 files changed

Lines changed: 53 additions & 47 deletions

File tree

  • dev-packages/node-integration-tests/suites

dev-packages/node-integration-tests/suites/pino/scenario.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ Sentry.pinoIntegration.untrackLogger(ignoredLogger);
88

99
ignoredLogger.info('this will not be tracked');
1010

11-
Sentry.withIsolationScope(() => {
11+
// Each operation runs in its own trace, so logs emitted within them carry distinct trace ids.
12+
Sentry.startNewTrace(() => {
1213
Sentry.startSpan({ name: 'startup' }, () => {
1314
logger.info({ user: 'user-id', something: { more: 3, complex: 'nope' } }, 'hello world');
1415
});
1516
});
1617

1718
setTimeout(() => {
18-
Sentry.withIsolationScope(() => {
19+
Sentry.startNewTrace(() => {
1920
Sentry.startSpan({ name: 'later' }, () => {
2021
const child = logger.child({ module: 'authentication' });
2122
child.error(new Error('oh no'));

dev-packages/node-integration-tests/suites/public-api/bindScopeToEmitter/test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ test('bindScopeToEmitter preserves the active span for listeners firing in a dif
3434
expect(childBound?.parent_span_id).toBe(parentSpanId);
3535
expect(childBound?.trace_id).toBe(parentTraceId);
3636

37-
// The unbound emitter's listener ran without the parent active -> its own, separate trace.
37+
// The unbound emitter's listener ran without the parent active -> its own root transaction,
38+
// not nested under the parent span. It still shares the isolation scope's propagation context
39+
// trace, matching the core SDK behavior for root spans.
3840
expect(childUnbound?.spans).toEqual([]);
39-
expect(childUnbound?.contexts?.trace?.trace_id).not.toBe(parentTraceId);
41+
expect(childUnbound?.contexts?.trace?.parent_span_id).toBeUndefined();
4042
});

dev-packages/node-integration-tests/suites/public-api/startSpan/parallel-root-spans-streamed/test.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,24 @@ afterAll(() => {
66
});
77

88
test('sends manually started streamed parallel root spans in root context', async () => {
9-
expect.assertions(7);
9+
expect.assertions(6);
1010

1111
await createRunner(__dirname, 'scenario.ts')
12-
.expect({ span: { items: [{ name: 'test_span_1' }] } })
1312
.expect({
1413
span: spanContainer => {
1514
expect(spanContainer).toBeDefined();
16-
const traceId = spanContainer.items[0]!.trace_id;
17-
expect(traceId).toMatch(/^[0-9a-f]{32}$/);
1815

19-
// It ignores propagation context of the root context
20-
expect(traceId).not.toBe('12345678901234567890123456789012');
21-
expect(spanContainer.items[0]!.parent_span_id).toBeUndefined();
16+
const span1 = spanContainer.items.find(item => item.name === 'test_span_1');
17+
const span2 = spanContainer.items.find(item => item.name === 'test_span_2');
18+
expect(span1).toBeDefined();
19+
expect(span2).toBeDefined();
2220

23-
// Different trace ID than the first span
24-
const trace1Id = spanContainer.items[0]!.attributes.spanIdTraceId?.value;
25-
expect(trace1Id).toMatch(/^[0-9a-f]{32}$/);
21+
// Both root spans continue the scope's propagation context, matching the core SDK behavior.
22+
expect(span1!.trace_id).toBe('12345678901234567890123456789012');
23+
expect(span1!.parent_span_id).toBe('1234567890123456');
2624

27-
expect(trace1Id).not.toBe(traceId);
25+
// Same trace ID for both spans
26+
expect(span2!.trace_id).toBe(span1!.trace_id);
2827
},
2928
})
3029
.start()

dev-packages/node-integration-tests/suites/public-api/startSpan/parallel-root-spans/test.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@ afterAll(() => {
66
});
77

88
test('should send manually started parallel root spans in root context', async () => {
9-
expect.assertions(7);
9+
expect.assertions(6);
1010

1111
await createRunner(__dirname, 'scenario.ts')
1212
.expect({ transaction: { transaction: 'test_span_1' } })
1313
.expect({
1414
transaction: transaction => {
1515
expect(transaction).toBeDefined();
1616
const traceId = transaction.contexts?.trace?.trace_id;
17-
expect(traceId).toBeDefined();
1817

19-
// It ignores propagation context of the root context
20-
expect(traceId).not.toBe('12345678901234567890123456789012');
21-
expect(transaction.contexts?.trace?.parent_span_id).toBeUndefined();
18+
// Both root spans continue the scope's propagation context, matching the core SDK behavior.
19+
expect(traceId).toBe('12345678901234567890123456789012');
20+
expect(transaction.contexts?.trace?.parent_span_id).toBe('1234567890123456');
2221

23-
// Different trace ID than the first span
22+
// Same trace ID as the first span
2423
const trace1Id = transaction.contexts?.trace?.data?.spanIdTraceId;
25-
expect(trace1Id).toBeDefined();
26-
expect(trace1Id).not.toBe(traceId);
24+
expect(trace1Id).toBe('12345678901234567890123456789012');
25+
expect(trace1Id).toBe(traceId);
2726
},
2827
})
2928
.start()

dev-packages/node-integration-tests/suites/public-api/startSpan/parallel-spans-in-scope-streamed/test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@ test('sends manually started streamed parallel root spans outside of root contex
99
expect.assertions(6);
1010

1111
await createRunner(__dirname, 'scenario.ts')
12-
.expect({ span: { items: [{ name: 'test_span_1' }] } })
1312
.expect({
1413
span: spanContainer => {
1514
expect(spanContainer).toBeDefined();
16-
const traceId = spanContainer.items[0]!.trace_id;
17-
expect(traceId).toMatch(/^[0-9a-f]{32}$/);
18-
expect(spanContainer.items[0]!.parent_span_id).toBeUndefined();
1915

20-
const trace1Id = spanContainer.items[0]!.attributes.spanIdTraceId?.value;
21-
expect(trace1Id).toMatch(/^[0-9a-f]{32}$/);
16+
const span1 = spanContainer.items.find(item => item.name === 'test_span_1');
17+
const span2 = spanContainer.items.find(item => item.name === 'test_span_2');
18+
expect(span1).toBeDefined();
19+
expect(span2).toBeDefined();
2220

23-
// Different trace ID as the first span
24-
expect(trace1Id).not.toBe(traceId);
21+
expect(span1!.trace_id).toMatch(/^[0-9a-f]{32}$/);
22+
expect(span1!.parent_span_id).toBeUndefined();
23+
24+
// Same trace ID for both spans - both root spans share the scope's propagation context
25+
expect(span2!.trace_id).toBe(span1!.trace_id);
2526
},
2627
})
2728
.start()

dev-packages/node-integration-tests/suites/public-api/startSpan/parallel-spans-in-scope-with-parentSpanId-streamed/test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@ test('sends manually started streamed parallel root spans outside of root contex
99
expect.assertions(6);
1010

1111
await createRunner(__dirname, 'scenario.ts')
12-
.expect({ span: { items: [{ name: 'test_span_1' }] } })
1312
.expect({
1413
span: spanContainer => {
1514
expect(spanContainer).toBeDefined();
16-
const traceId = spanContainer.items[0]!.trace_id;
17-
expect(traceId).toMatch(/^[0-9a-f]{32}$/);
18-
expect(spanContainer.items[0]!.parent_span_id).toBeUndefined();
1915

20-
const trace1Id = spanContainer.items[0]!.attributes.spanIdTraceId?.value;
21-
expect(trace1Id).toMatch(/^[0-9a-f]{32}$/);
16+
const span1 = spanContainer.items.find(item => item.name === 'test_span_1');
17+
const span2 = spanContainer.items.find(item => item.name === 'test_span_2');
18+
expect(span1).toBeDefined();
19+
expect(span2).toBeDefined();
2220

23-
// Different trace ID as the first span
24-
expect(trace1Id).not.toBe(traceId);
21+
// Both root spans continue the scope's propagation context, including the parentSpanId,
22+
// matching the core SDK behavior.
23+
expect(span1!.trace_id).toBe('12345678901234567890123456789012');
24+
expect(span1!.parent_span_id).toBe('1234567890123456');
25+
26+
// Same trace ID for both spans
27+
expect(span2!.trace_id).toBe(span1!.trace_id);
2528
},
2629
})
2730
.start()

dev-packages/node-integration-tests/suites/public-api/startSpan/parallel-spans-in-scope-with-parentSpanId/test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ test('should send manually started parallel root spans outside of root context w
1212
transaction: transaction => {
1313
expect(transaction).toBeDefined();
1414
const traceId = transaction.contexts?.trace?.trace_id;
15-
expect(traceId).toBeDefined();
16-
expect(transaction.contexts?.trace?.parent_span_id).toBeUndefined();
1715

18-
const trace1Id = transaction.contexts?.trace?.data?.spanIdTraceId;
19-
expect(trace1Id).toBeDefined();
16+
// Both root spans continue the scope's propagation context, including the parentSpanId,
17+
// matching the core SDK behavior.
18+
expect(traceId).toBe('12345678901234567890123456789012');
19+
expect(transaction.contexts?.trace?.parent_span_id).toBe('1234567890123456');
2020

21-
// Different trace ID as the first span
22-
expect(trace1Id).not.toBe(traceId);
21+
// Same trace ID as the first span
22+
const trace1Id = transaction.contexts?.trace?.data?.spanIdTraceId;
23+
expect(trace1Id).toBe(traceId);
2324
},
2425
})
2526
.start()

dev-packages/node-integration-tests/suites/public-api/startSpan/parallel-spans-in-scope/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ test('should send manually started parallel root spans outside of root context',
2020
const trace1Id = transaction.contexts?.trace?.data?.spanIdTraceId;
2121
expect(trace1Id).toBeDefined();
2222

23-
// Different trace ID as the first span
24-
expect(trace1Id).not.toBe(traceId);
23+
// Same trace ID as the first span - both root spans share the scope's propagation context
24+
expect(trace1Id).toBe(traceId);
2525
},
2626
})
2727
.start()

0 commit comments

Comments
 (0)