Skip to main content
The OTLP (OpenTelemetry Protocol) exporter is the recommended way to export telemetry data from your Rust applications. It supports all three telemetry signals (traces, metrics, and logs) and can communicate via gRPC or HTTP.

Installation

Add the dependency to your Cargo.toml:

Feature Flags

The OTLP exporter supports multiple protocols and HTTP clients: Default features:
For gRPC (Tonic):
For async HTTP with Reqwest:
Additional features:
  • gzip-tonic - gRPC compression with gzip
  • zstd-tonic - gRPC compression with zstd
  • gzip-http - HTTP compression with gzip
  • zstd-http - HTTP compression with zstd
  • tls-ring or tls-aws-lc - TLS support for gRPC
  • http-json - HTTP with JSON encoding

Quick Start

HTTP Binary Protocol

The HTTP binary protocol is the simplest to get started with:

gRPC Protocol

For gRPC, you need a Tokio runtime:

Complete Example with All Signals

Here’s a complete example that exports traces, metrics, and logs:

Configuration

Custom Endpoint

By default, the exporter connects to http://localhost:4318 for HTTP and http://localhost:4317 for gRPC. You can customize this:

Environment Variables

The exporter respects standard OpenTelemetry environment variables:
  • OTEL_EXPORTER_OTLP_ENDPOINT - Base endpoint for all signals
  • OTEL_EXPORTER_OTLP_TRACES_ENDPOINT - Endpoint for traces
  • OTEL_EXPORTER_OTLP_METRICS_ENDPOINT - Endpoint for metrics
  • OTEL_EXPORTER_OTLP_LOGS_ENDPOINT - Endpoint for logs
  • OTEL_EXPORTER_OTLP_HEADERS - Custom headers
  • OTEL_EXPORTER_OTLP_TIMEOUT - Export timeout

Headers and Authentication

Add custom headers for authentication:

Timeout Configuration

Compression

Enable compression to reduce network bandwidth: For gRPC:
For HTTP:

Integration with Backends

OpenTelemetry Collector

Run the collector with Docker:

Jaeger

Jaeger natively supports OTLP:
View traces at: http://localhost:16686

Prometheus

Prometheus can accept OTLP metrics:
Configure the exporter:

HTTP vs gRPC

When to Use HTTP

  • Simpler setup without async runtime requirements (with blocking client)
  • Firewall-friendly (standard HTTP/HTTPS ports)
  • Works well with HTTP proxies and load balancers
  • JSON format available for debugging

When to Use gRPC

  • Better performance for high-throughput scenarios
  • Built-in streaming support
  • More efficient binary protocol
  • Better support for bidirectional communication

Performance Considerations

Use Batch Exporters

Always use batch exporters in production:
Avoid simple exporters in production:

Enable Compression

Compression can reduce network bandwidth by 60-80%:

Tune Batch Configuration

Customize batching for your workload:

Troubleshooting

Connection Refused

If you see connection errors, verify:
  1. The collector is running: docker ps
  2. The endpoint is correct (default: http://localhost:4318 for HTTP)
  3. Firewall rules allow the connection

Spans Not Appearing

Ensure you’re calling shutdown:

High Memory Usage

Reduce batch queue size:

Protocol Reference

Available protocol options:

Next Steps

Stdout Exporter

Debug telemetry locally without a backend

Zipkin Exporter

Export traces to Zipkin