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

Commit d07d893

Browse files
authored
Fix CoreTracerBase not respecting propagated trace options (#811)
1 parent e40d5cc commit d07d893

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

packages/opencensus-core/src/trace/model/tracer-base.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,15 @@ export class CoreTracerBase implements types.TracerBase {
262262
}
263263
let propagatedSample = null;
264264
// if there is a context propagation, keep the decision
265-
if (options && options.spanContext && options.spanContext.options) {
265+
if (
266+
options &&
267+
options.spanContext &&
268+
options.spanContext.options !== undefined
269+
) {
266270
propagatedSample = (options.spanContext.options & this.IS_SAMPLED) !== 0;
271+
return !!propagatedSample;
267272
}
268-
269-
// Propagated sample or use the default global sampler
270-
return !!propagatedSample || this.sampler.shouldSample(traceId);
273+
// default global sampler
274+
return this.sampler.shouldSample(traceId);
271275
}
272276
}

packages/opencensus-core/test/test-tracer-base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,13 @@ describe('Tracer Base', () => {
225225
});
226226
});
227227

228-
it('should create the new RootSpan with no propagation (options bit is not set)', () => {
228+
it('should create the new NoRecordRootSpan with propagation options bit set to not-sample)', () => {
229229
const tracer = new CoreTracerBase();
230230
tracer.start(defaultConfig);
231231
traceOptions.spanContext!.options = 0x0;
232232
tracer.startRootSpan(traceOptions, rootSpan => {
233233
assert.ok(rootSpan);
234+
assert.ok(rootSpan instanceof NoRecordRootSpan);
234235
assert.strictEqual(rootSpan.name, traceOptions.name);
235236
assert.strictEqual(rootSpan.kind, traceOptions.kind);
236237
assert.strictEqual(rootSpan.traceId, spanContextPropagated.traceId);

0 commit comments

Comments
 (0)