项目作者: PoiScript

项目描述 :
New Relic integration for tracing
高级语言: Rust
项目地址: git://github.com/PoiScript/tracing-newrelic.git
创建时间: 2020-12-23T16:37:15Z
项目社区:https://github.com/PoiScript/tracing-newrelic

开源协议:MIT License

下载


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

  1. use std::thread::sleep;
  2. use std::time::Duration;
  3. use tracing_subscriber::{layer::SubscriberExt, Registry};
  4. #[tracing::instrument(name = "fibonacci()")]
  5. fn fibonacci(n: u32) -> u32 {
  6. let ms = 100 * n as u64;
  7. tracing::info!(n = n, "sleep {}ms", ms);
  8. sleep(Duration::from_millis(ms));
  9. match n {
  10. 0 | 1 => 1,
  11. _ => fibonacci(n - 1) + fibonacci(n - 2),
  12. }
  13. }
  14. fn main() {
  15. env_logger::init();
  16. let newrelic = tracing_newrelic::layer("YOUR-API-KEY");
  17. let fmt = tracing_subscriber::fmt::layer();
  18. let subscriber = Registry::default().with(newrelic).with(fmt);
  19. tracing::subscriber::with_default(subscriber, || {
  20. let span = tracing::info_span!(
  21. "calculating fibonacci(3)",
  22. service.name = "tracing-newrelic-demo"
  23. );
  24. let _enter = span.enter();
  25. fibonacci(3);
  26. });
  27. }
  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