[DEPRECATED] lambda-otel-utils
IMPORTANT: This package is deprecated and no longer maintained.
For similar functionality with an improved API, please consider using lambda-otel-lite. While not a direct replacement (APIs differ), it solves the same problems with a more modern implementation.
lambda-otel-utils is a Rust library that simplifies the integration of OpenTelemetry tracing and metrics with AWS Lambda functions. It provides utilities for setting up and configuring OpenTelemetry in serverless environments, making it easier to implement distributed tracing and metrics collection in your Lambda-based applications.
Features
- Easy setup of OpenTelemetry TracerProvider and MeterProvider for AWS Lambda
- Customizable tracing and metrics configuration
- Compatible with the
lambda_runtimecrate - Support for outputting to stdout using the
otlp-stdout-client - Environment variable configuration support
- AWS Lambda resource detection and attribute injection
- Flexible subscriber configuration with JSON formatting options
Installation
Add the following to your Cargo.toml or run cargo add lambda-otel-utils:
[]
= "0.2.0"
Usage
Basic Setup with Tracing and Metrics
use ;
use Error as StdError;
use Duration;
use ;
use OpenTelemetrySpanExt;
async
Main Components
HttpTracerProviderBuilder
The HttpTracerProviderBuilder allows you to configure and build a custom TracerProvider tailored for Lambda environments. Features include:
- Stdout client support for Lambda environments
- Configurable text map propagators (including XRay support)
- Custom ID generators with XRay support
- Simple and batch exporter options
- Global provider installation option
use HttpTracerProviderBuilder;
let tracer_provider = default
.with_stdout_client
.with_xray_text_map_propagator
.with_xray_id_generator
.with_simple_exporter
.enable_global
.build?;
HttpMeterProviderBuilder
The HttpMeterProviderBuilder provides configuration options for metrics collection:
- Customizable export intervals
- Stdout client support
- Meter naming
- Export timeout configuration
- Global provider installation
use HttpMeterProviderBuilder;
use Duration;
let meter_provider = default
.with_stdout_client
.with_meter_name
.with_export_interval
.build?;
OpenTelemetrySubscriberBuilder
A flexible builder for configuring tracing subscribers with OpenTelemetry support:
- Environment filter support (RUST_LOG)
- JSON formatting options
- Combined tracing and metrics setup
- Service name configuration
use OpenTelemetrySubscriberBuilder;
new
.with_tracer_provider
.with_meter_provider
.with_service_name
.with_env_filter
.with_json_format
.init?;
Environment Variables
The crate respects several environment variables for configuration:
OTEL_SERVICE_NAME: Sets the service name for telemetry dataAWS_LAMBDA_FUNCTION_NAME: Fallback for service name if OTEL_SERVICE_NAME is not setOTEL_EXPORTER_OTLP_PROTOCOL: Configures the OTLP protocol ("http/protobuf" or "http/json")LAMBDA_OTEL_SPAN_PROCESSOR: Selects the span processor type ("simple" or "batch")RUST_LOG: Controls logging levels when environment filter is enabled
Resource Detection
The crate automatically detects and includes AWS Lambda resource attributes in your telemetry data, including:
- Function name
- Function version
- Execution environment
- Memory limits
- Region information
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under MIT. See the LICENSE file for details.