11import { Span as SpanInterface , SpanContext } from '@sentry/types' ;
2- import { uuid4 } from '@sentry/utils' ;
2+ import { timestampWithMs , uuid4 } from '@sentry/utils' ;
33
44export const TRACEPARENT_REGEXP = / ^ [ \t ] * ( [ 0 - 9 a - f ] { 32 } ) ? - ? ( [ 0 - 9 a - f ] { 16 } ) ? - ? ( [ 0 1 ] ) ? [ \t ] * $ / ;
55
@@ -8,57 +8,57 @@ export const TRACEPARENT_REGEXP = /^[ \t]*([0-9a-f]{32})?-?([0-9a-f]{16})?-?([01
88 */
99export class Span implements SpanInterface , SpanContext {
1010 /**
11- * Trace ID
11+ * @inheritDoc
1212 */
1313 private readonly _traceId : string = uuid4 ( ) ;
1414
1515 /**
16- * Span ID
16+ * @inheritDoc
1717 */
1818 private readonly _spanId : string = uuid4 ( ) . substring ( 16 ) ;
1919
2020 /**
21- * Parent Span ID
21+ * @inheritDoc
2222 */
2323 private readonly _parentSpanId ?: string ;
2424
2525 /**
26- * Has the sampling decision been made?
26+ * @inheritDoc
2727 */
2828 public readonly sampled ?: boolean ;
2929
3030 /**
3131 * Timestamp when the span was created.
3232 */
33- public readonly startTimestamp : number = new Date ( ) . getTime ( ) / 1000 ;
33+ public readonly startTimestamp : number = timestampWithMs ( ) ;
3434
3535 /**
3636 * Finish timestamp of the span.
3737 */
3838 public timestamp ?: number ;
3939
4040 /**
41- * Transaction of the Span.
41+ * @inheritDoc
4242 */
4343 public transaction ?: string ;
4444
4545 /**
46- * Operation of the Span.
46+ * @inheritDoc
4747 */
4848 public op ?: string ;
4949
5050 /**
51- * Description of the Span.
51+ * @inheritDoc
5252 */
5353 public description ?: string ;
5454
5555 /**
56- * Tags of the Span.
56+ * @inheritDoc
5757 */
5858 public tags ?: { [ key : string ] : string } ;
5959
6060 /**
61- * Data of the Span.
61+ * @inheritDoc
6262 */
6363 public data ?: { [ key : string ] : any } ;
6464
@@ -101,7 +101,10 @@ export class Span implements SpanInterface, SpanContext {
101101 }
102102 }
103103
104- /** JSDoc */
104+ /**
105+ * Creates a new `Span` while setting the current `Span.id` as `parentSpanId`.
106+ * Also the `sampled` decision will be inherited.
107+ */
105108 public newSpan ( spanContext ?: Pick < SpanContext , Exclude < keyof SpanContext , 'spanId' > > ) : Span {
106109 const span = new Span ( {
107110 ...spanContext ,
@@ -116,7 +119,7 @@ export class Span implements SpanInterface, SpanContext {
116119 }
117120
118121 /**
119- * Continues a trace
122+ * Continues a trace from a string (usually the header).
120123 * @param traceparent Traceparent string
121124 */
122125 public static fromTraceparent (
@@ -131,7 +134,6 @@ export class Span implements SpanInterface, SpanContext {
131134 } else if ( matches [ 3 ] === '0' ) {
132135 sampled = false ;
133136 }
134-
135137 return new Span ( {
136138 ...spanContext ,
137139 parentSpanId : matches [ 2 ] ,
@@ -146,7 +148,7 @@ export class Span implements SpanInterface, SpanContext {
146148 * Sets the finish timestamp on the current span
147149 */
148150 public finish ( ) : void {
149- this . timestamp = new Date ( ) . getTime ( ) / 1000 ;
151+ this . timestamp = timestampWithMs ( ) ;
150152 this . finishedSpans . push ( this ) ;
151153 }
152154
0 commit comments