| Crates.io | tracing-loki-fmt |
| lib.rs | tracing-loki-fmt |
| version | 0.1.2 |
| created_at | 2025-05-05 14:55:38.693411+00 |
| updated_at | 2025-05-05 15:04:20.635638+00 |
| description | Grafana Loki tracing layer |
| homepage | |
| repository | https://github.com/KoHcoJlb/tracing-loki-fmt |
| max_upload_size | |
| id | 1660806 |
| size | 68,056 |
Layer that pushes logs formatted with tracing-subscriber into Grafana Loki and
attaching all fields
as Loki's structured metadata.
It combines both log readability and convenient manipulation (filtering | field = "value", aggregation, etc)
without the need for parsing.
use eyre::Result;
use std::time::Duration;
use tokio::spawn;
use tokio::time::sleep;
use tracing::{info, info_span};
use tracing_loki_fmt::Builder;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{fmt, registry};
#[tokio::main]
async fn main() -> Result<()> {
let builder = Builder::new(
"http://grafana.proxmox/loki/api/v1/push",
fmt::layer().without_time(),
)?;
let (layer, task) = builder
.add_label("this_is_label", "test456")
.add_label("job", "test")
.add_field("this_is_static_field", "Test6666")
.build();
spawn(task.run());
registry()
.with(fmt::layer())
.with(layer)
.init();
let _span1 = info_span!("span1", hello = "world").entered();
let _span2 = info_span!("span2", world = "test").entered();
info!(test = 123, test1 = "456", "hello world");
sleep(Duration::from_secs(15)).await;
Ok(())
}