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

Commit

Permalink
set CurrentRootSpan when parentSpanId passed on wire (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 authored Jun 3, 2019
1 parent 338ed3a commit eff8921
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
4 changes: 1 addition & 3 deletions packages/opencensus-core/src/trace/model/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,8 @@ export class Span implements types.Span {
parentSpanId: this.parentSpanId,
traceState: this.traceState
});
if (!this.parentSpanId) {
this.tracer.setCurrentRootSpan(this);
}

if (this.isRootSpan()) this.tracer.setCurrentRootSpan(this);
this.tracer.onStartSpan(this);
}

Expand Down
28 changes: 28 additions & 0 deletions packages/opencensus-core/test/test-span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,34 @@ describe('Span', () => {

assert.ok(span.started);
});


it('should start a RootSpan and set CurrentRootSpan when parentSpanId is empty',
() => {
const rootSpan = new RootSpan(tracer, name, kind, traceId, '');
rootSpan.start();
assert.strictEqual(tracer.currentRootSpan, rootSpan);

const span = new Span(tracer, rootSpan);
span.start();
assert.strictEqual(tracer.currentRootSpan, rootSpan);

assert.ok(span.started);
});

it('should start a RootSpan and set CurrentRootSpan when parentSpanId is not empty',
() => {
const rootSpan =
new RootSpan(tracer, name, kind, traceId, 'd5955a12632d46a1');
rootSpan.start();
assert.strictEqual(tracer.currentRootSpan, rootSpan);

const span = new Span(tracer, rootSpan);
span.start();
assert.strictEqual(tracer.currentRootSpan, rootSpan);

assert.ok(span.started);
});
});

/**
Expand Down

0 comments on commit eff8921

Please sign in to comment.