@@ -5,6 +5,13 @@ use std::{
55} ;
66
77use chrono:: { DateTime , Utc } ;
8+ use datadog_opentelemetry:: propagation:: {
9+ context:: SpanContext ,
10+ datadog:: {
11+ DATADOG_PARENT_ID_KEY , DATADOG_SAMPLING_PRIORITY_KEY , DATADOG_TAGS_KEY ,
12+ DATADOG_TRACE_ID_KEY ,
13+ } ,
14+ } ;
815use libdd_trace_protobuf:: pb:: Span ;
916use libdd_trace_utils:: tracer_header_tags;
1017use serde_json:: Value ;
@@ -31,14 +38,7 @@ use crate::{
3138 } ,
3239 tags:: { lambda:: tags:: resolve_runtime_from_proc, provider} ,
3340 traces:: {
34- context:: SpanContext ,
35- propagation:: {
36- DatadogCompositePropagator , Propagator ,
37- text_map_propagator:: {
38- DATADOG_PARENT_ID_KEY , DATADOG_SAMPLING_PRIORITY_KEY , DATADOG_SPAN_ID_KEY ,
39- DATADOG_TRACE_ID_KEY , DatadogHeaderPropagator ,
40- } ,
41- } ,
41+ propagation:: { DatadogCompositePropagator , carrier:: JsonCarrier } ,
4242 trace_processor:: SendingTraceProcessor ,
4343 } ,
4444} ;
@@ -52,6 +52,7 @@ pub const DATADOG_INVOCATION_ERROR_MESSAGE_KEY: &str = "x-datadog-invocation-err
5252pub const DATADOG_INVOCATION_ERROR_TYPE_KEY : & str = "x-datadog-invocation-error-type" ;
5353pub const DATADOG_INVOCATION_ERROR_STACK_KEY : & str = "x-datadog-invocation-error-stack" ;
5454pub const DATADOG_INVOCATION_ERROR_KEY : & str = "x-datadog-invocation-error" ;
55+ const DATADOG_SPAN_ID_KEY : & str = "x-datadog-span-id" ;
5556const TAG_SAMPLING_PRIORITY : & str = "_sampling_priority_v1" ;
5657
5758pub struct Processor {
@@ -979,7 +980,7 @@ impl Processor {
979980
980981 // Set the extracted trace context to the spans
981982 if let Some ( sc) = & context. extracted_span_context {
982- context. invocation_span . trace_id = sc. trace_id ;
983+ context. invocation_span . trace_id = sc. trace_id as u64 ;
983984 context. invocation_span . parent_id = sc. span_id ;
984985
985986 // Set the right data to the correct root level span,
@@ -1082,7 +1083,7 @@ impl Processor {
10821083 pub fn extract_span_context (
10831084 headers : & HashMap < String , String > ,
10841085 payload_value : & Value ,
1085- propagator : Arc < impl Propagator > ,
1086+ propagator : Arc < DatadogCompositePropagator > ,
10861087 ) -> Option < SpanContext > {
10871088 if let Some ( sc) =
10881089 span_inferrer:: extract_span_context ( payload_value, Arc :: clone ( & propagator) )
@@ -1093,14 +1094,14 @@ impl Processor {
10931094 if let Some ( sc) = payload_value
10941095 . get ( "request" )
10951096 . and_then ( |req| req. get ( "headers" ) )
1096- . and_then ( |headers| propagator. extract ( headers) )
1097+ . and_then ( |headers| propagator. extract ( & JsonCarrier ( headers) ) )
10971098 {
10981099 debug ! ( "Extracted trace context from event.request.headers" ) ;
10991100 return Some ( sc) ;
11001101 }
11011102
11021103 if let Some ( payload_headers) = payload_value. get ( "headers" )
1103- && let Some ( sc) = propagator. extract ( payload_headers)
1104+ && let Some ( sc) = propagator. extract ( & JsonCarrier ( payload_headers) )
11041105 {
11051106 debug ! ( "Extracted trace context from event headers" ) ;
11061107 return Some ( sc) ;
@@ -1202,14 +1203,14 @@ impl Processor {
12021203 self . inferrer . set_status_code ( status_code_as_string) ;
12031204 }
12041205
1205- let mut trace_id = 0 ;
1206- let mut parent_id = 0 ;
1206+ let mut trace_id: u64 = 0 ;
1207+ let mut parent_id: u64 = 0 ;
12071208 let mut tags: HashMap < String , String > = HashMap :: new ( ) ;
12081209
12091210 // If we have a trace context, this means we got it from
12101211 // distributed tracing
12111212 if let Some ( sc) = & context. extracted_span_context {
1212- trace_id = sc. trace_id ;
1213+ trace_id = sc. trace_id as u64 ;
12131214 parent_id = sc. span_id ;
12141215 tags. extend ( sc. tags . clone ( ) ) ;
12151216 }
@@ -1235,9 +1236,8 @@ impl Processor {
12351236 . insert ( TAG_SAMPLING_PRIORITY . to_string ( ) , priority) ;
12361237 }
12371238
1238- // Extract tags from headers
1239- // Used for 128 bit trace ids
1240- tags = DatadogHeaderPropagator :: extract_tags ( & headers) ;
1239+ // Extract _dd.p.* propagation tags from x-datadog-tags header
1240+ tags = extract_propagation_tags ( & headers) ;
12411241 }
12421242
12431243 // We should always use the generated span id from the tracer
@@ -1344,6 +1344,21 @@ impl Processor {
13441344 }
13451345}
13461346
1347+ fn extract_propagation_tags ( carrier : & HashMap < String , String > ) -> HashMap < String , String > {
1348+ let carrier_tags = carrier. get ( DATADOG_TAGS_KEY ) . map_or ( "" , String :: as_str) ;
1349+ carrier_tags
1350+ . split ( ',' )
1351+ . filter_map ( |pair| {
1352+ let ( k, v) = pair. split_once ( '=' ) ?;
1353+ if k. starts_with ( "_dd.p." ) {
1354+ Some ( ( k. to_string ( ) , v. to_string ( ) ) )
1355+ } else {
1356+ None
1357+ }
1358+ } )
1359+ . collect ( )
1360+ }
1361+
13471362#[ cfg( test) ]
13481363#[ allow( clippy:: unwrap_used) ]
13491364mod tests {
@@ -2048,8 +2063,8 @@ mod tests {
20482063 fn test_extract_span_context_priority_order ( ) {
20492064 let config = Arc :: new ( config:: Config {
20502065 trace_propagation_style_extract : vec ! [
2051- config :: trace_propagation_style :: TracePropagationStyle :: Datadog ,
2052- config :: trace_propagation_style :: TracePropagationStyle :: TraceContext ,
2066+ datadog_opentelemetry :: propagation :: TracePropagationStyle :: Datadog ,
2067+ datadog_opentelemetry :: propagation :: TracePropagationStyle :: TraceContext ,
20532068 ] ,
20542069 ..config:: Config :: default ( )
20552070 } ) ;
@@ -2086,8 +2101,8 @@ mod tests {
20862101 fn test_extract_span_context_no_request_headers ( ) {
20872102 let config = Arc :: new ( config:: Config {
20882103 trace_propagation_style_extract : vec ! [
2089- config :: trace_propagation_style :: TracePropagationStyle :: Datadog ,
2090- config :: trace_propagation_style :: TracePropagationStyle :: TraceContext ,
2104+ datadog_opentelemetry :: propagation :: TracePropagationStyle :: Datadog ,
2105+ datadog_opentelemetry :: propagation :: TracePropagationStyle :: TraceContext ,
20912106 ] ,
20922107 ..config:: Config :: default ( )
20932108 } ) ;
0 commit comments