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
Arcfor shared ownership of the tracer provider - Implements proper synchronization through
Mutexfor 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
impl OtelInternalExtension
Sourcepub fn new(
request_done_receiver: UnboundedReceiver<()>,
tracer_provider: Arc<SdkTracerProvider>,
) -> Self
pub fn new( request_done_receiver: UnboundedReceiver<()>, tracer_provider: Arc<SdkTracerProvider>, ) -> Self
Creates a new OtelInternalExtension.
§Arguments
request_done_receiver- Channel receiver for completion signalstracer_provider- TracerProvider for span management
Sourcepub async fn invoke(&self, event: LambdaEvent) -> Result<(), Error>
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
-
Event Reception:
- Receives Lambda extension events
- Filters for INVOKE events
- Ignores other event types
-
Handler Coordination:
- Waits for handler completion signal
- Uses async channel communication
- Handles channel closure gracefully
-
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§
impl !Freeze for OtelInternalExtension
impl !RefUnwindSafe for OtelInternalExtension
impl Send for OtelInternalExtension
impl Sync for OtelInternalExtension
impl Unpin for OtelInternalExtension
impl !UnwindSafe for OtelInternalExtension
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
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>
T in a tonic::Request