otlp-stdout-span-exporter
A Rust span exporter that writes OpenTelemetry spans to stdout in OTLP format. Part of the serverless-otlp-forwarder project.
This exporter is particularly useful in serverless environments like AWS Lambda where writing to stdout is a common pattern for exporting telemetry data.
Features
- Uses OTLP Protobuf serialization for efficient encoding
- Applies GZIP compression with configurable levels
- Detects service name from environment variables
- Supports custom headers via environment variables
- Consistent JSON output format
- Zero external HTTP dependencies
- Lightweight and fast
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
The recommended way to use this exporter is with batch export, which provides better performance by buffering and exporting spans in batches:
use ;
use ;
use OtlpStdoutSpanExporter;
async
This setup ensures that:
- Spans are batched together for efficient export
- Parent-child relationships are preserved
- System resources are used efficiently
- Spans are properly flushed on shutdown
Environment Variables
The exporter respects the following environment variables:
OTEL_SERVICE_NAME: Service name to use in outputAWS_LAMBDA_FUNCTION_NAME: Fallback service name (ifOTEL_SERVICE_NAMEnot set)OTEL_EXPORTER_OTLP_HEADERS: Global headers for OTLP exportOTEL_EXPORTER_OTLP_TRACES_HEADERS: Trace-specific headers (takes precedence)
Header format examples:
# Single header
# Multiple headers
# Headers with special characters
Output Format
The exporter writes each batch of spans as a JSON object to stdout:
Configuration
The exporter can be configured with different GZIP compression levels:
// Create exporter with custom GZIP level (0-9)
let exporter = with_gzip_level;
Development
- Clone the repository:
- Run tests:
- Run the example:
License
Apache License 2.0
See Also
- serverless-otlp-forwarder - The main project repository
- Python Span Exporter - The Python version of this exporter
- TypeScript Span Exporter - The TypeScript version of this exporter