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 crate
is part of the serverless-otlp-forwarder
project, which provides a comprehensive solution for OpenTelemetry telemetry collection
in AWS Lambda environments.
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.
§Key Features
- Implements
opentelemetry_http::HttpClient
for use in OTLP pipelines - Exports OpenTelemetry data to stdout in a structured format
- Designed for serverless environments, especially AWS Lambda
- Configurable through environment variables
- Optional GZIP compression of payloads
- Supports both JSON and Protobuf 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;
use opentelemetry_sdk::trace::SdkTracerProvider;
use opentelemetry_otlp::{WithExportConfig, WithHttpConfig};
use opentelemetry::trace::Tracer;
use opentelemetry::global;
fn init_tracer_provider() -> Result<SdkTracerProvider, Box<dyn std::error::Error>> {
let exporter = opentelemetry_otlp::SpanExporter::builder()
.with_http()
.with_http_client(StdoutClient::default())
.build()?;
let tracer_provider = opentelemetry_sdk::trace::SdkTracerProvider::builder()
.with_simple_exporter(exporter)
.build();
Ok(tracer_provider)
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let tracer_provider = init_tracer_provider()?;
global::set_tracer_provider(tracer_provider.clone());
let tracer = global::tracer("my_tracer");
// Use the tracer for instrumenting your code
// For example:
tracer.in_span("example_span", |_cx| {
// Your code here
});
Ok(())
}
§Configuration
The exporter can be configured using the following standard OTEL 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
-
OTEL_EXPORTER_OTLP_ENDPOINT
: Sets the endpoint for the OTLP exporter. Specify the endpoint of your OTLP collector. -
OTEL_EXPORTER_OTLP_HEADERS
: Sets additional headers for the OTLP exporter. Format: “key1=value1,key2=value2” -
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
For more detailed information on usage and configuration, please refer to the README.md file.