25 releases

0.32.2 Jan 30, 2024
0.32.1 Dec 18, 2023
0.32.0 Nov 28, 2023
0.31.5 Jun 16, 2023
0.23.0 Jul 8, 2021

#62 in Debugging

Download history 64728/week @ 2023-11-05 84191/week @ 2023-11-12 62959/week @ 2023-11-19 90761/week @ 2023-11-26 73007/week @ 2023-12-03 73979/week @ 2023-12-10 86736/week @ 2023-12-17 26061/week @ 2023-12-24 60025/week @ 2023-12-31 76952/week @ 2024-01-07 70519/week @ 2024-01-14 80923/week @ 2024-01-21 78459/week @ 2024-01-28 76894/week @ 2024-02-04 83448/week @ 2024-02-11 63484/week @ 2024-02-18

305,411 downloads per month
Used in 13 crates (4 directly)


4.5K SLoC


Sentry Rust SDK: sentry-tracing

Support for automatic breadcrumb, event, and trace capturing from tracing events.

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.


To fully enable the tracing integration, set the traces sample rate and add a layer to the tracing subscriber:

use tracing_subscriber::prelude::*;

let _guard = sentry::init(sentry::ClientOptions {
    // Enable capturing of traces; set this a to lower value in production:
    traces_sample_rate: 1.0,

// Register the Sentry tracing layer to capture breadcrumbs, events, and spans:

It is also possible to set an explicit filter, to customize which log events are captured by Sentry:

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

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


Logging Messages

Tracing events automatically create breadcrumbs that are attached to the current scope in Sentry. They show up on errors and transactions captured within this scope as shown in the examples below.

Fields passed to the event macro are automatically tracked as structured data in Sentry. For breadcrumbs, they are shown directly with the breadcrumb message. For other types of data, read below.

for i in 0..10 {
    tracing::debug!(number = i, "Generates a breadcrumb");

Tracking Errors

The easiest way to emit errors is by logging an event with ERROR level. This will create a grouped issue in Sentry. To add custom information, prepend the message with fields. It is also possible to add Sentry tags if a field is prefixed with "tags."

    field = "value",                  // will become a context field
    tags.custom = "value",            // will become a tag in Sentry
    "this is an error with a custom tag",

To track error structs, assign a reference to error trait object as field in one of the logging macros. By convention, it is recommended to use the ERROR level and assign it to a field called error, although the integration will also work with all other levels and field names.

All other fields passed to the macro are captured in a custom "Tracing Fields" context in Sentry.

use std::error::Error;
use std::io;

let custom_error = io::Error::new(io::ErrorKind::Other, "oh no");
tracing::error!(error = &custom_error as &dyn Error);

It is also possible to combine error messages with error structs. In Sentry, this creates issues grouped by the message and location of the error log, and adds the passed error as nested source.

use std::error::Error;
use std::io;

let custom_error = io::Error::new(io::ErrorKind::Other, "oh no");
tracing::error!(error = &custom_error as &dyn Error, "my operation failed");

Tracing Spans

The integration automatically tracks tracing spans as spans in Sentry. A convenient way to do this is with the #[instrument] attribute macro, which creates a transaction for the function in Sentry.

Function arguments are added as context fields automatically, which can be configured through attribute arguments. Refer to documentation of the macro for more information.

use std::time::Duration;

use tracing_subscriber::prelude::*;

// Functions instrumented by tracing automatically report
// their span as transactions.
async fn outer() {
    for i in 0..10 {

// This creates spans inside the outer transaction, unless called directly.
async fn inner(i: u32) {
    // Also works, since log events are ingested by the tracing system
    tracing::debug!(number = i, "Generates a breadcrumb");



License: Apache-2.0


~152K SLoC