3 releases

0.1.2 Mar 4, 2022
0.1.1 Feb 17, 2022
0.1.0 Feb 17, 2022

#470 in Debugging

Download history 6/week @ 2024-03-13 14/week @ 2024-03-20 31/week @ 2024-03-27 31/week @ 2024-04-03 1/week @ 2024-04-10 1/week @ 2024-04-17 9/week @ 2024-04-24 30/week @ 2024-05-01 48/week @ 2024-05-08 31/week @ 2024-05-15 39/week @ 2024-05-22 41/week @ 2024-05-29 21/week @ 2024-06-05 28/week @ 2024-06-12 12/week @ 2024-06-19

75 downloads per month

MIT license

1MB
620 lines

tracing-newrelic

New Relic integration for tracing

Overview

This crate provides a layer for collecting trace data from tracing and sending them to New Relic.

tracing::Span will be tried as Trace Span, and tracing::Event as Logs.

tracing::Attribute and tracing::Metadata wil be tried as Custom Attributes.

Examples

use std::thread::sleep;
use std::time::Duration;

use tracing_subscriber::{layer::SubscriberExt, Registry};

#[tracing::instrument(name = "fibonacci()")]
fn fibonacci(n: u32) -> u32 {
    let ms = 100 * n as u64;

    tracing::info!(n = n, "sleep {}ms", ms);

    sleep(Duration::from_millis(ms));

    match n {
        0 | 1 => 1,
        _ => fibonacci(n - 1) + fibonacci(n - 2),
    }
}

fn main() {
    env_logger::init();

    let newrelic = tracing_newrelic::layer("YOUR-API-KEY");

    let fmt = tracing_subscriber::fmt::layer();

    let subscriber = Registry::default().with(newrelic).with(fmt);

    tracing::subscriber::with_default(subscriber, || {
        let span = tracing::info_span!(
            "calculating fibonacci(3)",
            service.name = "tracing-newrelic-demo"
        );

        let _enter = span.enter();

        fibonacci(3);
    });
}
  1. Replace YOUR-API-KEY above with your api key and run it.

  2. Open New Relic One, navigate to Entity explorer and search for tracing-newrelic-demo.

  3. You should see a entry span named calculating fibonacci(3) and click it for more details:

newrelic screenshot
  1. Click See logs to view all events inside this span:
newrelic screenshot

And I strongly recommend include these attributes in your spans:

  1. span.kind

    New Relic creates throught and response time dashboards for spans with span.kind set to server and consumer.

    newrelic throughtput-reponse-time
  2. otel.status_code & otel.status_description

    New Relic creates error rate dashboard for spans with otel.status_code set to ERROR.

    newrelic error-rate
  3. service.name

    New Relic group entity by their service.name field.

    newrelic services
  4. name

    New Relic group trnsations by their name field.

    newrelic transactions

License

MIT

Dependencies

~7–21MB
~326K SLoC