@@ -11,6 +11,8 @@ use serde_json::Value;
1111use tokio:: time:: Instant ;
1212use tracing:: { debug, trace, warn} ;
1313
14+ use tokio:: sync:: mpsc;
15+
1416use crate :: {
1517 config:: { self , aws:: AwsConfig } ,
1618 extension:: telemetry:: events:: {
@@ -24,6 +26,7 @@ use crate::{
2426 span_inferrer:: { self , SpanInferrer } ,
2527 triggers:: get_default_service_name,
2628 } ,
29+ logs:: agent:: DurableContextUpdate ,
2730 metrics:: enhanced:: lambda:: { EnhancedMetricData , Lambda as EnhancedMetrics } ,
2831 proc:: {
2932 self , CPUData , NetworkData ,
@@ -88,6 +91,10 @@ pub struct Processor {
8891 /// Tracks whether if first invocation after init has been received in Managed Instance mode.
8992 /// Used to determine if we should search for the empty context on an invocation.
9093 awaiting_first_invocation : bool ,
94+ /// Sender used to forward durable execution context extracted from `aws.lambda` spans to the
95+ /// logs pipeline. Decouples the trace agent from the logs agent: the trace agent sends spans
96+ /// to the lifecycle processor, which extracts durable context and relays it here.
97+ durable_context_tx : mpsc:: Sender < DurableContextUpdate > ,
9198}
9299
93100impl Processor {
@@ -98,6 +105,7 @@ impl Processor {
98105 aws_config : Arc < AwsConfig > ,
99106 metrics_aggregator : dogstatsd:: aggregator:: AggregatorHandle ,
100107 propagator : Arc < DatadogCompositePropagator > ,
108+ durable_context_tx : mpsc:: Sender < DurableContextUpdate > ,
101109 ) -> Self {
102110 let resource = tags_provider
103111 . get_canonical_resource_name ( )
@@ -127,6 +135,7 @@ impl Processor {
127135 dynamic_tags : HashMap :: new ( ) ,
128136 active_invocations : 0 ,
129137 awaiting_first_invocation : false ,
138+ durable_context_tx,
130139 }
131140 }
132141
@@ -1337,10 +1346,27 @@ impl Processor {
13371346 ///
13381347 /// This is used to enrich the invocation span with additional metadata from the tracers
13391348 /// top level span, since we discard the tracer span when we create the invocation span.
1349+ ///
1350+ /// Also forwards durable execution context to the logs pipeline when the span carries
1351+ /// `durable_function_execution_id` and `durable_function_execution_name` metadata.
13401352 pub fn add_tracer_span ( & mut self , span : & Span ) {
13411353 if let Some ( request_id) = span. meta . get ( "request_id" ) {
13421354 self . context_buffer . add_tracer_span ( request_id, span) ;
13431355 }
1356+
1357+ if let ( Some ( request_id) , Some ( exec_id) , Some ( exec_name) ) = (
1358+ span. meta . get ( "request_id" ) ,
1359+ span. meta . get ( "durable_function_execution_id" ) ,
1360+ span. meta . get ( "durable_function_execution_name" ) ,
1361+ ) {
1362+ if let Err ( e) = self . durable_context_tx . try_send ( (
1363+ request_id. clone ( ) ,
1364+ exec_id. clone ( ) ,
1365+ exec_name. clone ( ) ,
1366+ ) ) {
1367+ warn ! ( "LIFECYCLE | Failed to forward durable context to logs pipeline: {e}" ) ;
1368+ }
1369+ }
13441370 }
13451371}
13461372
@@ -1387,7 +1413,8 @@ mod tests {
13871413 tokio:: spawn ( service. run ( ) ) ;
13881414
13891415 let propagator = Arc :: new ( DatadogCompositePropagator :: new ( Arc :: clone ( & config) ) ) ;
1390- Processor :: new ( tags_provider, config, aws_config, handle, propagator)
1416+ let ( durable_context_tx, _) = tokio:: sync:: mpsc:: channel ( 1 ) ;
1417+ Processor :: new ( tags_provider, config, aws_config, handle, propagator, durable_context_tx)
13911418 }
13921419
13931420 #[ test]
@@ -1924,7 +1951,8 @@ mod tests {
19241951
19251952 let propagator = Arc :: new ( DatadogCompositePropagator :: new ( Arc :: clone ( & config) ) ) ;
19261953
1927- let processor = Processor :: new ( tags_provider, config, aws_config, handle, propagator) ;
1954+ let ( durable_context_tx, _) = tokio:: sync:: mpsc:: channel ( 1 ) ;
1955+ let processor = Processor :: new ( tags_provider, config, aws_config, handle, propagator, durable_context_tx) ;
19281956
19291957 assert ! (
19301958 processor. is_managed_instance_mode( ) ,
0 commit comments