pub enum ProcessorMode {
Sync,
Async,
Finalize,
}Expand description
Controls how spans are processed and exported.
This enum determines when and how OpenTelemetry spans are flushed from the buffer to the configured exporter. Each mode offers different tradeoffs between latency, reliability, and flexibility.
§Modes
-
Sync: Immediate flush in handler thread- Spans are flushed before handler returns
- Direct export without extension coordination
- May be more efficient for small payloads and low memory configurations
- Guarantees span delivery before response
-
Async: Flush via Lambda extension- Spans are flushed after handler returns
- Requires coordination with extension process
- Additional overhead from IPC with extension
- Provides retry capabilities through extension
-
Finalize: Delegated to processor- Spans handled by configured processor
- Compatible with BatchSpanProcessor
- Best for custom export strategies
- Full control over export timing
§Configuration
The mode can be configured in two ways:
-
Using the
LAMBDA_EXTENSION_SPAN_PROCESSOR_MODEenvironment variable:- “sync” for Sync mode (default)
- “async” for Async mode
- “finalize” for Finalize mode
-
Programmatically through
TelemetryConfig:use lambda_otel_lite::{ProcessorMode, TelemetryConfig}; let config = TelemetryConfig::builder() .processor_mode(ProcessorMode::Async) .build();
The environment variable takes precedence over programmatic configuration.
§Example
use lambda_otel_lite::ProcessorMode;
use std::env;
// Set mode via environment variable
env::set_var("LAMBDA_EXTENSION_SPAN_PROCESSOR_MODE", "async");
// Get mode from environment
let mode = ProcessorMode::resolve(None);
assert!(matches!(mode, ProcessorMode::Async));
// Programmatically provide a default but let environment override it
let mode = ProcessorMode::resolve(Some(ProcessorMode::Sync));
assert!(matches!(mode, ProcessorMode::Async)); // Environment still takes precedenceVariants§
Sync
Synchronous flush in handler thread. Best for development and debugging.
Async
Asynchronous flush via extension. Best for production use to minimize latency.
Finalize
Let processor handle flushing. Best with BatchSpanProcessor for custom export strategies.
Implementations§
Source§impl ProcessorMode
impl ProcessorMode
Sourcepub fn resolve(config_mode: Option<ProcessorMode>) -> Self
pub fn resolve(config_mode: Option<ProcessorMode>) -> Self
Resolve processor mode from environment variable or provided configuration.
If LAMBDA_EXTENSION_SPAN_PROCESSOR_MODE environment variable is set, it takes precedence. Otherwise, uses the provided mode or defaults to Sync mode if neither is set.
Trait Implementations§
Source§impl Clone for ProcessorMode
impl Clone for ProcessorMode
Source§fn clone(&self) -> ProcessorMode
fn clone(&self) -> ProcessorMode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ProcessorMode
impl Debug for ProcessorMode
Source§impl Display for ProcessorMode
impl Display for ProcessorMode
Source§impl PartialEq for ProcessorMode
impl PartialEq for ProcessorMode
impl StructuralPartialEq for ProcessorMode
Auto Trait Implementations§
impl Freeze for ProcessorMode
impl RefUnwindSafe for ProcessorMode
impl Send for ProcessorMode
impl Sync for ProcessorMode
impl Unpin for ProcessorMode
impl UnwindSafe for ProcessorMode
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