MCPcopy Index your code
hub / github.com/aws/aws-lambda-rust-runtime / log_wrapper

Function log_wrapper

lambda-extension/src/logs.rs:193–231  ·  view source on GitHub ↗

Wrapper function that sends logs to the subscriber Service This takes an `hyper::Request` and transforms it into `Vec ` for the underlying `Service` to process.

(service: Arc<Mutex<S>>, req: Request<Incoming>)

Source from the content-addressed store, hash-verified

191/// This takes an `hyper::Request` and transforms it into `Vec<LambdaLog>` for the
192/// underlying `Service` to process.
193pub(crate) async fn log_wrapper<S>(service: Arc<Mutex<S>>, req: Request<Incoming>) -> Result<Response<Body>, Error>
194where
195 S: Service<Vec<LambdaLog>, Response = ()>,
196 S::Error: Into<Error> + fmt::Debug,
197 S::Future: Send,
198{
199 trace!("Received logs request");
200 // Parse the request body as a Vec<LambdaLog>
201 let body = match req.into_body().collect().await {
202 Ok(body) => body,
203 Err(e) => {
204 error!("Error reading logs request body: {}", e);
205 return Ok(hyper::Response::builder()
206 .status(hyper::StatusCode::BAD_REQUEST)
207 .body(Body::empty())
208 .unwrap());
209 }
210 };
211 let logs: Vec<LambdaLog> = match serde_json::from_slice(&body.to_bytes()) {
212 Ok(logs) => logs,
213 Err(e) => {
214 error!("Error parsing logs: {}", e);
215 return Ok(hyper::Response::builder()
216 .status(hyper::StatusCode::BAD_REQUEST)
217 .body(Body::empty())
218 .unwrap());
219 }
220 };
221
222 {
223 let mut service = service.lock().await;
224 match service.call(logs).await {
225 Ok(_) => (),
226 Err(err) => println!("{err:?}"),
227 }
228 }
229
230 Ok(hyper::Response::new(Body::empty()))
231}
232
233#[cfg(test)]
234mod tests {

Callers 1

registerMethod · 0.85

Calls 2

collectMethod · 0.80
callMethod · 0.45

Tested by

no test coverage detected