Automatic Instrumentation
Capturing transactions requires that you first set up performance monitoring 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.
Copied
fn main() {
tracing_subscriber::Registry::default()
.with(sentry::integrations::tracing::layer())
.init();
let _sentry = sentry::init(sentry::ClientOptions {
release: sentry::release_name!(),
traces_sample_rate: 1.0,
..Default::default()
});
main_span1();
}
#[tracing::instrument]
fn main_span1() {
thread::sleep(Duration::from_millis(50));
main_span2()
}
#[tracing::instrument]
fn main_span2() {
thread::sleep(Duration::from_millis(200));
}
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:
Copied
use sentry_tower::{NewSentryLayer, SentryHttpLayer};
use tower::ServiceBuilder;
let layer = ServiceBuilder::new()
.layer(NewSentryLayer::new_from_top())
.layer(SentryHttpLayer::with_transaction());
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").
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").
- Package:
- cargo:sentry
- Version:
- 0.32.2
- Repository:
- https://github.com/getsentry/sentry-rust