Struct OtelInternalExtension

Source
pub struct OtelInternalExtension { /* private fields */ }
Expand description

Extension that flushes OpenTelemetry spans after each Lambda invocation.

This extension is responsible for:

  • Receiving completion signals from the handler
  • Flushing spans at the appropriate time
  • Managing the lifecycle of the tracer provider

§Thread Safety

The extension is designed to be thread-safe:

  • Uses Arc for shared ownership of the tracer provider
  • Implements proper synchronization through Mutex for the channel receiver
  • Safely handles concurrent access from multiple tasks

§Performance Characteristics

The extension is optimized for Lambda environments:

  • Minimizes memory usage through efficient buffering
  • Uses non-blocking channel communication
  • Implements backpressure handling to prevent memory exhaustion

§Error Handling

The extension handles various error scenarios:

  • Channel closed: Logs error and continues processing
  • Export failures: Logs errors without failing the function
  • Shutdown signals: Ensures final flush of spans

The extension operates asynchronously to minimize impact on handler latency. It uses a channel-based communication pattern to coordinate with the handler.

Implementations§

Source§

impl OtelInternalExtension

Source

pub fn new( request_done_receiver: UnboundedReceiver<()>, tracer_provider: Arc<SdkTracerProvider>, ) -> Self

Creates a new OtelInternalExtension.

§Arguments
  • request_done_receiver - Channel receiver for completion signals
  • tracer_provider - TracerProvider for span management
Source

pub async fn invoke(&self, event: LambdaEvent) -> Result<(), Error>

Handles extension events and flushes telemetry after each invocation.

This method implements the core event handling logic for the extension. It coordinates with the Lambda function handler to ensure spans are exported at the appropriate time.

§Operation Flow
  1. Event Reception:

    • Receives Lambda extension events
    • Filters for INVOKE events
    • Ignores other event types
  2. Handler Coordination:

    • Waits for handler completion signal
    • Uses async channel communication
    • Handles channel closure gracefully
  3. Span Export:

    • Forces flush of all pending spans
    • Handles export errors without failing
    • Logs any export failures
§Error Handling

The method handles several failure scenarios:

  • Channel Errors:

    • Channel closure: Returns error with descriptive message
    • Send/receive failures: Properly propagated
  • Export Errors:

    • Individual span export failures are logged
    • Continues processing despite errors
    • Maintains extension stability
§Performance

The method is optimized for Lambda environments:

  • Uses async/await for efficient execution
  • Minimizes blocking operations
  • Implements proper error recovery
§Arguments
  • event - The Lambda extension event to handle
§Returns

Returns Ok(()) if the event was processed successfully, or an Error if something went wrong during processing. Note that export errors are logged but do not cause the method to return an error.

Auto Trait Implementations§

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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
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