Automatic Instrumentation

Learn what instrumentation automatically captures transactions.

Capturing transactions requires that you first set up tracing if you haven't already.

The Rust SDK offers an integration for the tracing ecosystem that will track spans automatically for every function that is annotated with #[tracing::instrument].

The integration takes care of starting a new transaction or a new child span of an already running transaction, and it automatically sets the created span as the current span.

fn main() {

    let _sentry = sentry::init(sentry::ClientOptions {
        release: sentry::release_name!(),
        traces_sample_rate: 1.0,


fn main_span1() {


fn main_span2() {

The Sentry SDK offers an integration for the tower ecosystem which can automatically continue a trace from an incoming HTTP request.

When combining both layers, order matters. For example, with tower::ServiceBuilder, you must define the Hub layer before the Http one, like so:

use sentry_tower::{NewSentryLayer, SentryHttpLayer};
use tower::ServiceBuilder;

let layer = ServiceBuilder::new()
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").