dd_tracing_layer/lib.rs
1//! A tracing layer that sends logs to [Datadog](https://docs.datadoghq.com/api/latest/logs/?code-lang=typescript#send-logs).
2//!
3//! 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).
4//!
5//! ## Example
6//!
7//! ```rust
8//! use dd_tracing_layer::DatadogOptions;
9//! use tracing_subscriber::prelude::*;
10//! use tracing::{instrument, subscriber};
11//!
12//! #[instrument]
13//! fn log(msg: &'static str) {
14//! tracing::info!("your message: {}", msg);
15//! }
16//!
17//! fn main() {
18//! let options = DatadogOptions::new("my-service", "my-datadog-api-key")
19//! .with_tags("env:dev");
20//! let dd = dd_tracing_layer::create(options);
21//! let subscriber = tracing_subscriber::registry()
22//! .with(tracing_subscriber::fmt::Layer::new().json())
23//! .with(dd);
24//! let _s = subscriber::set_default(subscriber);
25//! log("hello world!");
26//! }
27//!```
28mod datadog_ingestor;
29
30pub use datadog_ingestor::{DatadogOptions, Region};
31pub use log_tracing_layer::LogLayer;
32
33/// Creates a log layer that will send logs to Datadog
34#[must_use]
35pub fn create(options: DatadogOptions) -> LogLayer {
36 let ingestor = datadog_ingestor::DatadogLogIngestor::new(options);
37 LogLayer::new(ingestor)
38}