pub struct OtelTracingLayer<T: SpanAttributesExtractor> { /* private fields */ }Expand description
Tower middleware to create an OpenTelemetry tracing span for Lambda invocations.
This layer wraps a Lambda service to automatically create and configure OpenTelemetry spans for each invocation. It supports:
- Automatic span creation with configurable names
- Automatic attribute extraction from supported event types
- Context propagation from HTTP headers
- Response status tracking
§Example
use lambda_otel_lite::{init_telemetry, OtelTracingLayer, TelemetryConfig, SpanAttributes};
use lambda_runtime::{service_fn, Error, LambdaEvent, Runtime};
use aws_lambda_events::event::apigw::ApiGatewayV2httpRequest;
use tower::ServiceBuilder;
async fn handler(event: LambdaEvent<ApiGatewayV2httpRequest>) -> Result<serde_json::Value, Error> {
Ok(serde_json::json!({ "statusCode": 200 }))
}
let (_, completion_handler) = init_telemetry(TelemetryConfig::default()).await?;
// Create a layer with custom name
let layer = OtelTracingLayer::new(completion_handler)
.with_name("api-handler");
// Apply the layer to your handler
let service = ServiceBuilder::new()
.layer(layer)
.service_fn(handler);
Runtime::new(service).run().awaitImplementations§
Source§impl<T: SpanAttributesExtractor> OtelTracingLayer<T>
impl<T: SpanAttributesExtractor> OtelTracingLayer<T>
Sourcepub fn new(completion_handler: TelemetryCompletionHandler) -> Self
pub fn new(completion_handler: TelemetryCompletionHandler) -> Self
Create a new OpenTelemetry tracing layer with the required completion handler.
The completion handler is used to signal when spans should be exported. It’s typically
obtained from init_telemetry.
§Arguments
completion_handler- Handler for managing span export timing
Trait Implementations§
Source§impl<T: Clone + SpanAttributesExtractor> Clone for OtelTracingLayer<T>
impl<T: Clone + SpanAttributesExtractor> Clone for OtelTracingLayer<T>
Source§fn clone(&self) -> OtelTracingLayer<T>
fn clone(&self) -> OtelTracingLayer<T>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<S, T> Layer<S> for OtelTracingLayer<T>where
T: SpanAttributesExtractor + Clone,
impl<S, T> Layer<S> for OtelTracingLayer<T>where
T: SpanAttributesExtractor + Clone,
Auto Trait Implementations§
impl<T> Freeze for OtelTracingLayer<T>
impl<T> !RefUnwindSafe for OtelTracingLayer<T>
impl<T> Send for OtelTracingLayer<T>where
T: Send,
impl<T> Sync for OtelTracingLayer<T>where
T: Sync,
impl<T> Unpin for OtelTracingLayer<T>where
T: Unpin,
impl<T> !UnwindSafe for OtelTracingLayer<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request