#tracing #loki

tracing-loki

A tracing layer for shipping logs to Grafana Loki

4 releases (2 breaking)

Uses new Rust 2021

0.2.1 Jul 2, 2022
0.2.0 May 11, 2022
0.1.0 Mar 22, 2022
0.0.0 Mar 19, 2022

#166 in Debugging

Download history 2556/week @ 2022-04-25 3708/week @ 2022-05-02 3702/week @ 2022-05-09 3871/week @ 2022-05-16 3391/week @ 2022-05-23 3611/week @ 2022-05-30 3410/week @ 2022-06-06 3413/week @ 2022-06-13 3492/week @ 2022-06-20 3575/week @ 2022-06-27 3654/week @ 2022-07-04 3694/week @ 2022-07-11 4032/week @ 2022-07-18 3942/week @ 2022-07-25 4358/week @ 2022-08-01 3664/week @ 2022-08-08

16,537 downloads per month

MIT/Apache

44KB
983 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 url::Url;

#[tokio::main]
async fn main() -> Result<(), tracing_loki::Error> {
    let (layer, task) = tracing_loki::layer(
        Url::parse("http://127.0.0.1:3100").unwrap(),
        vec![("host".into(), "mine".into())].into_iter().collect(),
        vec![].into_iter().collect(),
    )?;

    // 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

~7–16MB
~310K SLoC