# Rust [Languages](README.md) · [Shared configuration](../../common.md) · [Verification](../../verification.md) This example uses the OpenTelemetry Rust **0.32.0** crate family and a current stable Rust toolchain. As of **2026-11-22**, [upstream Rust documentation](https://opentelemetry.io/docs/languages/rust/) lists traces as Beta and metrics/logs as Stable. That current maturity classification is separate from this pinned, trace-only 0.32.0 recipe. It exports one trace over HTTP/protobuf using the blocking HTTP client, which works with the SDK's ordinary batch processor without a Tokio runtime. ## Install ```sh cargo new corridora-rust cd corridora-rust ``` Replace the `[dependencies]` section of `Cargo.toml` with: ```toml [dependencies] opentelemetry = { version = "=0.32.0", default-features = false, features = ["trace"] } opentelemetry_sdk = { version = "=0.32.0", default-features = false, features = ["trace"] } opentelemetry-otlp = { version = "=0.32.0", default-features = false, features = ["trace", "http-proto", "reqwest-blocking-client", "reqwest-rustls"] } ``` Keep these crates on a compatible release family. HTTP, gRPC, TLS, and asynchronous clients are selected through Cargo features; changing an environment variable cannot enable a transport that was not compiled in. This example includes Rustls support for an optional HTTPS destination. ## Initialize and emit Start the [Collector](../../../collector.md), then configure the exporter: ```sh export OTEL_EXPORTER_OTLP_ENDPOINT='http://127.0.0.1:4318' unset OTEL_EXPORTER_OTLP_TRACES_ENDPOINT unset OTEL_EXPORTER_OTLP_HEADERS OTEL_EXPORTER_OTLP_TRACES_HEADERS ``` Save as `src/main.rs`: ```rust use opentelemetry::trace::{TraceContextExt, Tracer, TracerProvider}; use opentelemetry::KeyValue; use opentelemetry_otlp::{Protocol, WithExportConfig}; use opentelemetry_sdk::{trace::SdkTracerProvider, Resource}; use std::{error::Error, thread, time::Duration}; fn main() -> Result<(), Box> { let exporter = opentelemetry_otlp::SpanExporter::builder() .with_http() .with_protocol(Protocol::HttpBinary) .build()?; let provider = SdkTracerProvider::builder() .with_batch_exporter(exporter) .with_resource(Resource::builder() .with_service_name("corridora-rust") .with_attributes([ KeyValue::new("service.version", "example-1"), KeyValue::new("deployment.environment.name", "development"), ]) .build()) .build(); let tracer = provider.tracer("corridora.examples.rust"); tracer.in_span("example.calculate", |cx| { cx.span().set_attribute(KeyValue::new("example.language", "rust")); thread::sleep(Duration::from_millis(50)); println!("trace_id={}", cx.span().span_context().trace_id()); }); provider.shutdown()?; Ok(()) } ``` ```sh cargo run ``` Commit `Cargo.lock` for the application. The exporter reads its supported OTLP endpoint/header variables; the program explicitly selects HTTP binary encoding. The generic endpoint is a base URL, while a signal-specific endpoint identifies the trace path. ## Async applications and instrumentation The sample uses the OpenTelemetry API directly. Rust's `tracing` spans are a different API and require a compatible `tracing-opentelemetry` subscriber layer to become OpenTelemetry spans. Installing `tracing` or setting exporter variables alone does not connect the two systems. Keep an attached OpenTelemetry context guard out of a future that can yield and resume on another task. Use a compatible asynchronous context adapter or subscriber integration across `.await` boundaries. When manually instrumenting HTTP or queue traffic, inject and extract W3C trace context at the transport boundary. There is no universal Rust automatic instrumentation package that covers every web framework and client. Select middleware for the framework versions in your application and validate that nested operations share the same trace ID. ## Logs, metrics, and lifecycle Rust's trace, metric, and log SDKs require separate providers. Metrics need a meter provider, reader/exporter, and instruments. Logs need a logger provider, processor/exporter, and a bridge such as a compatible `opentelemetry-appender-tracing`. A `tracing` event is not necessarily an exported OTLP log, and `println!` is only stdout. This program initializes only tracing. Add the appropriate providers/exporters and any additional signal features before expecting logs or metrics. Use the same service resource and ensure logging occurs with a valid current span context when correlation is intended. Retain the provider for the process lifetime and call `shutdown` after spans finish. In an async server, integrate cleanup with its shutdown sequence; blocking exporter cleanup should not starve its event loop. The chosen transport and SDK processor must agree: replacing the blocking client with an async client may require the SDK's async runtime processor variants. ## Direct export and verification For direct Corridora export, replace the base endpoint with HTTPS and set `OTEL_EXPORTER_OTLP_HEADERS="X-CORRIDORA-KEY=${CORRIDORA_INGEST_KEY}"` after following [shared configuration](../../common.md). The included Rustls feature supplies TLS support. Programmatic builder endpoint/header options override environment configuration. Find service `corridora-rust` and the printed trace ID in Corridora. Expect one `example.calculate` span. If Cargo resolves incompatible OpenTelemetry types, inspect `cargo tree` for multiple crate families before changing application code. If the span exists locally but is absent remotely, check export diagnostics, shutdown errors, and [verification](../../verification.md).