Skip to content

Commit 28fbde8

Browse files
committed
adjust tests & behavior
1 parent eae55fd commit 28fbde8

File tree

4 files changed

+29
-36
lines changed

4 files changed

+29
-36
lines changed

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

+2-14
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,5 @@ Sentry.getCurrentScope().setPropagationContext({
1414
traceId: '12345678901234567890123456789012',
1515
});
1616

17-
const spanIdTraceId = Sentry.startSpan(
18-
{
19-
name: 'test_span_1',
20-
},
21-
span1 => span1.spanContext().traceId,
22-
);
23-
24-
Sentry.startSpan(
25-
{
26-
name: 'test_span_2',
27-
attributes: { spanIdTraceId },
28-
},
29-
() => undefined,
30-
);
17+
Sentry.startSpan({ name: 'test_span_1' }, () => undefined);
18+
Sentry.startSpan({ name: 'test_span_2' }, () => undefined);

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

+21-16
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,29 @@ afterAll(() => {
55
});
66

77
test('should send manually started parallel root spans in root context', done => {
8-
expect.assertions(7);
9-
108
createRunner(__dirname, 'scenario.ts')
11-
.expect({ transaction: { transaction: 'test_span_1' } })
129
.expect({
13-
transaction: transaction => {
14-
expect(transaction).toBeDefined();
15-
const traceId = transaction.contexts?.trace?.trace_id;
16-
expect(traceId).toBeDefined();
17-
18-
// It ignores propagation context of the root context
19-
expect(traceId).not.toBe('12345678901234567890123456789012');
20-
expect(transaction.contexts?.trace?.parent_span_id).toBeUndefined();
21-
22-
// Different trace ID than the first span
23-
const trace1Id = transaction.contexts?.trace?.data?.spanIdTraceId;
24-
expect(trace1Id).toBeDefined();
25-
expect(trace1Id).not.toBe(traceId);
10+
transaction: {
11+
transaction: 'test_span_1',
12+
contexts: {
13+
trace: {
14+
span_id: expect.any(String),
15+
parent_span_id: '1234567890123456',
16+
trace_id: '12345678901234567890123456789012',
17+
},
18+
},
19+
},
20+
})
21+
.expect({
22+
transaction: {
23+
transaction: 'test_span_2',
24+
contexts: {
25+
trace: {
26+
span_id: expect.any(String),
27+
parent_span_id: '1234567890123456',
28+
trace_id: '12345678901234567890123456789012',
29+
},
30+
},
2631
},
2732
})
2833
.start(done);

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ test('should send manually started parallel root spans outside of root context',
1919
const trace1Id = transaction.contexts?.trace?.data?.spanIdTraceId;
2020
expect(trace1Id).toBeDefined();
2121

22-
// Same trace ID as the first span
23-
expect(trace1Id).toBe(traceId);
22+
expect(trace1Id).not.toBe(traceId);
2423
},
2524
})
2625
.start(done);

packages/opentelemetry/src/trace.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Context, Span, SpanContext, SpanOptions, Tracer } from '@opentelemetry/api';
1+
import { Context, ROOT_CONTEXT, Span, SpanContext, SpanOptions, Tracer } from '@opentelemetry/api';
22
import { INVALID_SPANID, SpanStatusCode, TraceFlags, context, trace } from '@opentelemetry/api';
33
import { suppressTracing } from '@opentelemetry/core';
44
import {
@@ -180,13 +180,14 @@ function getContext(scope: Scope | undefined, forceTransaction: boolean | undefi
180180

181181
// In the case that we have no parent span, we need to "simulate" one to ensure the propagation context is correct
182182
if (!parentSpan) {
183-
const actualScope = getScopesFromContext(ctx)?.scope;
184-
const propagationContext = actualScope && actualScope.getPropagationContext();
183+
// If we cannot pick a scope from the context (e.g. if it is the root context), we just take the current scope
184+
const actualScope = getScopesFromContext(ctx)?.scope || getCurrentScope();
185+
const propagationContext = actualScope.getPropagationContext();
185186

186187
// If we are continuing an incoming trace, we use it
187188
// This is signified by the presence of `parentSpanId` -
188189
// if this is not set, then we are not continuing an incoming trace
189-
if (propagationContext && propagationContext.parentSpanId) {
190+
if (propagationContext.parentSpanId) {
190191
// We store the DSC as OTEL trace state on the span context
191192
const traceState = makeTraceState({
192193
parentSpanId: propagationContext.parentSpanId,

0 commit comments

Comments
 (0)