1
+ use opentelemetry:: propagation:: PropagationError ;
1
2
use opentelemetry:: {
2
3
global:: { self , Error } ,
3
4
propagation:: { text_map_propagator:: FieldIter , Extractor , Injector , TextMapPropagator } ,
@@ -6,7 +7,6 @@ use opentelemetry::{
6
7
} ;
7
8
use std:: borrow:: Cow ;
8
9
use std:: str:: FromStr ;
9
- use opentelemetry:: propagation:: PropagationError ;
10
10
11
11
const JAEGER_HEADER : & str = "uber-trace-id" ;
12
12
const JAEGER_BAGGAGE_PREFIX : & str = "uberctx-" ;
@@ -86,14 +86,24 @@ impl Propagator {
86
86
return None ;
87
87
}
88
88
89
- // extract trace id
90
- let trace_id = self . extract_trace_id ( parts[ 0 ] ) ?;
91
- let span_id = self . extract_span_id ( parts[ 1 ] ) ?;
92
- // Ignore parent span id since it's deprecated.
93
- let flags = self . extract_trace_flags ( parts[ 3 ] ) ?;
94
- let state = self . extract_trace_state ( extractor) ?;
95
-
96
- Some ( SpanContext :: new ( trace_id, span_id, flags, true , state) )
89
+ match (
90
+ self . extract_trace_id ( parts[ 0 ] ) ,
91
+ self . extract_span_id ( parts[ 1 ] ) ,
92
+ // Ignore parent span id since it's deprecated.
93
+ self . extract_trace_flags ( parts[ 3 ] ) ,
94
+ self . extract_trace_state ( extractor) ,
95
+ ) {
96
+ ( Ok ( trace_id) , Ok ( span_id) , Ok ( flags) , Ok ( state) ) => {
97
+ Some ( SpanContext :: new ( trace_id, span_id, flags, true , state) )
98
+ }
99
+ _ => {
100
+ global:: handle_error ( Error :: Propagation ( PropagationError :: extract (
101
+ "invalid jaeger header format" ,
102
+ "JaegerPropagator" ,
103
+ ) ) ) ;
104
+ None
105
+ }
106
+ }
97
107
}
98
108
99
109
/// Extract trace id from the header.
@@ -193,7 +203,7 @@ impl TextMapPropagator for Propagator {
193
203
fn extract_with_context ( & self , cx : & Context , extractor : & dyn Extractor ) -> Context {
194
204
self . extract_span_context ( extractor)
195
205
. map ( |sc| cx. with_remote_span_context ( sc) )
196
- . unwrap_or_else ( |_ | cx. clone ( ) )
206
+ . unwrap_or_else ( || cx. clone ( ) )
197
207
}
198
208
199
209
fn fields ( & self ) -> FieldIter < ' _ > {
@@ -435,7 +445,7 @@ mod tests {
435
445
) ;
436
446
assert_eq ! (
437
447
propagator_with_custom_header. extract_span_context( & map) ,
438
- Ok ( SpanContext :: new(
448
+ Some ( SpanContext :: new(
439
449
TraceId :: from_hex( "12345" ) . unwrap( ) ,
440
450
SpanId :: from_hex( "54321" ) . unwrap( ) ,
441
451
TRACE_FLAG_DEBUG | TraceFlags :: SAMPLED ,
@@ -452,7 +462,7 @@ mod tests {
452
462
) ;
453
463
assert_eq ! (
454
464
propagator_with_custom_header. extract_span_context( & map) ,
455
- Ok ( SpanContext :: new(
465
+ Some ( SpanContext :: new(
456
466
TraceId :: from_hex( "12345" ) . unwrap( ) ,
457
467
SpanId :: from_hex( "54321" ) . unwrap( ) ,
458
468
TRACE_FLAG_DEBUG | TraceFlags :: SAMPLED ,
@@ -468,7 +478,7 @@ mod tests {
468
478
) ;
469
479
assert_eq ! (
470
480
propagator_with_custom_header. extract_span_context( & map) ,
471
- Err ( ( ) )
481
+ None ,
472
482
) ;
473
483
474
484
map. clear ( ) ;
@@ -478,7 +488,7 @@ mod tests {
478
488
) ;
479
489
assert_eq ! (
480
490
propagator_with_custom_header. extract_span_context( & map) ,
481
- Err ( ( ) )
491
+ None ,
482
492
) ;
483
493
484
494
map. clear ( ) ;
@@ -488,7 +498,7 @@ mod tests {
488
498
) ;
489
499
assert_eq ! (
490
500
propagator_with_custom_header. extract_span_context( & map) ,
491
- Err ( ( ) )
501
+ None ,
492
502
) ;
493
503
494
504
map. clear ( ) ;
@@ -498,7 +508,7 @@ mod tests {
498
508
) ;
499
509
assert_eq ! (
500
510
propagator_with_custom_header. extract_span_context( & map) ,
501
- Err ( ( ) )
511
+ None ,
502
512
) ;
503
513
504
514
map. clear ( ) ;
@@ -511,7 +521,7 @@ mod tests {
511
521
map. set ( & too_long_baggage_key, "baggage_value" . to_owned ( ) ) ;
512
522
assert_eq ! (
513
523
propagator_with_custom_header. extract_span_context( & map) ,
514
- Err ( ( ) )
524
+ None ,
515
525
) ;
516
526
}
517
527
0 commit comments