Skip to content

Commit cff9c0e

Browse files
HazATkamilogorek
authored andcommitted
fix: SpanContext var name, Timestamp in secs
1 parent 59516ce commit cff9c0e

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

packages/hub/src/hub.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -389,17 +389,17 @@ export class Hub implements HubInterface {
389389
/**
390390
* @inheritDoc
391391
*/
392-
public startSpan(SpanContext?: SpanContext): Span {
392+
public startSpan(spanContext?: SpanContext): Span {
393393
const scope = this.getScope();
394394

395395
if (scope) {
396396
const span = scope.getSpan();
397397
if (span) {
398-
return span.newSpan(SpanContext);
398+
return span.newSpan(spanContext);
399399
}
400400
}
401401

402-
return new Span(SpanContext);
402+
return new Span(spanContext);
403403
}
404404

405405
/**

packages/hub/src/span.ts

+26-26
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class Span implements SpanInterface, SpanContext {
3030
/**
3131
* Timestamp when the span was created.
3232
*/
33-
public readonly startTimestamp: number = new Date().getTime();
33+
public readonly startTimestamp: number = new Date().getTime() / 1000;
3434

3535
/**
3636
* Finish timestamp of the span.
@@ -67,44 +67,44 @@ export class Span implements SpanInterface, SpanContext {
6767
*/
6868
public finishedSpans: Span[] = [];
6969

70-
public constructor(SpanContext?: SpanContext) {
71-
if (!SpanContext) {
70+
public constructor(spanContext?: SpanContext) {
71+
if (!spanContext) {
7272
return this;
7373
}
7474

75-
if (SpanContext.traceId) {
76-
this._traceId = SpanContext.traceId;
75+
if (spanContext.traceId) {
76+
this._traceId = spanContext.traceId;
7777
}
78-
if (SpanContext.spanId) {
79-
this._spanId = SpanContext.spanId;
78+
if (spanContext.spanId) {
79+
this._spanId = spanContext.spanId;
8080
}
81-
if (SpanContext.parentSpanId) {
82-
this._parentSpanId = SpanContext.parentSpanId;
81+
if (spanContext.parentSpanId) {
82+
this._parentSpanId = spanContext.parentSpanId;
8383
}
84-
if (SpanContext.sampled) {
85-
this.sampled = SpanContext.sampled;
84+
if (spanContext.sampled) {
85+
this.sampled = spanContext.sampled;
8686
}
87-
if (SpanContext.transaction) {
88-
this.transaction = SpanContext.transaction;
87+
if (spanContext.transaction) {
88+
this.transaction = spanContext.transaction;
8989
}
90-
if (SpanContext.op) {
91-
this.op = SpanContext.op;
90+
if (spanContext.op) {
91+
this.op = spanContext.op;
9292
}
93-
if (SpanContext.description) {
94-
this.description = SpanContext.description;
93+
if (spanContext.description) {
94+
this.description = spanContext.description;
9595
}
96-
if (SpanContext.data) {
97-
this.data = SpanContext.data;
96+
if (spanContext.data) {
97+
this.data = spanContext.data;
9898
}
99-
if (SpanContext.tags) {
100-
this.tags = SpanContext.tags;
99+
if (spanContext.tags) {
100+
this.tags = spanContext.tags;
101101
}
102102
}
103103

104104
/** JSDoc */
105-
public newSpan(SpanContext?: Pick<SpanContext, Exclude<keyof SpanContext, 'spanId'>>): Span {
105+
public newSpan(spanContext?: Pick<SpanContext, Exclude<keyof SpanContext, 'spanId'>>): Span {
106106
const span = new Span({
107-
...SpanContext,
107+
...spanContext,
108108
parentSpanId: this._spanId,
109109
sampled: this.sampled,
110110
traceId: this._traceId,
@@ -121,7 +121,7 @@ export class Span implements SpanInterface, SpanContext {
121121
*/
122122
public static fromTraceparent(
123123
traceparent: string,
124-
SpanContext?: Pick<SpanContext, Exclude<keyof SpanContext, 'spanId' | 'sampled' | 'traceid'>>,
124+
spanContext?: Pick<SpanContext, Exclude<keyof SpanContext, 'spanId' | 'sampled' | 'traceid'>>,
125125
): Span | undefined {
126126
const matches = traceparent.match(TRACEPARENT_REGEXP);
127127
if (matches) {
@@ -133,7 +133,7 @@ export class Span implements SpanInterface, SpanContext {
133133
}
134134

135135
return new Span({
136-
...SpanContext,
136+
...spanContext,
137137
parentSpanId: matches[2],
138138
sampled,
139139
traceId: matches[1],
@@ -146,7 +146,7 @@ export class Span implements SpanInterface, SpanContext {
146146
* Sets the finish timestamp on the current span
147147
*/
148148
public finish(): void {
149-
this.timestamp = new Date().getTime();
149+
this.timestamp = new Date().getTime() / 1000;
150150
this.finishedSpans.push(this);
151151
}
152152

packages/types/src/hub.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export interface Hub {
173173
traceHeaders(): { [key: string]: string };
174174

175175
/** JSDoc */
176-
startSpan(SpanContext?: SpanContext): Span;
176+
startSpan(spanContext?: SpanContext): Span;
177177

178178
/** JSDoc */
179179
finishSpan(span: Span): string | undefined;

0 commit comments

Comments
 (0)