@@ -16,12 +16,12 @@ use aws_lambda_events::apigw::{ApiGatewayV2httpRequest, ApiGatewayV2httpRequestC
16
16
use aws_lambda_events:: apigw:: { ApiGatewayWebsocketProxyRequest , ApiGatewayWebsocketProxyRequestContext } ;
17
17
use aws_lambda_events:: { encodings:: Body , query_map:: QueryMap } ;
18
18
use http:: header:: HeaderName ;
19
- use http:: HeaderMap ;
19
+ use http:: { HeaderMap , HeaderValue } ;
20
20
use serde:: Deserialize ;
21
21
use serde_json:: error:: Error as JsonError ;
22
22
use std:: future:: Future ;
23
23
use std:: pin:: Pin ;
24
- use std:: { io:: Read , mem} ;
24
+ use std:: { env , io:: Read , mem} ;
25
25
use url:: Url ;
26
26
27
27
/// Internal representation of an Lambda http event from
@@ -119,8 +119,9 @@ fn into_api_gateway_v2_request(ag: ApiGatewayV2httpRequest) -> http::Request<Bod
119
119
. extension ( RequestContext :: ApiGatewayV2 ( ag. request_context ) ) ;
120
120
121
121
let mut headers = ag. headers ;
122
+ update_xray_trace_id_header ( & mut headers) ;
122
123
if let Some ( cookies) = ag. cookies {
123
- if let Ok ( header_value) = http :: header :: HeaderValue :: from_str ( & cookies. join ( ";" ) ) {
124
+ if let Ok ( header_value) = HeaderValue :: from_str ( & cookies. join ( ";" ) ) {
124
125
headers. append ( http:: header:: COOKIE , header_value) ;
125
126
}
126
127
}
@@ -142,6 +143,13 @@ fn into_api_gateway_v2_request(ag: ApiGatewayV2httpRequest) -> http::Request<Bod
142
143
req
143
144
}
144
145
146
+ fn update_xray_trace_id_header ( headers : & mut HeaderMap ) {
147
+ if let Ok ( xray_trace_id) = env:: var ( "_X_AMZN_TRACE_ID" ) {
148
+ if let Ok ( header_value) = HeaderValue :: from_str ( & xray_trace_id) {
149
+ headers. insert ( HeaderName :: from_static ( "x-amzn-trace-id" ) , header_value) ;
150
+ }
151
+ }
152
+ }
145
153
#[ cfg( feature = "apigw_rest" ) ]
146
154
fn into_proxy_request ( ag : ApiGatewayProxyRequest ) -> http:: Request < Body > {
147
155
let http_method = ag. http_method ;
@@ -179,6 +187,7 @@ fn into_proxy_request(ag: ApiGatewayProxyRequest) -> http::Request<Body> {
179
187
// multi-value_headers our cannoncial source of request headers
180
188
let mut headers = ag. multi_value_headers ;
181
189
headers. extend ( ag. headers ) ;
190
+ update_xray_trace_id_header ( & mut headers) ;
182
191
183
192
let base64 = ag. is_base64_encoded . unwrap_or_default ( ) ;
184
193
let mut req = builder
@@ -229,6 +238,7 @@ fn into_alb_request(alb: AlbTargetGroupRequest) -> http::Request<Body> {
229
238
// multi-value_headers our cannoncial source of request headers
230
239
let mut headers = alb. multi_value_headers ;
231
240
headers. extend ( alb. headers ) ;
241
+ update_xray_trace_id_header ( & mut headers) ;
232
242
233
243
let base64 = alb. is_base64_encoded ;
234
244
@@ -291,6 +301,7 @@ fn into_websocket_request(ag: ApiGatewayWebsocketProxyRequest) -> http::Request<
291
301
// multi-value_headers our cannoncial source of request headers
292
302
let mut headers = ag. multi_value_headers ;
293
303
headers. extend ( ag. headers ) ;
304
+ update_xray_trace_id_header ( & mut headers) ;
294
305
295
306
let base64 = ag. is_base64_encoded . unwrap_or_default ( ) ;
296
307
let mut req = builder
0 commit comments