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
//! A tracing layer that sends logs to [Datadog](https://docs.datadoghq.com/api/latest/logs/?code-lang=typescript#send-logs).
//!
//! It's mainly useful when you don't have access to your infrastructure and you cannot use the [Datadog Agent](https://docs.datadoghq.com/agent/) or any [other mean](https://docs.datadoghq.com/logs/log_collection/?tab=host#setup).
//!
//! ## Example
//!
//! ```rust
//!#[instrument]
//!fn log(msg: &'static str) {
//!  tracing::info!(format!("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!");
//!}
//!```
mod datadog_ingestor;

pub use datadog_ingestor::DatadogOptions;
pub use log_tracing_layer::LogLayer;

/// Creates a log layer that will send logs to Datadog
#[must_use]
pub fn create(options: DatadogOptions) -> LogLayer {
    let ingestor = datadog_ingestor::DatadogLogIngestor::new(options);
    LogLayer::new(ingestor)
}