@@ -50,8 +50,8 @@ const SAMPLED_FLAG_KEY = 'Sampled';
50
50
const IS_SAMPLED = '1' ;
51
51
const NOT_SAMPLED = '0' ;
52
52
53
- const LINEAGE_KEY = " Lineage" ;
54
- const LINEAGE_DELIMITER = ":" ;
53
+ const LINEAGE_KEY = ' Lineage' ;
54
+ const LINEAGE_DELIMITER = ':' ;
55
55
const LINEAGE_HASH_LENGTH = 8 ;
56
56
const LINEAGE_MAX_REQUEST_COUNTER = 255 ;
57
57
const LINEAGE_MAX_LOOP_COUNTER = 32767 ;
@@ -82,24 +82,24 @@ export class AWSXRayPropagator implements TextMapPropagator {
82
82
: NOT_SAMPLED ;
83
83
// TODO: Add OT trace state to the X-Ray trace header
84
84
85
- let traceHeader =
86
- `${ TRACE_ID_KEY } ` +
87
- `${ KV_DELIMITER } ` +
88
- `${ xrayTraceId } ` +
89
- `${ TRACE_HEADER_DELIMITER } ` +
90
- `${ PARENT_ID_KEY } ` +
91
- `${ KV_DELIMITER } ` +
92
- `${ parentId } ` +
93
- `${ TRACE_HEADER_DELIMITER } ` +
94
- `${ SAMPLED_FLAG_KEY } ` +
95
- `${ KV_DELIMITER } ` +
96
- `${ samplingFlag } ` ;
85
+ let traceHeader =
86
+ `${ TRACE_ID_KEY } ` +
87
+ `${ KV_DELIMITER } ` +
88
+ `${ xrayTraceId } ` +
89
+ `${ TRACE_HEADER_DELIMITER } ` +
90
+ `${ PARENT_ID_KEY } ` +
91
+ `${ KV_DELIMITER } ` +
92
+ `${ parentId } ` +
93
+ `${ TRACE_HEADER_DELIMITER } ` +
94
+ `${ SAMPLED_FLAG_KEY } ` +
95
+ `${ KV_DELIMITER } ` +
96
+ `${ samplingFlag } ` ;
97
97
98
98
const baggage = propagation . getBaggage ( context ) ;
99
99
const lineageV2Header = baggage ?. getEntry ( LINEAGE_KEY ) ?. value ;
100
100
101
101
if ( lineageV2Header ) {
102
- traceHeader +=
102
+ traceHeader +=
103
103
`${ TRACE_HEADER_DELIMITER } ` +
104
104
`${ LINEAGE_KEY } ` +
105
105
`${ KV_DELIMITER } ` +
@@ -138,7 +138,8 @@ export class AWSXRayPropagator implements TextMapPropagator {
138
138
return context ;
139
139
}
140
140
141
- let baggage : Baggage = propagation . getBaggage ( context ) || propagation . createBaggage ( ) ;
141
+ let baggage : Baggage =
142
+ propagation . getBaggage ( context ) || propagation . createBaggage ( ) ;
142
143
143
144
let pos = 0 ;
144
145
let trimmedPart : string ;
@@ -167,7 +168,7 @@ export class AWSXRayPropagator implements TextMapPropagator {
167
168
parsedTraceFlags = AWSXRayPropagator . _parseTraceFlag ( value ) ;
168
169
} else if ( trimmedPart . startsWith ( LINEAGE_KEY ) ) {
169
170
if ( AWSXRayPropagator . _isValidLineageV2Header ( value ) ) {
170
- baggage = baggage . setEntry ( LINEAGE_KEY , { value} ) ;
171
+ baggage = baggage . setEntry ( LINEAGE_KEY , { value } ) ;
171
172
}
172
173
}
173
174
}
@@ -181,7 +182,10 @@ export class AWSXRayPropagator implements TextMapPropagator {
181
182
isRemote : true ,
182
183
} ;
183
184
if ( isSpanContextValid ( resultSpanContext ) ) {
184
- context = trace . setSpan ( context , trace . wrapSpanContext ( resultSpanContext ) ) ;
185
+ context = trace . setSpan (
186
+ context ,
187
+ trace . wrapSpanContext ( resultSpanContext )
188
+ ) ;
185
189
}
186
190
if ( baggage . getAllEntries ( ) . length > 0 ) {
187
191
context = propagation . setBaggage ( context , baggage ) ;
@@ -233,17 +237,21 @@ export class AWSXRayPropagator implements TextMapPropagator {
233
237
234
238
private static _isValidLineageV2Header ( xrayLineageHeader : string ) : boolean {
235
239
const lineageSubstrings = xrayLineageHeader . split ( LINEAGE_DELIMITER ) ;
236
- if ( lineageSubstrings . length != 3 ) {
240
+ if ( lineageSubstrings . length !== 3 ) {
237
241
return false ;
238
242
}
239
243
240
244
const requestCounter = parseInt ( lineageSubstrings [ 0 ] ) ;
241
245
const hashedResourceId = lineageSubstrings [ 1 ] ;
242
246
const loopCounter = parseInt ( lineageSubstrings [ 2 ] ) ;
243
-
244
- const isValidKey = hashedResourceId . length == LINEAGE_HASH_LENGTH && ! ! hashedResourceId . match ( / ^ [ 0 - 9 a - f A - F ] + $ / ) ;
245
- const isValidRequestCounter = requestCounter >= 0 && requestCounter <= LINEAGE_MAX_REQUEST_COUNTER ;
246
- const isValidLoopCounter = loopCounter >= 0 && loopCounter <= LINEAGE_MAX_LOOP_COUNTER ;
247
+
248
+ const isValidKey =
249
+ hashedResourceId . length === LINEAGE_HASH_LENGTH &&
250
+ ! ! hashedResourceId . match ( / ^ [ 0 - 9 a - f A - F ] + $ / ) ;
251
+ const isValidRequestCounter =
252
+ requestCounter >= 0 && requestCounter <= LINEAGE_MAX_REQUEST_COUNTER ;
253
+ const isValidLoopCounter =
254
+ loopCounter >= 0 && loopCounter <= LINEAGE_MAX_LOOP_COUNTER ;
247
255
248
256
return isValidKey && isValidRequestCounter && isValidLoopCounter ;
249
257
}
0 commit comments