Skip to content

A tracing layer for shipping logs to Grafana Loki

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

hrxi/tracing-loki

Folders and files

NameName
Last commit message
Last commit date

Latest commit

c733081 Â· Mar 19, 2025

History

45 Commits
Aug 1, 2023
Aug 1, 2023
Jan 13, 2025
Dec 4, 2024
Mar 22, 2022
Aug 1, 2023
Jan 13, 2025
Jan 13, 2025
Aug 20, 2023
Aug 20, 2023
Mar 19, 2025

Repository files navigation

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(())
}

About

A tracing layer for shipping logs to Grafana Loki

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages