#tracing-layer #tracing #logging-tracing #loki #grafana #tracing-subscriber #shipping

tracing-loki

用于将日志发送到 Grafana Loki 的跟踪层

8 个版本

0.2.5 2024年6月12日
0.2.4 2023年8月1日
0.2.3 2023年6月16日
0.2.2 2023年3月8日
0.0.0 2022年3月19日

#87 in 调试

Download history 14627/week @ 2024-05-03 17746/week @ 2024-05-10 17689/week @ 2024-05-17 18726/week @ 2024-05-24 20437/week @ 2024-05-31 15707/week @ 2024-06-07 17405/week @ 2024-06-14 20351/week @ 2024-06-21 17635/week @ 2024-06-28 11144/week @ 2024-07-05 11202/week @ 2024-07-12 10974/week @ 2024-07-19 9698/week @ 2024-07-26 10415/week @ 2024-08-02 10440/week @ 2024-08-09 11010/week @ 2024-08-16

43,963 每月下载量
用于 7 个代码包 (6 直接)

MIT/Apache

57KB
1K SLoC

tracing-loki

tracing 提供的 Grafana Loki 跟踪层。

Build status

文档

https://docs.rs/tracing-loki

用法

将此添加到您的 Cargo.toml

[dependencies]
tracing-loki = "0.1"

示例

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

依赖项

~7–19MB
~269K SLoC