Sentry
Seamlessly integrates with Sentry by wrapping the sentry crate and providing optional integration with logging & tracing.
Quickstart
- Enable the
sentryfeature.
cargo add strut --features sentry
- Configure the Sentry DSN (connection URL).
- All runtime panics will now be reported to Sentry.
If the tracing component is enabled, you can also send your tracing events to Sentry by adding
alert = truekey-value field.
use strut::tracing::*;
#[strut::main]
async fn main() {
error!(alert = true, "This will be also sent to Sentry");
}
Cargo features
⛳︎ Feature sentry
This is the main gateway feature of this component.
Component structure
☑︎ Configuration
At the most basic, you need to provide the Sentry DSN. An empty or omitted DSN will essentially disable the Sentry client.
- YAML
- TOML
sentry:
dsn: https://0123456789abcdef0123456789abcdef@012345.ingest.sentry.1o/9876543
[sentry]
dsn = "https://0123456789abcdef0123456789abcdef@012345.ingest.sentry.1o/9876543"
The full configuration is shown below.
- YAML
- TOML
sentry:
dsn: https://0123456789abcdef0123456789abcdef@012345.ingest.sentry.1o/9876543
debug: false
sample_rate: 1.0
traces_sample_rate: 0.0
max_breadcrumbs: 64
attach_stacktrace: false
shutdown_timeout: 2s # parsed using `humantime` crate
[sentry]
dsn = "https://0123456789abcdef0123456789abcdef@012345.ingest.sentry.1o/9876543"
debug = false
sample_rate = 1.0
traces_sample_rate = 0.0
max_breadcrumbs = 64
attach_stacktrace = false
shutdown_timeout = "2s" # parsed using `humantime` crate
For in-code reference, see SentryConfig.
☑︎ Startup
The startup logic of this component is called from the RuntimeWiring.
It involves creating and binding a Sentry client and then keeping the returned guard for the duration of the runtime.
∅ Facade
This component does not expose a facade.
☑︎ Spindown
The component automatically attempts to flush all unsent Sentry events during spindown by dropping the Sentry guard.
Tracing integration
If you also use the tracing component, you can easily create Sentry events from the tracing events.
Simply add alert = true key-value field:
use strut::tracing::*;
#[strut::main]
async fn main() {
error!(alert = true, "This will be also sent to Sentry");
}