Expand description
§otlp-stdout-client
otlp-stdout-client is a Rust library that provides an OpenTelemetry exporter
designed for serverless environments, particularly AWS Lambda functions.
This exporter implements the opentelemetry_http::HttpClient interface and can be used
in an OpenTelemetry OTLP pipeline to send OTLP data (both JSON and Protobuf formats)
to stdout. This allows the data to be easily ingested and forwarded to an OTLP collector.
§Note on Dependencies
This crate currently includes a local implementation of the LambdaResourceDetector
from the opentelemetry-aws crate. This is a temporary measure while waiting for the
opentelemetry-aws crate to be updated to version 0.13.0. Once the update is available,
this local implementation will be removed in favor of the official crate dependency.
§Key Features
- Implements
opentelemetry_http::HttpClientfor use in OTLP pipelines - Exports OpenTelemetry data to stdout in a structured format
- Supports both HTTP/JSON and HTTP/Protobuf OTLP records
- Designed for serverless environments, especially AWS Lambda
- Configurable through environment variables
- Includes Lambda-specific resource detection
- Optional GZIP compression of payloads
§Usage
This library can be integrated into OpenTelemetry OTLP pipelines to redirect telemetry data to stdout. It’s particularly useful in serverless environments where direct network access to a collector might not be available or desired.
use otlp_stdout_client::{StdoutClient, init_tracer_provider};
use opentelemetry::trace::TracerProvider;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize a tracer provider with the StdoutClient
let tracer_provider = init_tracer_provider()?;
// Use the tracer for instrumenting your code
let tracer = tracer_provider.tracer("my-service");
// Your instrumented code here...
Ok(())
}§Configuration
The exporter can be configured using the following environment variables.
-
OTEL_EXPORTER_OTLP_PROTOCOL: Specifies the protocol to use for the OTLP exporter. Valid values are:-
“http/json” (default): Uses HTTP with JSON payload
-
“http/protobuf”: Uses HTTP with Protobuf payload
If not set or set to an unsupported value, defaults to “http/json”. The output will be written to stdout in the format specified by the protocol.
-
-
OTEL_EXPORTER_OTLP_ENDPOINT: Sets the endpoint for the OTLP exporter. Specify the endpoint of your OTLP collector. A fieldendpointwill be added to the output, and can be used by the forwarder to actually send the data. -
OTEL_EXPORTER_OTLP_HEADERS: Sets additional headers for the OTLP exporter. Format: “key1=value1,key2=value2” These headers will be added to the output under theheadersfield. If your collector requires authentication, it’s probably better to not add them here, as they will be visible in the logs. You should add the authentication information in the forwarder, and not here. -
OTEL_EXPORTER_OTLP_TIMEOUT: Sets the timeout for the OTLP exporter in milliseconds. If not set, a default timeout is used. Since the output is written to stdout, this setting is not used. -
OTEL_EXPORTER_OTLP_COMPRESSION: Specifies the compression algorithm to use. Valid values are:-
“gzip”: Compresses the payload using GZIP
-
If not set or any other value, no compression is applied
If you specify a compression algorithm, the payload will be compressed before being written to stdout, and encoded as base64. The
content-encodingheader will be also added as a field that can be used by the forwarder to determine the compression algorithm to both decode the payload and set the correctContent-Encodingheader in the request to the collector.
-
-
OTEL_SERVICE_NAME: Sets the service name for the Lambda function. If not set, falls back to the name of the lambda function.
§Usage
This crate provides functions to initialize tracer and meter providers that use the stdout exporter. These can be easily integrated into your Lambda functions or other serverless applications. Please refer to the main README.md for the lambda-otlp-forwarder project for more information.
For detailed usage instructions, see the documentation for init_tracer_provider
and init_meter_provider functions.
Structs§
Functions§
- Retrieves the Lambda resource information for OpenTelemetry.
- Initializes and returns a new TracerProvider configured for stdout output.