File tree 2 files changed +11
-3
lines changed
2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change 1
- use std:: env;
2
1
use tower:: { Layer , Service } ;
3
2
use tracing:: { instrument:: Instrumented , Instrument } ;
4
3
@@ -53,15 +52,13 @@ where
53
52
fn request_span ( ctx : & Context ) -> tracing:: Span {
54
53
match & ctx. xray_trace_id {
55
54
Some ( trace_id) => {
56
- env:: set_var ( "_X_AMZN_TRACE_ID" , trace_id) ;
57
55
tracing:: info_span!(
58
56
"Lambda runtime invoke" ,
59
57
requestId = & ctx. request_id,
60
58
xrayTraceId = trace_id
61
59
)
62
60
}
63
61
None => {
64
- env:: remove_var ( "_X_AMZN_TRACE_ID" ) ;
65
62
tracing:: info_span!( "Lambda runtime invoke" , requestId = & ctx. request_id)
66
63
}
67
64
}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ use http_body_util::BodyExt;
6
6
use lambda_runtime_api_client:: BoxError ;
7
7
use lambda_runtime_api_client:: Client as ApiClient ;
8
8
use serde:: { Deserialize , Serialize } ;
9
+ use std:: env;
9
10
use std:: fmt:: Debug ;
10
11
use std:: future:: Future ;
11
12
use std:: sync:: Arc ;
@@ -176,6 +177,9 @@ where
176
177
let context = Context :: new ( invoke_request_id ( & parts. headers ) ?, config. clone ( ) , & parts. headers ) ?;
177
178
let invocation = LambdaInvocation { parts, body, context } ;
178
179
180
+ // Setup Amazon's default tracing data
181
+ amzn_trace_env ( & invocation. context ) ;
182
+
179
183
// Wait for service to be ready
180
184
let ready = service. ready ( ) . await ?;
181
185
@@ -232,6 +236,13 @@ fn incoming(
232
236
}
233
237
}
234
238
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
+
235
246
/* --------------------------------------------------------------------------------------------- */
236
247
/* TESTS */
237
248
/* --------------------------------------------------------------------------------------------- */
You can’t perform that action at this time.
0 commit comments