Crates.io | dd-tracing-layer |
lib.rs | dd-tracing-layer |
version | 0.5.0 |
source | src |
created_at | 2023-01-29 23:40:10.623593 |
updated_at | 2024-11-23 21:28:58.883233 |
description | Send your logs to Datadog |
homepage | |
repository | https://github.com/robertohuertasm/log-tracing-layer |
max_upload_size | |
id | 771283 |
size | 20,217 |
A tracing layer that sends logs to the Datadog Log API.
It's mainly useful when you don't have access to your infrastructure and you cannot use the Datadog Agent or any other mean.
You'll need a Datadog API Key for everything to work.
This crate uses the v2
logs endpoints and, by default, will try to send the logs to the US1
region.
You can easily change the region or provide a custom URL if needed.
Here's a simple example of how to set it up and use it:
use dd_tracing_layer::DatadogOptions;
use tracing_subscriber::prelude::*;
use tracing::{instrument, subscriber};
#[instrument]
fn log(msg: &'static str) {
tracing::info!("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!");
}
The layer will send the logs either 5 seconds after the last log is received or when the buffer arrives to 1000 logs. This is basically due to a limitation in the Datadog API.