Automatic Instrumentation
Capturing transactions requires that you first set up performance monitoring if you haven't already.
tracing
Integration
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));
}
HTTP Instrumentation
The Sentry SDK offers an integration for the tower
ecosystem which can automatically continue a trace from an incoming HTTP request.
Copied
use sentry_tower::{NewSentryLayer, SentryHttpLayer};
use tower::ServiceBuilder;
let layer = ServiceBuilder::new()
// continue trace from incoming request
.layer(SentryHttpLayer::with_transaction())
// bind a new hub for each request
.layer(NewSentryLayer::new_from_top());
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to 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!) to suggesting an update ("yeah, this would be better").
Suggest an edit to this page | Contribute to Docs | Report a problem
🎉 Thank you for your feedback! 🙌
- Package:
- cargo:sentry
- Version:
- 0.31.7
- Repository:
- https://github.com/getsentry/sentry-rust