pub struct TracingLayer<F: Fn() + Clone, I: Instrumentor> { /* private fields */ }Expand description
Tower Layer that wraps the Lambda runtime service with per-invocation OTel spans.
TracingLayer intercepts each LambdaInvocation and:
- Parses the
_X_AMZN_TRACE_IDheader and propagates the X-Ray trace context into the new span. - Creates a
SERVER-kind span named after the Lambda function with thefaas.trigger,faas.invocation_id,faas.coldstart,cloud.account.id, andcloud.resource_idattributes. - Wraps the invocation future in a
FlushedFuturethat calls the flush callback when the future drops, ensuring the exporter is flushed even when the invocation is cancelled.
Use DefaultTracingLayer to avoid specifying the I type parameter
explicitly.
§Examples
use awssdk_instrumentation::lambda::layer::DefaultTracingLayer;
use awssdk_instrumentation::lambda::OTelFaasTrigger;
let layer = DefaultTracingLayer::new(|| { /* flush */ })
.with_trigger(OTelFaasTrigger::Datasource);Implementations§
Source§impl<F: Fn() + Clone, I: Instrumentor> TracingLayer<F, I>
impl<F: Fn() + Clone, I: Instrumentor> TracingLayer<F, I>
Sourcepub fn new(flush_fn: F) -> Self
pub fn new(flush_fn: F) -> Self
Creates a new TracingLayer with the given flush callback.
The flush_fn is called synchronously in the Drop impl of
FlushedFuture after each invocation completes or is cancelled. Use
it to call tracer_provider.force_flush().
The faas.trigger attribute defaults to OTelFaasTrigger::Datasource.
Call with_trigger to override it.
§Examples
use awssdk_instrumentation::lambda::layer::DefaultTracingLayer;
let layer = DefaultTracingLayer::new(|| { /* flush */ });Sourcepub fn with_trigger(self, trigger: OTelFaasTrigger) -> Self
pub fn with_trigger(self, trigger: OTelFaasTrigger) -> Self
Sets the faas.trigger OTel attribute for every invocation span.
§Examples
use awssdk_instrumentation::lambda::layer::DefaultTracingLayer;
use awssdk_instrumentation::lambda::OTelFaasTrigger;
let layer = DefaultTracingLayer::new(|| { /* flush */ })
.with_trigger(OTelFaasTrigger::Http);Trait Implementations§
Source§impl<S, F: Fn() + Clone, I: Instrumentor> Layer<S> for TracingLayer<F, I>
Wraps the Lambda runtime service S with per-invocation OTel instrumentation.
impl<S, F: Fn() + Clone, I: Instrumentor> Layer<S> for TracingLayer<F, I>
Wraps the Lambda runtime service S with per-invocation OTel instrumentation.
Auto Trait Implementations§
impl<F, I> Freeze for TracingLayer<F, I>where
F: Freeze,
impl<F, I> RefUnwindSafe for TracingLayer<F, I>where
F: RefUnwindSafe,
I: RefUnwindSafe,
impl<F, I> Send for TracingLayer<F, I>
impl<F, I> Sync for TracingLayer<F, I>
impl<F, I> Unpin for TracingLayer<F, I>
impl<F, I> UnsafeUnpin for TracingLayer<F, I>where
F: UnsafeUnpin,
impl<F, I> UnwindSafe for TracingLayer<F, I>where
F: UnwindSafe,
I: UnwindSafe,
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> 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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.