#loki #tracing #api #tracing-loki

loki-api

Protobuf types used by the Grafana Loki HTTP API

5 releases

0.1.3 Jan 13, 2025
0.1.2 Jun 12, 2024
0.1.1 Mar 8, 2023
0.1.0 Mar 22, 2022
0.0.0 Mar 19, 2022

#552 in Debugging

Download history 2818/week @ 2024-12-24 8490/week @ 2024-12-31 19908/week @ 2025-01-07 19973/week @ 2025-01-14 17912/week @ 2025-01-21 18013/week @ 2025-01-28 23543/week @ 2025-02-04 25041/week @ 2025-02-11 15248/week @ 2025-02-18 15583/week @ 2025-02-25 17250/week @ 2025-03-04 21189/week @ 2025-03-11 19581/week @ 2025-03-18 21451/week @ 2025-03-25 20769/week @ 2025-04-01 21388/week @ 2025-04-08

87,690 downloads per month
Used in 10 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.2"

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

~500KB