| Crates.io | datadog-opentelemetry |
| lib.rs | datadog-opentelemetry |
| version | 0.2.1 |
| created_at | 2025-03-12 10:19:12.899247+00 |
| updated_at | 2025-12-11 17:09:32.533656+00 |
| description | A Datadog layer of compatibility for the opentelemetry SDK |
| homepage | |
| repository | https://github.com/DataDog/dd-trace-rs/tree/main/datadog-opentelemetry |
| max_upload_size | |
| id | 1589605 |
| size | 819,845 |
This library powers Distributed Tracing. It provides OpenTelemetry API and SDK compatibility with Datadog-specific features and optimizations.
The datadog-opentelemetry crate provides an easy to use override for the rust opentelemetry-sdk.
Add to you Cargo.toml
datadog-opentelemetry = { version = "0.2.1" }
To trace functions, you can either use the opentelemetry crate's API or the tracing crate API with the tracing-opentelemetry bridge.
The following examples will read datadog and opentelemetry configuration from environment variables and other available sources, initialize and set up the tracer provider and the text distributed tracing propagators globally.
tracing-subscriber and tracinguse opentelemetry::trace::TracerProvider;
use std::time::Duration;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
fn main() {
// This picks up env var configuration and other datadog configuration sources
let tracer_provider = datadog_opentelemetry::tracing()
.init();
tracing_subscriber::registry()
.with(tracing_opentelemetry::layer().with_tracer(tracer_provider.tracer("my_application_name")))
.init();
tracer_provider.shutdown_with_timeout(Duration::from_secs(1)).expect("tracer shutdown error");
}
opentelemetryuse std::time::Duration;
fn main() {
// This picks up env var configuration and other datadog configuration sources
let tracer_provider = datadog_opentelemetry::tracing()
.init();
// Your code
// Now use standard OpenTelemetry APIs
use opentelemetry::global;
use opentelemetry::trace::Tracer;
let tracer = global::tracer("my-service");
let span = tracer.start("my-operation");
// ... do work ...
// Shutdown the tracer to flush the remaining data
tracer_provider.shutdown_with_timeout(Duration::from_secs(1)).expect("tracer shutdown error");
}
Configuration can be passed either:
let config = datadog_opentelemetry::configuration::Config::builder()
.set_service("my_service".to_string())
.set_env("prod".to_string())
.build();
let tracer_provider = datadog_opentelemetry::tracing()
.with_config(config)
// this also accepts options for the Opentelemetry SDK builder
.with_max_attributes_per_span(64)
.init();
For advanced usage and configuration information, check out the library documentation.
DD_SERVICE=my_service DD_ENV=prod cargo run
This API call also be used to pass options to the OpenTelemetry SDK TracerProviderBuilder
impl opentelemetry_sdk::trace::SpanProcessor for MySpanProcessor { ... }
// Custom otel tracer sdk options
datadog_opentelemetry::tracing()
.with_max_attributes_per_span(64)
// Custom span processor
.with_span_processor(MySpanProcessor)
.init();
tracing-opentelemetry version: 0.32