1
1
import { Span as SpanInterface , SpanContext } from '@sentry/types' ;
2
- import { uuid4 } from '@sentry/utils' ;
2
+ import { timestampWithMs , uuid4 } from '@sentry/utils' ;
3
3
4
4
export const TRACEPARENT_REGEXP = / ^ [ \t ] * ( [ 0 - 9 a - f ] { 32 } ) ? - ? ( [ 0 - 9 a - f ] { 16 } ) ? - ? ( [ 0 1 ] ) ? [ \t ] * $ / ;
5
5
@@ -8,57 +8,57 @@ export const TRACEPARENT_REGEXP = /^[ \t]*([0-9a-f]{32})?-?([0-9a-f]{16})?-?([01
8
8
*/
9
9
export class Span implements SpanInterface , SpanContext {
10
10
/**
11
- * Trace ID
11
+ * @inheritDoc
12
12
*/
13
13
private readonly _traceId : string = uuid4 ( ) ;
14
14
15
15
/**
16
- * Span ID
16
+ * @inheritDoc
17
17
*/
18
18
private readonly _spanId : string = uuid4 ( ) . substring ( 16 ) ;
19
19
20
20
/**
21
- * Parent Span ID
21
+ * @inheritDoc
22
22
*/
23
23
private readonly _parentSpanId ?: string ;
24
24
25
25
/**
26
- * Has the sampling decision been made?
26
+ * @inheritDoc
27
27
*/
28
28
public readonly sampled ?: boolean ;
29
29
30
30
/**
31
31
* Timestamp when the span was created.
32
32
*/
33
- public readonly startTimestamp : number = new Date ( ) . getTime ( ) / 1000 ;
33
+ public readonly startTimestamp : number = timestampWithMs ( ) ;
34
34
35
35
/**
36
36
* Finish timestamp of the span.
37
37
*/
38
38
public timestamp ?: number ;
39
39
40
40
/**
41
- * Transaction of the Span.
41
+ * @inheritDoc
42
42
*/
43
43
public transaction ?: string ;
44
44
45
45
/**
46
- * Operation of the Span.
46
+ * @inheritDoc
47
47
*/
48
48
public op ?: string ;
49
49
50
50
/**
51
- * Description of the Span.
51
+ * @inheritDoc
52
52
*/
53
53
public description ?: string ;
54
54
55
55
/**
56
- * Tags of the Span.
56
+ * @inheritDoc
57
57
*/
58
58
public tags ?: { [ key : string ] : string } ;
59
59
60
60
/**
61
- * Data of the Span.
61
+ * @inheritDoc
62
62
*/
63
63
public data ?: { [ key : string ] : any } ;
64
64
@@ -101,7 +101,10 @@ export class Span implements SpanInterface, SpanContext {
101
101
}
102
102
}
103
103
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
+ */
105
108
public newSpan ( spanContext ?: Pick < SpanContext , Exclude < keyof SpanContext , 'spanId' > > ) : Span {
106
109
const span = new Span ( {
107
110
...spanContext ,
@@ -116,7 +119,7 @@ export class Span implements SpanInterface, SpanContext {
116
119
}
117
120
118
121
/**
119
- * Continues a trace
122
+ * Continues a trace from a string (usually the header).
120
123
* @param traceparent Traceparent string
121
124
*/
122
125
public static fromTraceparent (
@@ -131,7 +134,6 @@ export class Span implements SpanInterface, SpanContext {
131
134
} else if ( matches [ 3 ] === '0' ) {
132
135
sampled = false ;
133
136
}
134
-
135
137
return new Span ( {
136
138
...spanContext ,
137
139
parentSpanId : matches [ 2 ] ,
@@ -146,7 +148,7 @@ export class Span implements SpanInterface, SpanContext {
146
148
* Sets the finish timestamp on the current span
147
149
*/
148
150
public finish ( ) : void {
149
- this . timestamp = new Date ( ) . getTime ( ) / 1000 ;
151
+ this . timestamp = timestampWithMs ( ) ;
150
152
this . finishedSpans . push ( this ) ;
151
153
}
152
154
0 commit comments