nr_tracing_layer/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//! A tracing layer that sends logs to [New Relic](https://docs.newrelic.com/docs/logs/get-started/get-started-log-management/).
//!
//! ## Example
//!
//! ```rust
//! 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!");
//! }
//!```
mod new_relic_ingestor;

pub use log_tracing_layer::LogLayer;
pub use new_relic_ingestor::{NewRelicOptions, Region};

/// Creates a log layer that will send logs to New Relic.
#[must_use]
pub fn create(options: NewRelicOptions) -> LogLayer {
    let ingestor = new_relic_ingestor::NewRelicLogIngestor::new(options);
    LogLayer::new(ingestor)
}