12 unstable releases (3 breaking)

0.4.0 Sep 18, 2024
0.3.0 Dec 24, 2023
0.2.0 Oct 4, 2023
0.1.8 Sep 20, 2023
0.1.3 Jan 31, 2023

#1355 in Development tools

Download history 45/week @ 2024-06-24 42/week @ 2024-07-01 30/week @ 2024-07-08 14/week @ 2024-07-22 71/week @ 2024-07-29 15/week @ 2024-08-05 16/week @ 2024-08-12 98/week @ 2024-08-19 31/week @ 2024-08-26 4/week @ 2024-09-02 26/week @ 2024-09-09 168/week @ 2024-09-16 80/week @ 2024-09-23 27/week @ 2024-09-30 30/week @ 2024-10-07

306 downloads per month

MIT license

27KB
438 lines

dd-tracing-layer

license crates.io docs.rs

A tracing layer that sends logs to the Datadog Log API.

It's mainly useful when you don't have access to your infrastructure and you cannot use the Datadog Agent or any other mean.

Requirements

You'll need a Datadog API Key for everything to work.

Endpoint

This crate uses the v2 logs endpoints and, by default, will try to send the logs to the US1 region.

You can easily change the region or provide a custom URL if needed.

Example

Here's a simple example of how to set it up and use it:

use dd_tracing_layer::DatadogOptions;
use tracing_subscriber::prelude::*;
use tracing::{instrument, subscriber};

#[instrument]
fn log(msg: &'static str) {
    tracing::info!("your message: {}", msg);
}

fn main() {
    let options = DatadogOptions::new("my-service", "my-datadog-api-key")
        .with_tags("env:dev");
    let dd = dd_tracing_layer::create(options);
    let subscriber = tracing_subscriber::registry()
        .with(tracing_subscriber::fmt::Layer::new().json())
        .with(dd);
    let _s = subscriber::set_default(subscriber);
    log("hello world!");
}

Caveats

The layer will send the logs either 5 seconds after the last log is received or when the buffer arrives to 1000 logs. This is basically due to a limitation in the Datadog API.

Dependencies

~10–21MB
~298K SLoC