4 releases

0.1.2 Jun 12, 2024
0.1.1 Mar 8, 2023
0.1.0 Mar 22, 2022
0.0.0 Mar 19, 2022

#2 in #loki

Download history 10963/week @ 2024-07-21 9309/week @ 2024-07-28 9812/week @ 2024-08-04 10083/week @ 2024-08-11 14054/week @ 2024-08-18 13526/week @ 2024-08-25 15499/week @ 2024-09-01 14463/week @ 2024-09-08 11732/week @ 2024-09-15 15554/week @ 2024-09-22 14745/week @ 2024-09-29 13339/week @ 2024-10-06 14531/week @ 2024-10-13 14252/week @ 2024-10-20 10785/week @ 2024-10-27 11368/week @ 2024-11-03

51,579 downloads per month
Used in 11 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

~450KB