7 releases (4 breaking)

Uses new Rust 2021

0.27.0 Jun 20, 2022
0.26.0 May 20, 2022
0.25.0 Mar 2, 2022
0.24.3 Feb 8, 2022
0.23.0 Jul 8, 2021

#10 in #sentry

Download history 11878/week @ 2022-04-22 7822/week @ 2022-04-29 7699/week @ 2022-05-06 6873/week @ 2022-05-13 6648/week @ 2022-05-20 8027/week @ 2022-05-27 9733/week @ 2022-06-03 10495/week @ 2022-06-10 10361/week @ 2022-06-17 12757/week @ 2022-06-24 15166/week @ 2022-07-01 15930/week @ 2022-07-08 17284/week @ 2022-07-15 17873/week @ 2022-07-22 17965/week @ 2022-07-29 13168/week @ 2022-08-05

69,230 downloads per month
Used in 2 crates (via sentry)

Apache-2.0

160KB
3K SLoC

Sentry

Sentry Rust SDK: sentry-tracing

Adds support for automatic Breadcrumb, Event and Transaction capturing from tracing events, similar to the sentry-log crate.

The tracing crate is supported in three ways. First, events can be captured as breadcrumbs for later. Secondly, error events can be captured as events to Sentry. Finally, spans can be recorded as structured transaction events. By default, events above Info are recorded as breadcrumbs, events above Error are captured as error events, and spans above Info are recorded as transactions.

By using this crate in combination with tracing-subscriber and its log integration, sentry-log does not need to be used, as logs will be ingested in the tracing system and generate events, thus be relayed to this crate. It effectively replaces sentry-log when tracing is used.

Examples

use std::time::Duration;

use tokio::time::sleep;
use tracing_subscriber::prelude::*;

#[tokio::main]
async fn main() {
    let _guard = sentry::init(sentry::ClientOptions {
        // Set this a to lower value in production
        traces_sample_rate: 1.0,
        ..sentry::ClientOptions::default()
    });

    tracing_subscriber::registry()
        .with(tracing_subscriber::fmt::layer())
        .with(sentry_tracing::layer())
        .init();

    outer().await;
}

// Functions instrumented by tracing automatically report
// their span as transactions
#[tracing::instrument]
async fn outer() {
    tracing::info!("Generates a breadcrumb");

    for _ in 0..10 {
        inner().await;
    }

    tracing::error!("Generates an event");
}

#[tracing::instrument]
async fn inner() {
    // Also works, since log events are ingested by the tracing system
    log::info!("Generates a breadcrumb");

    sleep(Duration::from_millis(100)).await;

    log::error!("Generates an event");
}

Or one might also set an explicit filter, to customize how to treat log records:

use sentry_tracing::EventFilter;
use tracing_subscriber::prelude::*;

let layer = sentry_tracing::layer().event_filter(|md| match md.level() {
    &tracing::Level::ERROR => EventFilter::Event,
    _ => EventFilter::Ignore,
});

tracing_subscriber::registry().with(layer).init();

Resources

License: Apache-2.0

Dependencies

~5MB
~127K SLoC