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

Commit 22387ff

Browse files
fabiogomessilvakjin
authored andcommitted
fix: set currentRootSpan before start and set parentSpanId at span constructor (#32)
* fix: set currentRootSpan before start, set parentSpanId at span constructor and add options to SpanBase.spanContext * refactor: changes to address review comments
1 parent 1cae8f1 commit 22387ff

3 files changed

Lines changed: 6 additions & 15 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ export abstract class SpanBase implements types.Span {
116116
/** Gives the TraceContext of the span. */
117117
get spanContext(): types.SpanContext {
118118
return {
119-
traceId: this.traceId.toString(),
120-
spanId: this.id.toString(),
121-
parentSpanId: this.parentSpanId
122-
} as types.SpanContext;
119+
traceId: this.traceId,
120+
spanId: this.id,
121+
options: 0x1 // always traced
122+
};
123123
}
124124

125125
/**

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,14 @@ export class Span extends SpanBase implements types.Span {
3232
super();
3333
this.root = root;
3434
this.logger = this.root.logger || logger.logger();
35+
this.parentSpanId = root.id;
3536
}
3637

3738
/** Gets trace id of span. */
3839
get traceId(): string {
3940
return this.root.traceId;
4041
}
4142

42-
/** Gets trace context of span. */
43-
get spanContext(): types.SpanContext {
44-
return {
45-
traceId: this.traceId.toString(),
46-
spanId: this.id.toString(),
47-
options: 1 // always traced
48-
};
49-
}
50-
5143
/** Starts the span instance. */
5244
start() {
5345
super.start();
@@ -57,7 +49,6 @@ export class Span extends SpanBase implements types.Span {
5749
}
5850

5951

60-
6152
/** Ends the span. */
6253
end(): void {
6354
super.end();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ export class Tracer implements types.Tracer {
126126
this.sampler.shouldSample(aRoot.traceId);
127127

128128
if (sampleDecision) {
129-
aRoot.start();
130129
this.currentRootSpan = aRoot;
130+
aRoot.start();
131131
newRoot = aRoot;
132132
}
133133
} else {

0 commit comments

Comments
 (0)