File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change 1- use std:: env;
21use tower:: { Layer , Service } ;
32use tracing:: { instrument:: Instrumented , Instrument } ;
43
@@ -53,15 +52,13 @@ where
5352fn request_span ( ctx : & Context ) -> tracing:: Span {
5453 match & ctx. xray_trace_id {
5554 Some ( trace_id) => {
56- env:: set_var ( "_X_AMZN_TRACE_ID" , trace_id) ;
5755 tracing:: info_span!(
5856 "Lambda runtime invoke" ,
5957 requestId = & ctx. request_id,
6058 xrayTraceId = trace_id
6159 )
6260 }
6361 None => {
64- env:: remove_var ( "_X_AMZN_TRACE_ID" ) ;
6562 tracing:: info_span!( "Lambda runtime invoke" , requestId = & ctx. request_id)
6663 }
6764 }
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ use http_body_util::BodyExt;
66use lambda_runtime_api_client:: BoxError ;
77use lambda_runtime_api_client:: Client as ApiClient ;
88use serde:: { Deserialize , Serialize } ;
9+ use std:: env;
910use std:: fmt:: Debug ;
1011use std:: future:: Future ;
1112use std:: sync:: Arc ;
@@ -176,6 +177,9 @@ where
176177 let context = Context :: new ( invoke_request_id ( & parts. headers ) ?, config. clone ( ) , & parts. headers ) ?;
177178 let invocation = LambdaInvocation { parts, body, context } ;
178179
180+ // Setup Amazon's default tracing data
181+ amzn_trace_env ( & invocation. context ) ;
182+
179183 // Wait for service to be ready
180184 let ready = service. ready ( ) . await ?;
181185
@@ -232,6 +236,13 @@ fn incoming(
232236 }
233237}
234238
239+ fn amzn_trace_env ( ctx : & Context ) {
240+ match & ctx. xray_trace_id {
241+ Some ( trace_id) => env:: set_var ( "_X_AMZN_TRACE_ID" , trace_id) ,
242+ None => env:: remove_var ( "_X_AMZN_TRACE_ID" ) ,
243+ }
244+ }
245+
235246/* --------------------------------------------------------------------------------------------- */
236247/* TESTS */
237248/* --------------------------------------------------------------------------------------------- */
You can’t perform that action at this time.
0 commit comments