Crate tracing_duper

Crate tracing_duper 

Source
Expand description

A composable tracing_subscriber layer to emit Duper events.

You can install it to a tracing_subscriber::registry() just like any other filter or formatter:

use tracing_duper::DuperLayer;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

tracing_subscriber::registry()
    // ... add filtering layers ...
    .with(DuperLayer::new().with_span_timings(true))
    .init();

See DuperLayer for all the available configuration.

Now, you can emit tracing spans and events as usual. If you’d like to emit Duper values, use $duper. as the prefix of the field, and set the value to a Duper-formatted string.

use tracing::{debug, warn};

#[tracing::instrument]
fn send_gifts(count: &mut usize) {
    if *count < 12 {
        warn!("too few gifts... try again later");
    } else {
        debug!(
            user_id = &b"santa"[..],
            "$duper.delivery_date" = "(PlainMonthDay('12-25'), \"Christmas\")",
            "sending {count} gifts"
        );
        std::thread::sleep(std::time::Duration::from_millis(100));
        *count = 0;
    }
}

This should print logs like the following to stdout:

{level:"WARN",timestamp:Instant('2025-12-04T13:29:33.947380870-03:00'),target:"simple",span:{count:10,span_id:1},spans:[{count:10,span_id:1}],fields:{message:"too few gifts... try again later"}}
{level:"INFO",timestamp:Instant('2025-12-04T13:29:33.947608295-03:00'),target:"simple",span:{count:10,span_id:1},spans:[{count:10,span_id:1}],fields:{span_event:"closed","span_time.busy":Duration('PT0.000265196S'),"span_time.idle":Duration('PT0.000003567S')}}
{level:"DEBUG",timestamp:Instant('2025-12-04T13:29:33.948805983-03:00'),target:"simple",span:{count:23,span_id:2251799813685249},spans:[{count:23,span_id:2251799813685249}],fields:{delivery_date:(PlainMonthDay('12-25'),"Christmas"),message:"sending 23 gifts",user_id:b"santa"}}
{level:"INFO",timestamp:Instant('2025-12-04T13:29:34.049418692-03:00'),target:"simple",span:{count:23,span_id:2251799813685249},spans:[{count:23,span_id:2251799813685249}],fields:{span_event:"closed","span_time.busy":Duration('PT0.100555973S'),"span_time.idle":Duration('PT0.000001603S')}}

To create Duper values programmatically, look into duper and duper::Serializer, or the serde_duper crate.

§Feature flags

  • chrono: Use chrono to format log timestamps. Enabled by default.

Structs§

ChronoLocalTimer
An Instant timestamp generator that uses chrono and includes the local timezone.
ChronoUtcTimer
An Instant timestamp generator that uses chrono and includes the UTC timezone.
DuperLayer
A tracing_subscriber::Layer that generates Duper-formatted logs to the specified writer.

Traits§

DuperTimer
A trait to allow implementing timestamp generators.