@@ -31,31 +31,19 @@ use anyhow::anyhow;
31
31
use http:: header:: Entry ;
32
32
use lambda_http:: http:: response:: Parts ;
33
33
use lambda_http:: http:: HeaderValue ;
34
- use lambda_http:: request:: RequestContext ;
35
34
use lambda_http:: {
36
35
lambda_runtime, Adapter , Body as LambdaBody , Error as LambdaError , Request , RequestExt ,
37
36
Response , Service ,
38
37
} ;
39
38
use mime_guess:: { mime, Mime } ;
40
39
use once_cell:: sync:: Lazy ;
40
+ use tracing:: { info_span, Instrument } ;
41
41
use warp:: hyper:: Body as WarpBody ;
42
42
pub use { lambda_http, warp} ;
43
43
44
- use super :: LAMBDA_REQUEST_ID_HEADER ;
45
-
46
44
pub type WarpRequest = warp:: http:: Request < warp:: hyper:: Body > ;
47
45
pub type WarpResponse = warp:: http:: Response < warp:: hyper:: Body > ;
48
46
49
- #[ derive( thiserror:: Error , Debug ) ]
50
- pub enum WarpAdapterError {
51
- #[ error( "This may never occur, it's infallible!!" ) ]
52
- Infallible ( #[ from] std:: convert:: Infallible ) ,
53
- #[ error( "Warp error: `{0:#?}`" ) ]
54
- HyperError ( #[ from] warp:: hyper:: Error ) ,
55
- #[ error( "Unexpected error: `{0:#?}`" ) ]
56
- Unexpected ( #[ from] LambdaError ) ,
57
- }
58
-
59
47
pub async fn run < ' a , S > ( service : S ) -> Result < ( ) , LambdaError >
60
48
where
61
49
S : Service < WarpRequest , Response = WarpResponse , Error = Infallible > + Send + ' a ,
@@ -141,18 +129,7 @@ where
141
129
142
130
fn call ( & mut self , req : Request ) -> Self :: Future {
143
131
let query_params = req. query_string_parameters ( ) ;
144
- let request_id_opt = match req. request_context ( ) {
145
- RequestContext :: ApiGatewayV2 ( ctx) => ctx. request_id . clone ( ) ,
146
- RequestContext :: ApiGatewayV1 ( ctx) => ctx. request_id . clone ( ) ,
147
- RequestContext :: Alb ( _) => None ,
148
- RequestContext :: WebSocket ( ctx) => ctx. request_id . clone ( ) ,
149
- } ;
150
- let request_id_header_opt = match request_id_opt. as_ref ( ) . map ( |a| HeaderValue :: from_str ( a) )
151
- {
152
- Some ( Ok ( rid) ) => Some ( rid) ,
153
- Some ( Err ( _) ) => None ,
154
- None => None ,
155
- } ;
132
+ let request_id = req. lambda_context ( ) . request_id . clone ( ) ;
156
133
let ( mut parts, body) = req. into_parts ( ) ;
157
134
let ( content_len, body) = match body {
158
135
LambdaBody :: Empty => ( 0 , WarpBody :: empty ( ) ) ,
@@ -175,9 +152,6 @@ where
175
152
if let Entry :: Vacant ( v) = parts. headers . entry ( "Content-Length" ) {
176
153
v. insert ( content_len. into ( ) ) ;
177
154
}
178
- if let Some ( rid) = & request_id_header_opt {
179
- parts. headers . insert ( LAMBDA_REQUEST_ID_HEADER , rid. clone ( ) ) ;
180
- }
181
155
182
156
parts. uri = warp:: hyper:: Uri :: from_str ( uri. as_str ( ) )
183
157
. map_err ( |e| e)
@@ -190,14 +164,12 @@ where
190
164
// Create lambda future
191
165
let fut = async move {
192
166
let warp_response = warp_fut. await ?;
193
- let ( mut parts, res_body) : ( _ , _ ) = warp_response. into_parts ( ) ;
167
+ let ( parts, res_body) : ( _ , _ ) = warp_response. into_parts ( ) ;
194
168
let body = warp_body_as_lambda_body ( res_body, & parts) . await ?;
195
- if let Some ( rid) = request_id_header_opt {
196
- parts. headers . insert ( LAMBDA_REQUEST_ID_HEADER , rid) ;
197
- }
198
169
let lambda_response = Response :: from_parts ( parts, body) ;
199
170
Ok :: < Self :: Response , Self :: Error > ( lambda_response)
200
- } ;
171
+ }
172
+ . instrument ( info_span ! ( "searcher request" , request_id) ) ;
201
173
Box :: pin ( fut)
202
174
}
203
175
}
0 commit comments