tracing-opentelemetry-setup
OpenTelemetry integration for tracing.
The goal of this crate is to provide all-in-one crate to initialize OpenTelemetry integration with tracing
MSRV 1.85
Features
panic- Provides panic hook implementation. Must be enabled via panic modulepropagation- Enables propagation utilitiesmetrics- Enable integration with metricstracing-metrics- Enable metrics usage via tracing-opentelemetryrt-tokio- Tell OpenTelemetry sdk that you use tokio runtimetracing-log- Enablestracing-logfeature across alltracingecosystem used by this crate.internal-logs- Enablesinternal-logsfeature across opentelemetry crates.
Non-standard exporters
datadog- Enables datadog agent exporter. Currently supports only traces & logs
Grpc features
grpc- Enables tonic based gRPC transportgrpc-compression- Enables tonic based gRPC transport with compressiongrpc-tls- Enables tonic based gRPC transport with TLSgrpc-retry- Enables retry logic for grpc exporter. Requirestokiofeature to be used
HTTP features
Note that when enabling multiple clients, only one client will be used by default and it is up to opentelemetry-otlp
-
http- Enables http exporter code without specific client as default option. -
http-compression- Enables http transport with compression -
http-tls- Enables http transport with TLS -
http-retry- Enables retry logic for HTTP exporter. Requirestokiofeature to be used -
http-reqwest-blocking- Enables blocking reqwest client. -
http-reqwest- Enables async reqwest client. -
http-hyper- Enables hyper client. -
http-ureq- Enables option of using basicureqhttp client (no dependency on async IO) -
http-ureq-tls- Enables TLS support inurequsing rustls with platform verifier.
Usage
Make sure tracing-opentelemetry-setup is installed to your dependencies
use ;
use ;
use SubscriberExt;
use SubscriberInitExt;
let default_attrs = builder.with_attr.finish;
let trace_settings = new;
let destination = Destination ;
//Create common OTLP settings
let mut otlp = builder.with_runtime.with_header;
//Initialize subscriber
let registry = registry.with //initializes tracing and return layer
.with //initializes logging and returns layer
.with;
//Finalizes OTLP returning guard
let mut otlp = otlp.finish;
let _guard = registry.set_default;
//Do your job then shutdown to make sure you flush everything
otlp.shutdown.expect