Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit eff8921

Browse files
authored
set CurrentRootSpan when parentSpanId passed on wire (#570)
1 parent 338ed3a commit eff8921

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

packages/opencensus-core/src/trace/model/span.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,8 @@ export class Span implements types.Span {
310310
parentSpanId: this.parentSpanId,
311311
traceState: this.traceState
312312
});
313-
if (!this.parentSpanId) {
314-
this.tracer.setCurrentRootSpan(this);
315-
}
316313

314+
if (this.isRootSpan()) this.tracer.setCurrentRootSpan(this);
317315
this.tracer.onStartSpan(this);
318316
}
319317

packages/opencensus-core/test/test-span.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,34 @@ describe('Span', () => {
113113

114114
assert.ok(span.started);
115115
});
116+
117+
118+
it('should start a RootSpan and set CurrentRootSpan when parentSpanId is empty',
119+
() => {
120+
const rootSpan = new RootSpan(tracer, name, kind, traceId, '');
121+
rootSpan.start();
122+
assert.strictEqual(tracer.currentRootSpan, rootSpan);
123+
124+
const span = new Span(tracer, rootSpan);
125+
span.start();
126+
assert.strictEqual(tracer.currentRootSpan, rootSpan);
127+
128+
assert.ok(span.started);
129+
});
130+
131+
it('should start a RootSpan and set CurrentRootSpan when parentSpanId is not empty',
132+
() => {
133+
const rootSpan =
134+
new RootSpan(tracer, name, kind, traceId, 'd5955a12632d46a1');
135+
rootSpan.start();
136+
assert.strictEqual(tracer.currentRootSpan, rootSpan);
137+
138+
const span = new Span(tracer, rootSpan);
139+
span.start();
140+
assert.strictEqual(tracer.currentRootSpan, rootSpan);
141+
142+
assert.ok(span.started);
143+
});
116144
});
117145

118146
/**

0 commit comments

Comments
 (0)