3 unstable releases

0.1.1 Mar 8, 2023
0.1.0 Mar 22, 2022
0.0.0 Mar 19, 2022

#5 in #loki

Download history 8753/week @ 2023-12-13 4674/week @ 2023-12-20 4316/week @ 2023-12-27 7442/week @ 2024-01-03 7839/week @ 2024-01-10 10428/week @ 2024-01-17 8838/week @ 2024-01-24 6139/week @ 2024-01-31 5763/week @ 2024-02-07 7334/week @ 2024-02-14 8346/week @ 2024-02-21 6968/week @ 2024-02-28 8837/week @ 2024-03-06 10199/week @ 2024-03-13 9703/week @ 2024-03-20 5104/week @ 2024-03-27

35,437 downloads per month
Used in 5 crates (2 directly)

MIT/Apache

14KB
303 lines

tracing-loki

A tracing layer for Grafana Loki.

Build status

Documentation

https://docs.rs/tracing-loki

Usage

Add this to your Cargo.toml:

[dependencies]
tracing-loki = "0.1"

Example

use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use std::process;
use url::Url;

#[tokio::main]
async fn main() -> Result<(), tracing_loki::Error> {
    let (layer, task) = tracing_loki::builder()
        .label("host", "mine")?
        .extra_field("pid", format!("{}", process::id()))?
        .build_url(Url::parse("http://127.0.0.1:3100").unwrap())?;

    // We need to register our layer with `tracing`.
    tracing_subscriber::registry()
        .with(layer)
        // One could add more layers here, for example logging to stdout:
        // .with(tracing_subscriber::fmt::Layer::new())
        .init();

    // The background task needs to be spawned so the logs actually get
    // delivered.
    tokio::spawn(task);

    tracing::info!(
        task = "tracing_setup",
        result = "success",
        "tracing successfully set up",
    );

    Ok(())
}

Dependencies

~2.5MB
~52K SLoC