37 releases (17 breaking)

new 0.36.0 Jan 7, 2025
0.35.0 Nov 29, 2024
0.34.0 Jun 5, 2024
0.32.2 Jan 30, 2024
0.19.0 Jun 18, 2020

#920 in Debugging

Download history 2484/week @ 2024-09-22 1824/week @ 2024-09-29 2095/week @ 2024-10-06 2320/week @ 2024-10-13 2749/week @ 2024-10-20 1904/week @ 2024-10-27 2324/week @ 2024-11-03 2480/week @ 2024-11-10 2279/week @ 2024-11-17 1789/week @ 2024-11-24 2362/week @ 2024-12-01 2320/week @ 2024-12-08 1578/week @ 2024-12-15 556/week @ 2024-12-22 639/week @ 2024-12-29 2163/week @ 2025-01-05

4,995 downloads per month
Used in sentry

Apache-2.0

245KB
4.5K SLoC

Sentry

Sentry Rust SDK: sentry-slog

Sentry slog Integration.

This mainly provides the SentryDrain, which wraps another slog::Drain and can be configured to forward slog::Records to Sentry. The SentryDrain can be used to create a slog::Logger.

The integration also supports slog::KV pairs. They will be added to the breadcrumb data or the event extra properties respectively.

Examples

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")
);

The Drain can also be customized with a filter, and a mapper:

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,
    });

When a mapper is specified, a corresponding filter should also be provided.

Resources

License: Apache-2.0

Dependencies

~4–5.5MB
~102K SLoC