Expand description
Structured event recording for OpenTelemetry spans in AWS Lambda functions.
This module provides functionality for recording structured events within OpenTelemetry spans. Events are queryable data points that provide additional context and business logic markers within the execution of Lambda functions.
§Key Features
- Dual API: Both function-based and builder-based interfaces
- Level-based filtering: Events can be filtered by severity level
- Structured attributes: Attach custom key-value pairs to events
- OpenTelemetry compliance: Uses standard OpenTelemetry event semantics
- Lambda-optimized: Designed for AWS Lambda execution patterns
- Performance-conscious: Early filtering to minimize overhead
§Use Cases
Events are particularly useful for:
- Business logic markers: Track significant application state changes
- Audit trails: Record user actions and system decisions
- Debugging context: Add structured data for troubleshooting
- Performance insights: Mark important execution milestones
- Compliance logging: Record security and regulatory events
§API Styles
§Function-based API (Direct)
use lambda_otel_lite::events::{record_event, EventLevel};
use opentelemetry::KeyValue;
record_event(
EventLevel::Info,
"User logged in",
vec![
KeyValue::new("user_id", "123"),
KeyValue::new("method", "oauth"),
],
None, // timestamp
);§Builder-based API (Ergonomic)
use lambda_otel_lite::events::{event, EventLevel};
// Simple event
event()
.level(EventLevel::Info)
.message("User logged in")
.call();
// Event with individual attributes
event()
.level(EventLevel::Info)
.message("User logged in")
.attribute("user_id", "123")
.attribute("method", "oauth")
.call();§Environment Configuration
The event level can be controlled via the AWS_LAMBDA_LOG_LEVEL environment variable
(with fallback to LOG_LEVEL), same as the internal logging system:
TRACE: All events (most verbose)DEBUG: Debug, Info, Warn, Error eventsINFO: Info, Warn, Error events (default)WARN: Warn, Error events onlyERROR: Error events only
Structs§
- Event
Builder - Use builder syntax to set the inputs and finish with
call().
Enums§
- Event
Level - Event severity levels for filtering and categorization.
Functions§
- event
- Create an event builder for ergonomic event construction (builder-based API).
- record_
event - Record a structured event within the current OpenTelemetry span (function-based API).