dd-trace-rs
This library powers Distributed Tracing. It provides OpenTelemetry API and SDK compatibility with Datadog-specific features and optimizations.
Usage
The datadog-opentelemetry crate provides an easy to use override for the rust opentelemetry-sdk.
Installation
Add to you Cargo.toml
= { = "0.2.0" }
Tracing
To trace functions, you can either use the opentelemetry crate's API or the tracing crate API with the tracing-opentelemetry bridge.
Initialization
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 API
- Requires
tracing-subscriberandtracing
use TracerProvider;
use Duration;
use ;
Opentelemetry API
- requires
opentelemetry
use Duration;
Configuration
Configuration can be passed either:
- Programmatically
let config = builder
.set_service
.set_env
.build;
let tracer_provider = tracing
.with_config
// this also accepts options for the Opentelemetry SDK builder
.with_max_attributes_per_span
.init;
For advanced usage and configuration information, check out the library documentation.
- Through env variables
DD_SERVICE=my_service DD_ENV=prod
This API call also be used to pass options to the OpenTelemetry SDK TracerProviderBuilder
// Custom otel tracer sdk options
tracing
.with_max_attributes_per_span
// Custom span processor
.with_span_processor
.init;
Support
- MSRV: 1.84
- opentelemetry version: 0.31
tracing-opentelemetryversion: 0.32