getsentry / sentry-rust

Official Sentry SDK for Rust
https://sentry.io/
Apache License 2.0
620 stars 153 forks source link

Breadcrumbs from Multiple Requests Mixing in Sentry Traces #616

Closed ferologics closed 1 year ago

ferologics commented 1 year ago

We're using sentry-rust with Actix-web and the tracing integration. We've encountered an issue where Sentry traces for errors contain breadcrumbs from multiple incoming requests. Our goal is to ensure that breadcrumbs are associated only with the specific request that generated them, similar to the behavior of tracing-actix-web.

We've considered using sentry-actix, but we want finer control over error reporting and prefer sending errors via tracing::error!().

One approach we've looked into is creating a custom middleware to manage the Sentry hub and scope across threads. However, this feels somewhat manual and might not be the most efficient solution.

Is there a recommended or more streamlined way to achieve isolated breadcrumbs per request without relying on sentry-actix's automatic error reporting?

Swatinem commented 1 year ago

You should be able to turn of automatic error capturing with the builder methods, like so:

sentry_actix::Sentry::builder().capture_server_errors(false).finish()

That should give you Hub isolation and more metadata on the scope for each request, as well as the option to start a performance monitoring transaction with start_transaction(true).

ferologics commented 1 year ago

thank you @Swatinem, this is exactly the kind of answer i was hoping for, we deployed the change and will be testing how it does over then next week 🤞

ferologics commented 1 year ago

so far seems to be working well, thanks!