2 unstable releases

0.5.0 Nov 23, 2024
0.4.0 Oct 12, 2024

#1784 in Development tools

Download history 107/week @ 2024-10-07 36/week @ 2024-10-14 114/week @ 2024-11-18 25/week @ 2024-11-25 8/week @ 2024-12-02 16/week @ 2024-12-09

102 downloads per month

MIT license

27KB
439 lines

nr-tracing-layer

license crates.io docs.rs

A tracing layer that sends logs to the New Relic Log API.

Requirements

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

Endpoint

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 nr_tracing_layer::NewRelicOptions;
use tracing_subscriber::prelude::*;
use tracing::{instrument, subscriber}

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

fn main() {
    let options = NewRelicOptions::new("my-service", "my-new-relic-api-key")
        .with_tags("env:dev");
    let dd = nr_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–22MB
~297K SLoC