@@ -71,16 +71,6 @@ export class Span implements SpanInterface {
7171 */
7272 public status ?: SpanStatusType | string ;
7373
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-
8474 /**
8575 * @inheritDoc
8676 */
@@ -131,6 +121,10 @@ export class Span implements SpanInterface {
131121 protected _sampled : boolean | undefined ;
132122 protected _name ?: string ;
133123 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 ;
134128
135129 private _logMessage ?: string ;
136130
@@ -144,7 +138,7 @@ export class Span implements SpanInterface {
144138 public constructor ( spanContext : SpanContext = { } ) {
145139 this . _traceId = spanContext . traceId || uuid4 ( ) ;
146140 this . _spanId = spanContext . spanId || uuid4 ( ) . substring ( 16 ) ;
147- this . startTimestamp = spanContext . startTimestamp || timestampInSeconds ( ) ;
141+ this . _startTime = spanContext . startTimestamp || timestampInSeconds ( ) ;
148142 // eslint-disable-next-line deprecation/deprecation
149143 this . tags = spanContext . tags ? { ...spanContext . tags } : { } ;
150144 // eslint-disable-next-line deprecation/deprecation
@@ -170,7 +164,7 @@ export class Span implements SpanInterface {
170164 this . status = spanContext . status ;
171165 }
172166 if ( spanContext . endTimestamp ) {
173- this . endTimestamp = spanContext . endTimestamp ;
167+ this . _endTime = spanContext . endTimestamp ;
174168 }
175169 }
176170
@@ -273,6 +267,38 @@ export class Span implements SpanInterface {
273267 this . _attributes = attributes ;
274268 }
275269
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+
276302 /* eslint-enable @typescript-eslint/member-ordering */
277303
278304 /** @inheritdoc */
@@ -426,6 +452,10 @@ export class Span implements SpanInterface {
426452
427453 /** @inheritdoc */
428454 public end ( endTimestamp ?: SpanTimeInput ) : void {
455+ // If already ended, skip
456+ if ( this . _endTime ) {
457+ return ;
458+ }
429459 const rootSpan = getRootSpan ( this ) ;
430460 if (
431461 DEBUG_BUILD &&
@@ -439,7 +469,7 @@ export class Span implements SpanInterface {
439469 }
440470 }
441471
442- this . endTimestamp = spanTimeInputToSeconds ( endTimestamp ) ;
472+ this . _endTime = spanTimeInputToSeconds ( endTimestamp ) ;
443473 }
444474
445475 /**
@@ -460,12 +490,12 @@ export class Span implements SpanInterface {
460490 return dropUndefinedKeys ( {
461491 data : this . _getData ( ) ,
462492 description : this . _name ,
463- endTimestamp : this . endTimestamp ,
493+ endTimestamp : this . _endTime ,
464494 op : this . op ,
465495 parentSpanId : this . parentSpanId ,
466496 sampled : this . _sampled ,
467497 spanId : this . _spanId ,
468- startTimestamp : this . startTimestamp ,
498+ startTimestamp : this . _startTime ,
469499 status : this . status ,
470500 // eslint-disable-next-line deprecation/deprecation
471501 tags : this . tags ,
@@ -483,12 +513,12 @@ export class Span implements SpanInterface {
483513 this . data = spanContext . data || { } ;
484514 // eslint-disable-next-line deprecation/deprecation
485515 this . _name = spanContext . name || spanContext . description ;
486- this . endTimestamp = spanContext . endTimestamp ;
516+ this . _endTime = spanContext . endTimestamp ;
487517 this . op = spanContext . op ;
488518 this . parentSpanId = spanContext . parentSpanId ;
489519 this . _sampled = spanContext . sampled ;
490520 this . _spanId = spanContext . spanId || this . _spanId ;
491- this . startTimestamp = spanContext . startTimestamp || this . startTimestamp ;
521+ this . _startTime = spanContext . startTimestamp || this . _startTime ;
492522 this . status = spanContext . status ;
493523 // eslint-disable-next-line deprecation/deprecation
494524 this . tags = spanContext . tags || { } ;
@@ -516,19 +546,19 @@ export class Span implements SpanInterface {
516546 op : this . op ,
517547 parent_span_id : this . parentSpanId ,
518548 span_id : this . _spanId ,
519- start_timestamp : this . startTimestamp ,
549+ start_timestamp : this . _startTime ,
520550 status : this . status ,
521551 // eslint-disable-next-line deprecation/deprecation
522552 tags : Object . keys ( this . tags ) . length > 0 ? this . tags : undefined ,
523- timestamp : this . endTimestamp ,
553+ timestamp : this . _endTime ,
524554 trace_id : this . _traceId ,
525555 origin : this . origin ,
526556 } ) ;
527557 }
528558
529559 /** @inheritdoc */
530560 public isRecording ( ) : boolean {
531- return ! this . endTimestamp && ! ! this . _sampled ;
561+ return ! this . _endTime && ! ! this . _sampled ;
532562 }
533563
534564 /**
0 commit comments