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

Commit

Permalink
Fix CoreTracerBase not respecting propagated trace options (#811)
Browse files Browse the repository at this point in the history
  • Loading branch information
philicious authored May 27, 2020
1 parent e40d5cc commit d07d893
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions packages/opencensus-core/src/trace/model/tracer-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,15 @@ export class CoreTracerBase implements types.TracerBase {
}
let propagatedSample = null;
// if there is a context propagation, keep the decision
if (options && options.spanContext && options.spanContext.options) {
if (
options &&
options.spanContext &&
options.spanContext.options !== undefined
) {
propagatedSample = (options.spanContext.options & this.IS_SAMPLED) !== 0;
return !!propagatedSample;
}

// Propagated sample or use the default global sampler
return !!propagatedSample || this.sampler.shouldSample(traceId);
// default global sampler
return this.sampler.shouldSample(traceId);
}
}
3 changes: 2 additions & 1 deletion packages/opencensus-core/test/test-tracer-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,13 @@ describe('Tracer Base', () => {
});
});

it('should create the new RootSpan with no propagation (options bit is not set)', () => {
it('should create the new NoRecordRootSpan with propagation options bit set to not-sample)', () => {
const tracer = new CoreTracerBase();
tracer.start(defaultConfig);
traceOptions.spanContext!.options = 0x0;
tracer.startRootSpan(traceOptions, rootSpan => {
assert.ok(rootSpan);
assert.ok(rootSpan instanceof NoRecordRootSpan);
assert.strictEqual(rootSpan.name, traceOptions.name);
assert.strictEqual(rootSpan.kind, traceOptions.kind);
assert.strictEqual(rootSpan.traceId, spanContextPropagated.traceId);
Expand Down

0 comments on commit d07d893

Please sign in to comment.