Module lambda_http

Module lambda_http 

Source
Expand description

Extractor for lambda_http crate integration.

Provides trace context extraction from [lambda_http::request::LambdaRequest], enabling seamless integration with the lambda_http crate’s tower middleware pattern.

§Example

use lambda_http::{Body, Error, Request, Response};
use opentelemetry_lambda_tower::{LambdaHttpExtractor, OtelTracingLayer};
use tower::ServiceBuilder;

async fn handler(event: Request) -> Result<Response<Body>, Error> {
    Ok(Response::builder().status(200).body("Hello".into())?)
}

#[tokio::main]
async fn main() -> Result<(), Error> {
    let tracing_layer = OtelTracingLayer::new(LambdaHttpExtractor::new());

    let service = ServiceBuilder::new()
        .layer(tracing_layer)
        .layer_fn(lambda_http::Adapter::from)
        .service_fn(handler);

    lambda_runtime::run(service).await
}

Structs§

LambdaHttpExtractor
Extractor for lambda_http::request::LambdaRequest.