Utilities for integrating Datadog with opentelemetry + tracing in rust

Overview

crates-badge docs-badge Crates.io

Non-official datadog tracing and log correlation for Rust services.

This crate contains the necessary glue to bridge the gap between OpenTelemetry, tracing and Datadog.

Features

datadog-tracing has the following features:

  1. tracing: utilities for building an OpenTelemetry tracer/layer that sends traces to the Datadog agent
  2. log correlation: a log formatter that converts the trace ID and span ID to the Datadog native format and injects them into the dd.trace_id and dd.span_id fields (more information)
  3. propagation: a utility function to set the Datadog propagator as the global propagator
  4. axum (enabled via the axum feature): re-exposing the functionality of axum-tracing-opentelemetry
  5. opionated tracing-subscriber init function, configuring logs and the datadog exporter. It's optional, and you can build your own: the functions it uses are exposed.

Configuration

The lib is configurable via environment variables as following:

env var default value description
DD_ENABLED false Enables the datadog exporter and trace_id/span_id on logs
DD_SERVICE Datadog service name
DD_AGENT_HOST localhost Datadog agent host
DD_AGENT_PORT 8126 Datadog agent port
RUST_LOG info
AXUM_TRACING_LOG_LEVEL if DD_ENABLED=true, "info", otherwise "off"
OTEL_LOG_LEVEL debug

Examples

  • Check the axum folder for a complete example using axum.
    • Please refer to the Cargo.toml here.

Further Context and Rationale

Inspiration

This lib was highly inspired on ddtrace crate, which is also a glue between tracing + opentelemetry + datadog. The main difference is that it exportes using the opentelemetry_otlp exporter, and this one uses opentelemetry_datadog, so there is no need to configure your datadog agent to receive traces via OTLP and the default datadog APM works as expected!

Propagation

Two commonly used propagation standards are B3 (OpenZipkin's propagation style) and Jaeger. OpenTelemetry supports both.

Most Datadog SDK's support both B3 and the Datadog native propagation style. For example, the Python datadog-tracing library supports B3 but it needs to be explicitly enabled.

For ease of integration with services written in other languages that use the official Datadog SDK, we opted for sticking with Datadog-style propagation over B3. This is set via the set_global_propagator function which is automatically called when you create the tracer.

Reqwest Propagation

The Python library takes care of propagation of the trace context automatically. Unfortunately, we need to do this manually in Rust.

Arguably, propagation in HTTP requests is the most common need. This crate does not provide any additional support, but we recommend using the reqwest-middleware crate to inject the necessary headers when using reqwest. If you set the global propagator using datadog-tracing, it will work out of the box.

use datadog-tracing::set_global_propagator;
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
use reqwest_tracing::TracingMiddleware;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let (_guard, tracer_shutdown) = datadog_tracing::init()?;
    client = get_http_client();
    
    // setup your app and inject the client
}

fn get_http_client() -> ClientWithMiddleware {
    ClientBuilder::new(reqwest::Client::new())
        .with(TracingMiddleware::default())
        .build()
}
You might also like...
A patch to fix tracing LocalTime problem.

tracing-local-time A patch to fix tracing LocalTime problem. Tracing-subscriber now has a bug in LocalTime, so build ourselves' to fix it. In this pat

An example of a fairing for rocket to use tracing (as this pops up at many places in dicussions and questions)
An example of a fairing for rocket to use tracing (as this pops up at many places in dicussions and questions)

Rocket Tracing Fairing Example This repository aims to give a short example of how you can add a Fairing to your Rocket for tracing and how to use it

A dynamic binary tracing tool

Backlight Backlight is a dynamic binary tracing tool. Install $ git clone [email protected]:JoshMcguigan/backlight.git $ cd backlight $ cargo install-b

Tracing layer to quickly inspect spans and events

tracing-texray First, a word of warning: This is alpha software. Don't run this in prod or anywhere where a panic would ruin your day. tracing-texray

A convenient tracing config and init lib, with symlinking and local timezone.
A convenient tracing config and init lib, with symlinking and local timezone.

clia-tracing-config A convenient tracing config and init lib, with symlinking and local timezone. Use these formats default, and can be configured: pr

AWS Cloudwatch layer for tracing-subscriber

tracing-cloudwatch tracing-cloudwatch is a custom tracing-subscriber layer that sends your application's tracing events(logs) to AWS CloudWatch Logs.

High-performance QEMU memory and instruction tracing
High-performance QEMU memory and instruction tracing

Cannoli Cannoli is a high-performance tracing engine for qemu-user. It can record a trace of both PCs executed, as well as memory operations. It consi

Utilities to gather data out of roms. Written in Rust. It (should) support all types.

snesutilities Utilities to gather data out of roms. Written in Rust. It (should) support all types. How Have a look at main.rs: use snesutilities::Sne

A set of utilities to better enable polymorphic behavior in Rust

Polymorph A set of utilities to better enable polymorphic behavior in Rust. Introduction Rust is a wonderful language, with a strong emphasis on fast,

Owner
willbank
willbank
A crate providing a tracing-subscriber layer for formatting events so Datadog can parse them

Datadog Formatting Layer A crate providing a tracing-subscriber layer for formatting events so Datadog can parse them. Features Provides a layer for t

Open Schnick 4 Jun 22, 2023
tracing-glog is a glog-inspired formatter for tracing-subscriber.

tracing-glog tracing-glog is a glog-inspired formatter for tracing-subscriber. tracing-glog should be used with tracing-subscriber, as it is a formatt

David Barsky 7 Oct 8, 2022
Integrating `coqidetop` inside Kakoune

This plugin aims at providing a functional and usable coqidetop wrapper for use with Kakoune. For a list of things left to do, see the end of this REA

Mesabloo 6 Apr 22, 2022
Error propagation tracing in Rust.

Propagate Error propagation tracing in Rust. Why Propagate? Being able to trace the cause of an error is critical for many types of software written i

Ben Reeves 10 Sep 23, 2021
Emit ETW events in tracing-enabled Rust applications.

tracing-etw Emit ETW events in tracing-enabled Rust applications. This crate depends on rust_win_etw. There are four ETW events. fn NewSpan(span_id: u

Microsoft 11 Aug 10, 2022
tracing - a framework for instrumenting Rust programs to collect structured, event-based diagnostic information

tracing-appender Writers for logging events and spans Documentation | Chat Overview tracing is a framework for instrumenting Rust programs to collect

Cris Liao 1 Mar 9, 2022
A rust `tracing` compatible framework inspired by log4rs.

trace4rs This crate allows users to configure output from tracing in the same way as you would configure the output of log4rs. Overview For a usage ex

Imperva 5 Oct 24, 2022
This crate bridges between gstreamer and tracing ecosystems.

This crate provides a bridge between gstreamer and the tracing ecosystem. The goal is to allow Rust applications utilizing GStreamer to better integra

Standard Cognition OSS 17 Jun 7, 2022
A tracing profiler for the Sega MegaDrive/Genesis

md-profiler, a tracing profiler for the Sega MegaDrive/Genesis This program, meant to be used with this fork of BlastEm, helps you finding bottlenecks

null 15 Nov 3, 2022
A tracing layer for macOS/iOS's `oslog`

tracing_oslog This is a tracing layer for the Apple OS logging framework. Activities are used to handle spans, Example use tracing_oslog::OsLogger; l

Lucy 12 Dec 6, 2022