#distributed-tracing #datadog #statistics #metrics #aggregation #tracing-metrics #libdd

libdd-trace-stats

This crate provides utilities to compute stats from Datadog traces

2 stable releases

1.0.1 Feb 25, 2026
1.0.0 Nov 18, 2025

#314 in Machine learning

Download history 281/week @ 2025-11-14 427/week @ 2025-11-21 334/week @ 2025-11-28 538/week @ 2025-12-05 531/week @ 2025-12-12 277/week @ 2025-12-19 241/week @ 2025-12-26 314/week @ 2026-01-02 1152/week @ 2026-01-09 739/week @ 2026-01-16 824/week @ 2026-01-23 1204/week @ 2026-01-30 20551/week @ 2026-02-06 22117/week @ 2026-02-13 41222/week @ 2026-02-20 44403/week @ 2026-02-27

128,566 downloads per month
Used in 3 crates (via libdd-data-pipeline)

Apache-2.0

530KB
11K SLoC

libdd-trace-stats

Compute aggregated statistics from distributed tracing spans with time-bucketed concentration.

Overview

libdd-trace-stats provides utilities for computing trace statistics by aggregating spans into time-based buckets with support for DDSketch distributions.

Features

  • Span Concentration: Aggregate spans into time buckets
  • DDSketch Integration: Use DDSketch for latency distribution metrics
  • Peer Tags: Support for peer service aggregation
  • Span Filtering: Filter spans by top-level, measured, or span.kind
  • Time Bucketing: Configurable bucket sizes for aggregation
  • Statistics Export: Generate statistics payloads for Datadog backend

Span Concentrator

The SpanConcentrator is the core component that aggregates spans into statistics:

Aggregation

Spans are aggregated into time buckets based on their end time. Within each bucket, spans are further aggregated by:

  • Service name
  • Resource name
  • Operation name
  • Span type
  • HTTP status code
  • Peer tags (if enabled)

Span Eligibility

Only certain spans are aggregated:

  • Root spans
  • Top-level spans
  • Measured spans
  • Spans with eligible span.kind values

Flushing

When flushed, the concentrator keeps the most recent buckets and returns older buckets as statistics.

Example Usage

use libdd_trace_stats::span_concentrator::SpanConcentrator;
use std::time::{Duration, SystemTime};

// Create a concentrator
let mut concentrator = SpanConcentrator::new(
    Duration::from_secs(10), // 10 second buckets
    SystemTime::now(),
    vec!["client".to_string(), "server".to_string()], // eligible span kinds
    vec!["peer.service".to_string()], // peer tag keys
);

// Add spans
// concentrator.add_span(&span);

// Flush statistics
// let stats = concentrator.flush(false);

Dependencies

~16–32MB
~368K SLoC