Skip to main content

TracingLayer

Struct TracingLayer 

Source
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:

  1. Parses the _X_AMZN_TRACE_ID header and propagates the X-Ray trace context into the new span.
  2. Creates a SERVER-kind span named after the Lambda function with the faas.trigger, faas.invocation_id, faas.coldstart, cloud.account.id, and cloud.resource_id attributes.
  3. Wraps the invocation future in a FlushedFuture that 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>

Source

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 */ });
Source

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.

Source§

type Service = TracingService<I, S, F>

The wrapped service
Source§

fn layer(&self, inner: S) -> Self::Service

Wrap the given service with the middleware, returning a new service that has been decorated with the middleware.

Auto Trait Implementations§

§

impl<F, I> Freeze for TracingLayer<F, I>
where F: Freeze,

§

impl<F, I> RefUnwindSafe for TracingLayer<F, I>

§

impl<F, I> Send for TracingLayer<F, I>
where F: Send, I: Send,

§

impl<F, I> Sync for TracingLayer<F, I>
where F: Sync, I: Sync,

§

impl<F, I> Unpin for TracingLayer<F, I>
where F: Unpin, I: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more