Connect Rust to Bugsink

When a Rust application fails, Bugsink gives you the panic or error, the available stack trace, and the context you need to investigate it.

This guide covers the initial setup, the main ways to report failures, and the useful context you can attach to them. You’ll start by connecting an application and triggering a deliberate panic to confirm that it reaches Bugsink.

To follow along, create a Bugsink project and copy its DSN. The quickstart guide shows where to find it.

Install the SDK

Add the open-source Sentry Rust SDK to your Cargo project. Bugsink accepts the Sentry event protocol, so the SDK can send events directly to your Bugsink project:

cargo add sentry --no-default-features \
    --features backtrace,contexts,panic,reqwest,rustls
cargo add sentry-log log env_logger

Configure your DSN

Initialize the SDK before starting worker threads or an async runtime. Reading the DSN from the environment keeps it out of source control; keeping the returned guard alive lets the SDK drain queued events when the process exits:

let _sentry = sentry::init((
    env::var("SENTRY_DSN").unwrap_or_default(),
    sentry::ClientOptions::new().release("inventory-rust@0.1.0"),
));

Set SENTRY_DSN to the DSN shown by your Bugsink project when you run the application:

export SENTRY_DSN=https://key@bugsink.example/1

Send a test error

Temporarily add a panic to a code path you can run. The SDK’s panic integration reports it automatically while Rust still prints the panic and exits normally:

panic!("Bugsink Rust setup check");

Run that code path once.

See the error in Bugsink

Open your Bugsink project. The new panic issue contains the message and the Rust application frame where the panic happened.

Bugsink preview: Rust panic
Bugsink preview

That’s it: your application is connected. Remove the deliberate panic; unhandled panics will continue to be reported automatically.

Capture other kinds of errors

Panics are automatic, but they are not the only failures worth reporting. You can also capture errors your code handles, error-level log records, and exceptional conditions that do not have an error value.

Handled errors

Handled errors do not reach the panic hook, because your application recovered from them. Call capture_error() when the failure should still appear in Bugsink; it accepts any normal std::error::Error and does not change your control flow or return value:

if let Err(error) = reserve_product(sku) {
    sentry::capture_error(&error);
}

The error remains handled and appears as a ProductNotFound issue.

Bugsink preview: handled Rust error
Bugsink preview

Log records

Log records can use the same log facade your application already calls. Wrap your logger with sentry-log: records at Error become Bugsink events, while the preceding Info and Warning records become breadcrumbs on the next event. The target becomes the logger name shown in Bugsink:

fn initialize_logging() {
    let mut destination = env_logger::Builder::new();
    destination.filter_level(log::LevelFilter::Info);
    let logger = sentry_log::SentryLogger::with_dest(destination.build());
    log::set_boxed_logger(Box::new(logger)).expect("logger is initialized once");
    log::set_max_level(log::LevelFilter::Info);
}
:::rust
log::error!(target: "inventory", "Warehouse feed is unavailable");

Bugsink preview: error log record
Bugsink preview

Messages without errors

Messages report an exceptional condition without constructing an error. Use capture_message() for a failed defensive check or an unresponsive queue and choose the severity Bugsink should use. There is no exception stack, so prefer an error or panic when either is a natural fit:

sentry::capture_message("Inventory queue is not responding", Level::Error);

Bugsink preview: captured message
Bugsink preview

Add useful context

An error tells you what failed; context helps explain why. Values added to the current scope are attached to later events, so set them at the boundary where the relevant job, request, or operation begins.

Tags

Tags make events searchable by short key/value pairs. Bugsink already records standard values such as release; use set_tag() for your own component, region, plan, or feature flag. This adds component:inventory to later events on the current scope:

scope.set_tag("component", "inventory");

Bugsink preview: component tag
Bugsink preview

Structured context

Structured context adds a named group of details you want to inspect but do not need to search. Build a value map and pass it as Context::Other; this creates an Inventory section containing the SKU and warehouse on later events:

let mut inventory = BTreeMap::new();
inventory.insert("sku".into(), Value::String(sku.into()));
inventory.insert("warehouse".into(), Value::String("eu-west".into()));
scope.set_context("inventory", Context::Other(inventory));

Bugsink preview: inventory context
Bugsink preview

Breadcrumbs record what happened before an error without creating an issue of their own. Add them for application steps the SDK cannot know about, such as a reservation attempt or retry. The next captured event includes the category, message, level, and any structured data:

let mut data = BTreeMap::new();
data.insert("sku".into(), Value::String(sku.into()));
sentry::add_breadcrumb(Breadcrumb {
    category: Some("inventory".into()),
    message: Some("Starting inventory reservation".into()),
    level: Level::Info,
    data,
    ..Default::default()
});

Bugsink preview: breadcrumb
Bugsink preview

Application lifecycle

The first example is enough to send events, but three lifecycle details matter once the SDK is part of a real service or command.

Name your releases

Releases tell you which version of your application produced an event. Pass a stable, application-specific value through ClientOptions::release()—for example inventory-rust@0.1.0—and update it with each build. Every event from that build then carries the same release value in Bugsink.

Let events drain on shutdown

The guard returned by sentry::init() flushes the transport when it is dropped, using the configured shutdown timeout. Keep it in the outermost scope for the full process lifetime. Exiting immediately with process::exit() or discarding the guard can lose events that are still queued.

Initialize before async runtimes

Create the SDK client before Tokio, Actix, or another multithreaded runtime so new threads inherit the configured hub. This means using a normal fn main() and constructing the runtime inside it instead of initializing Sentry from an attribute-generated async main function.

Limitations

capture_error() reports the Rust error type and value, but does not attach the call-site stack to that handled error in this configuration. Panics do include a native Rust stack. Captured messages and error-level log events also arrive without an application stack.

This setup covers error reporting. Performance transactions, structured logs, and release-health sessions use separate SDK features and are not configured here.

Rust web frameworks

Actix Web captures returned server errors automatically; Axum's Tower integration attaches requests to errors captured inside handlers.