35个版本

0.34.0 2024年6月5日
0.32.3 2024年4月16日
0.32.2 2024年1月30日
0.32.1 2023年12月18日
0.19.0 2020年6月18日

766调试 中排名

Download history 3203/week @ 2024-04-29 2113/week @ 2024-05-06 2908/week @ 2024-05-13 3042/week @ 2024-05-20 2129/week @ 2024-05-27 2403/week @ 2024-06-03 2831/week @ 2024-06-10 2474/week @ 2024-06-17 2454/week @ 2024-06-24 2409/week @ 2024-07-01 2580/week @ 2024-07-08 2437/week @ 2024-07-15 2797/week @ 2024-07-22 2859/week @ 2024-07-29 2121/week @ 2024-08-05 2411/week @ 2024-08-12

每月10,256次下载
sentry 中使用

Apache-2.0

235KB
4.5K SLoC

Sentry

Sentry Rust SDK: sentry-slog

Sentry slog 集成。

此集成主要提供 SentryDrain,它包装另一个 slog::Drain 并可以配置将 slog::Record 记录发送到Sentry。可以使用 SentryDrain 创建一个 slog::Logger

集成还支持 slog::KV 对。它们将分别添加到面包屑 data 或事件的 extra 属性中。

示例

use sentry_slog::SentryDrain;

let _sentry = sentry::init(());

let drain = SentryDrain::new(slog::Discard);
let root = slog::Logger::root(drain, slog::o!("global_kv" => 1234));

slog::info!(root, "recorded as breadcrumb"; "breadcrumb_kv" => Some("breadcrumb"));
slog::warn!(root, "recorded as regular event"; "event_kv" => "event");

let breadcrumb = &captured_event.breadcrumbs.as_ref()[0];
assert_eq!(
    breadcrumb.message.as_deref(),
    Some("recorded as breadcrumb")
);
assert_eq!(breadcrumb.data["breadcrumb_kv"], "breadcrumb");
assert_eq!(breadcrumb.data["global_kv"], 1234);

assert_eq!(
    captured_event.message.as_deref(),
    Some("recorded as regular event")
);
assert_eq!(captured_event.extra["event_kv"], "event");
assert_eq!(captured_event.extra["global_kv"], 1234);

slog::crit!(root, "recorded as exception event");

assert_eq!(
    captured_event.message.as_deref(),
    Some("recorded as exception event")
);

Drain还可以使用 filtermapper 进行自定义

use sentry_slog::{exception_from_record, LevelFilter, RecordMapping, SentryDrain};

let drain = SentryDrain::new(slog::Discard)
    .filter(|level| match level {
        slog::Level::Critical | slog::Level::Error => LevelFilter::Event,
        _ => LevelFilter::Ignore,
    })
    .mapper(|record, kv| match record.level() {
        slog::Level::Critical | slog::Level::Error => {
            RecordMapping::Event(exception_from_record(record, kv))
        }
        _ => RecordMapping::Ignore,
    });

指定 mapper 时,也应提供相应的 filter

资源

许可证:Apache-2.0

依赖

约3.5–4.5MB
约116K SLoC