pub struct TelemetryCompletionHandler { /* private fields */ }Expand description
A handler that ensures telemetry data is properly exported upon Lambda function completion.
This type manages the completion of telemetry data export based on the configured mode:
-
In
Syncmode, directly exports the data in the handler thread- Simple execution path with no IPC overhead
- Efficient for small payloads and low resource environments
- Guarantees span delivery before response
-
In
Asyncmode, notifies the internal extension to export the data- Requires coordination with extension process
- Additional overhead from IPC
- Provides retry capabilities through extension
-
In
Finalizemode, lets the processor handle the export strategy- Full control over export timing and behavior
- Compatible with BatchSpanProcessor
- Best for specialized export requirements
§Thread Safety
The handler is thread-safe and can be cloned and shared between threads.
§Example
use lambda_otel_lite::{init_telemetry, TelemetryConfig};
use lambda_runtime::{service_fn, Error, LambdaEvent};
async fn handler(event: LambdaEvent<serde_json::Value>) -> Result<serde_json::Value, Error> {
// ... handler logic ...
Ok(event.payload)
}
#[tokio::main]
async fn main() -> Result<(), Error> {
let completion_handler = init_telemetry(TelemetryConfig::default()).await?;
lambda_runtime::run(service_fn(|event| async {
let result = handler(event).await;
completion_handler.complete();
result
})).await
}Implementations§
Source§impl TelemetryCompletionHandler
impl TelemetryCompletionHandler
Sourcepub fn mode(&self) -> ProcessorMode
pub fn mode(&self) -> ProcessorMode
Returns the current processor mode
Sourcepub fn provider(&self) -> &Arc<SdkTracerProvider>
pub fn provider(&self) -> &Arc<SdkTracerProvider>
Get a reference to the tracer provider
Sourcepub fn complete(&self)
pub fn complete(&self)
Signals completion of the current Lambda invocation, triggering telemetry export.
The behavior depends on the processor mode:
-
In
Syncmode:- Directly exports spans in the handler thread
- Simple execution path with no IPC overhead
- Blocks until export completes
- Best for small payloads or when immediate delivery is required
-
In
Asyncmode:- Notifies the extension to handle export
- Non-blocking operation in handler thread
- Requires coordination with extension process
- Provides retry capabilities through extension
-
In
Finalizemode:- Lets the configured processor handle export
- Behavior depends on processor implementation
- Useful for custom export strategies
- No additional action taken by handler
Sourcepub fn force_export(&self)
pub fn force_export(&self)
Forces immediate export of all telemetry data, regardless of mode.
This is useful when you need to ensure all telemetry data is exported immediately, such as during shutdown or error handling.
Trait Implementations§
Source§impl Clone for TelemetryCompletionHandler
impl Clone for TelemetryCompletionHandler
Source§fn clone(&self) -> TelemetryCompletionHandler
fn clone(&self) -> TelemetryCompletionHandler
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for TelemetryCompletionHandler
impl !RefUnwindSafe for TelemetryCompletionHandler
impl Send for TelemetryCompletionHandler
impl Sync for TelemetryCompletionHandler
impl Unpin for TelemetryCompletionHandler
impl !UnwindSafe for TelemetryCompletionHandler
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> 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>
T in a tonic::Request