1
- import { Span as SpanInterface , SpanDetails } from '@sentry/types' ;
1
+ import { Span as SpanInterface , SpanProps } from '@sentry/types' ;
2
2
import { 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
6
6
/**
7
- * Span containg all data about a span
7
+ * Span contains all data about a span
8
8
*/
9
- export class Span implements SpanInterface {
9
+ export class Span implements SpanInterface , SpanProps {
10
10
/**
11
11
* Trace ID
12
12
*/
@@ -57,38 +57,38 @@ export class Span implements SpanInterface {
57
57
*/
58
58
public finishedSpans : Span [ ] = [ ] ;
59
59
60
- public constructor ( spanDetails ?: SpanDetails ) {
61
- if ( ! spanDetails ) {
60
+ public constructor ( spanProps ?: SpanProps ) {
61
+ if ( ! spanProps ) {
62
62
return this ;
63
63
}
64
64
65
- if ( spanDetails . traceId ) {
66
- this . _traceId = spanDetails . traceId ;
65
+ if ( spanProps . traceId ) {
66
+ this . _traceId = spanProps . traceId ;
67
67
}
68
- if ( spanDetails . spanId ) {
69
- this . _spanId = spanDetails . spanId ;
68
+ if ( spanProps . spanId ) {
69
+ this . _spanId = spanProps . spanId ;
70
70
}
71
- if ( spanDetails . parentSpanId ) {
72
- this . _parentSpanId = spanDetails . parentSpanId ;
71
+ if ( spanProps . parentSpanId ) {
72
+ this . _parentSpanId = spanProps . parentSpanId ;
73
73
}
74
- if ( spanDetails . sampled ) {
75
- this . sampled = spanDetails . sampled ;
74
+ if ( spanProps . sampled ) {
75
+ this . sampled = spanProps . sampled ;
76
76
}
77
- if ( spanDetails . transaction ) {
78
- this . transaction = spanDetails . transaction ;
77
+ if ( spanProps . transaction ) {
78
+ this . transaction = spanProps . transaction ;
79
79
}
80
- if ( spanDetails . op ) {
81
- this . op = spanDetails . op ;
80
+ if ( spanProps . op ) {
81
+ this . op = spanProps . op ;
82
82
}
83
- if ( spanDetails . description ) {
84
- this . description = spanDetails . description ;
83
+ if ( spanProps . description ) {
84
+ this . description = spanProps . description ;
85
85
}
86
86
}
87
87
88
88
/** JSDoc */
89
- public newSpan ( spanDetails ?: Pick < SpanDetails , Exclude < keyof SpanDetails , 'spanId' > > ) : Span {
89
+ public newSpan ( spanProps ?: Pick < SpanProps , Exclude < keyof SpanProps , 'spanId' > > ) : Span {
90
90
const span = new Span ( {
91
- ...spanDetails ,
91
+ ...spanProps ,
92
92
parentSpanId : this . _parentSpanId ,
93
93
sampled : this . sampled ,
94
94
traceId : this . _traceId ,
@@ -99,27 +99,19 @@ export class Span implements SpanInterface {
99
99
return span ;
100
100
}
101
101
102
- /**
103
- * Setter for transaction.
104
- */
105
- public setTransaction ( transaction : string | undefined ) : this {
106
- this . transaction = transaction ;
107
- return this ;
108
- }
109
-
110
102
/**
111
103
* Continues a trace
112
104
* @param traceparent Traceparent string
113
105
*/
114
106
public static fromTraceparent (
115
107
traceparent : string ,
116
- spanDetails ?: Pick < SpanDetails , Exclude < keyof SpanDetails , 'spanId' | 'sampled' | 'traceid' > > ,
108
+ spanProps ?: Pick < SpanProps , Exclude < keyof SpanProps , 'spanId' | 'sampled' | 'traceid' > > ,
117
109
) : Span | undefined {
118
110
const matches = traceparent . match ( TRACEPARENT_REGEXP ) ;
119
111
if ( matches ) {
120
112
const [ traceId , spanId , sampled ] = matches ;
121
113
return new Span ( {
122
- ...spanDetails ,
114
+ ...spanProps ,
123
115
sampled,
124
116
spanId,
125
117
traceId,
@@ -142,6 +134,7 @@ export class Span implements SpanInterface {
142
134
public toTraceparent ( ) : string {
143
135
return `${ this . _traceId } -${ this . _spanId } ${ this . sampled ? '-1' : '0' } ` ;
144
136
}
137
+
145
138
/**
146
139
* @inheritDoc
147
140
*/
0 commit comments