@@ -71,16 +71,6 @@ export class Span implements SpanInterface {
71
71
*/
72
72
public status ?: SpanStatusType | string ;
73
73
74
- /**
75
- * Timestamp in seconds when the span was created.
76
- */
77
- public startTimestamp : number ;
78
-
79
- /**
80
- * Timestamp in seconds when the span ended.
81
- */
82
- public endTimestamp ?: number ;
83
-
84
74
/**
85
75
* @inheritDoc
86
76
*/
@@ -131,6 +121,10 @@ export class Span implements SpanInterface {
131
121
protected _sampled : boolean | undefined ;
132
122
protected _name ?: string ;
133
123
protected _attributes : SpanAttributes ;
124
+ /** Epoch timestamp in seconds when the span started. */
125
+ protected _startTime : number ;
126
+ /** Epoch timestamp in seconds when the span ended. */
127
+ protected _endTime ?: number ;
134
128
135
129
private _logMessage ?: string ;
136
130
@@ -144,7 +138,7 @@ export class Span implements SpanInterface {
144
138
public constructor ( spanContext : SpanContext = { } ) {
145
139
this . _traceId = spanContext . traceId || uuid4 ( ) ;
146
140
this . _spanId = spanContext . spanId || uuid4 ( ) . substring ( 16 ) ;
147
- this . startTimestamp = spanContext . startTimestamp || timestampInSeconds ( ) ;
141
+ this . _startTime = spanContext . startTimestamp || timestampInSeconds ( ) ;
148
142
// eslint-disable-next-line deprecation/deprecation
149
143
this . tags = spanContext . tags ? { ...spanContext . tags } : { } ;
150
144
// eslint-disable-next-line deprecation/deprecation
@@ -170,7 +164,7 @@ export class Span implements SpanInterface {
170
164
this . status = spanContext . status ;
171
165
}
172
166
if ( spanContext . endTimestamp ) {
173
- this . endTimestamp = spanContext . endTimestamp ;
167
+ this . _endTime = spanContext . endTimestamp ;
174
168
}
175
169
}
176
170
@@ -273,6 +267,38 @@ export class Span implements SpanInterface {
273
267
this . _attributes = attributes ;
274
268
}
275
269
270
+ /**
271
+ * Timestamp in seconds (epoch time) indicating when the span started.
272
+ * @deprecated Use `spanToJSON()` instead.
273
+ */
274
+ public get startTimestamp ( ) : number {
275
+ return this . _startTime ;
276
+ }
277
+
278
+ /**
279
+ * Timestamp in seconds (epoch time) indicating when the span started.
280
+ * @deprecated In v8, you will not be able to update the span start time after creation.
281
+ */
282
+ public set startTimestamp ( startTime : number ) {
283
+ this . _startTime = startTime ;
284
+ }
285
+
286
+ /**
287
+ * Timestamp in seconds when the span ended.
288
+ * @deprecated Use `spanToJSON()` instead.
289
+ */
290
+ public get endTimestamp ( ) : number | undefined {
291
+ return this . _endTime ;
292
+ }
293
+
294
+ /**
295
+ * Timestamp in seconds when the span ended.
296
+ * @deprecated Set the end time via `span.end()` instead.
297
+ */
298
+ public set endTimestamp ( endTime : number | undefined ) {
299
+ this . _endTime = endTime ;
300
+ }
301
+
276
302
/* eslint-enable @typescript-eslint/member-ordering */
277
303
278
304
/** @inheritdoc */
@@ -426,6 +452,10 @@ export class Span implements SpanInterface {
426
452
427
453
/** @inheritdoc */
428
454
public end ( endTimestamp ?: SpanTimeInput ) : void {
455
+ // If already ended, skip
456
+ if ( this . _endTime ) {
457
+ return ;
458
+ }
429
459
const rootSpan = getRootSpan ( this ) ;
430
460
if (
431
461
DEBUG_BUILD &&
@@ -439,7 +469,7 @@ export class Span implements SpanInterface {
439
469
}
440
470
}
441
471
442
- this . endTimestamp = spanTimeInputToSeconds ( endTimestamp ) ;
472
+ this . _endTime = spanTimeInputToSeconds ( endTimestamp ) ;
443
473
}
444
474
445
475
/**
@@ -460,12 +490,12 @@ export class Span implements SpanInterface {
460
490
return dropUndefinedKeys ( {
461
491
data : this . _getData ( ) ,
462
492
description : this . _name ,
463
- endTimestamp : this . endTimestamp ,
493
+ endTimestamp : this . _endTime ,
464
494
op : this . op ,
465
495
parentSpanId : this . parentSpanId ,
466
496
sampled : this . _sampled ,
467
497
spanId : this . _spanId ,
468
- startTimestamp : this . startTimestamp ,
498
+ startTimestamp : this . _startTime ,
469
499
status : this . status ,
470
500
// eslint-disable-next-line deprecation/deprecation
471
501
tags : this . tags ,
@@ -483,12 +513,12 @@ export class Span implements SpanInterface {
483
513
this . data = spanContext . data || { } ;
484
514
// eslint-disable-next-line deprecation/deprecation
485
515
this . _name = spanContext . name || spanContext . description ;
486
- this . endTimestamp = spanContext . endTimestamp ;
516
+ this . _endTime = spanContext . endTimestamp ;
487
517
this . op = spanContext . op ;
488
518
this . parentSpanId = spanContext . parentSpanId ;
489
519
this . _sampled = spanContext . sampled ;
490
520
this . _spanId = spanContext . spanId || this . _spanId ;
491
- this . startTimestamp = spanContext . startTimestamp || this . startTimestamp ;
521
+ this . _startTime = spanContext . startTimestamp || this . _startTime ;
492
522
this . status = spanContext . status ;
493
523
// eslint-disable-next-line deprecation/deprecation
494
524
this . tags = spanContext . tags || { } ;
@@ -521,19 +551,19 @@ export class Span implements SpanInterface {
521
551
op : this . op ,
522
552
parent_span_id : this . parentSpanId ,
523
553
span_id : this . _spanId ,
524
- start_timestamp : this . startTimestamp ,
554
+ start_timestamp : this . _startTime ,
525
555
status : this . status ,
526
556
// eslint-disable-next-line deprecation/deprecation
527
557
tags : Object . keys ( this . tags ) . length > 0 ? this . tags : undefined ,
528
- timestamp : this . endTimestamp ,
558
+ timestamp : this . _endTime ,
529
559
trace_id : this . _traceId ,
530
560
origin : this . origin ,
531
561
} ) ;
532
562
}
533
563
534
564
/** @inheritdoc */
535
565
public isRecording ( ) : boolean {
536
- return ! this . endTimestamp && ! ! this . _sampled ;
566
+ return ! this . _endTime && ! ! this . _sampled ;
537
567
}
538
568
539
569
/**
0 commit comments