#tracing #loki

tracing-loki

A tracing layer for shipping logs to Grafana Loki

5 unstable releases

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

#59 in Debugging

Download history 4611/week @ 2022-11-28 4468/week @ 2022-12-05 4917/week @ 2022-12-12 4561/week @ 2022-12-19 4301/week @ 2022-12-26 5240/week @ 2023-01-02 5706/week @ 2023-01-09 5468/week @ 2023-01-16 6920/week @ 2023-01-23 7430/week @ 2023-01-30 7237/week @ 2023-02-06 6919/week @ 2023-02-13 7670/week @ 2023-02-20 7033/week @ 2023-02-27 7738/week @ 2023-03-06 7882/week @ 2023-03-13

31,114 downloads per month

MIT/Apache

54KB
1K SLoC

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

~8–16MB
~310K SLoC