Expand description
This crate provides support for logging events and errors / panics to the Sentry error logging service. It integrates with the standard panic system in Rust as well as a few popular error handling setups.
§Quickstart
The most convenient way to use this library is via the sentry::init
function,
which starts a sentry client with a default set of integrations, and binds
it to the current Hub
. More Information on how to use Sentry in parallel,
concurrent and async scenarios can be found on the Hub
docs as well.
The sentry::init
function returns a guard that when dropped will flush Events that were not
yet sent to the sentry service. It has a two second deadline for this so shutdown of
applications might slightly delay as a result of this. Keep the guard around or sending events
will not work.
let _guard = sentry::init("https://key@sentry.io/42");
sentry::capture_message("Hello World!", sentry::Level::Info);
// when the guard goes out of scope here, the client will wait up to two
// seconds to send remaining events to the service.
More complex examples on how to use sentry can also be found in examples. Extended instructions may also be found on Sentry itself.
§Integrations
What makes this crate useful are its various integrations. Some of them are enabled by default; See Features. Uncommon integrations or integrations for deprecated parts of the ecosystem require a feature flag. For available integrations and how to use them, see integrations and apply_defaults.
§Minimal API
This crate comes fully-featured. If the goal is to instrument libraries for usage
with sentry, or to extend sentry with a custom Integration
or a Transport
,
one should use the sentry-core
crate instead.
§Features
Additional functionality and integrations are enabled via feature flags. Some features require extra setup to function properly.
Feature | Default | Is Integration | Deprecated | Additional notes |
---|---|---|---|---|
backtrace | ✅ | 🔌 | ||
contexts | ✅ | 🔌 | ||
panic | ✅ | 🔌 | ||
transport | ✅ | |||
anyhow | 🔌 | |||
test | ||||
debug-images | ✅ | 🔌 | ||
log | 🔌 | Requires extra setup; See sentry-log ’s documentation. | ||
debug-logs | ❗ | Requires extra setup; See sentry-log ’s documentation. | ||
slog | 🔌 | Requires extra setup; See sentry-slog ’s documentation. | ||
reqwest | ✅ | |||
native-tls | ✅ | reqwest must be enabled. | ||
rustls | reqwest must be enabled. native-tls must be disabled via default-features = false . | |||
curl | ||||
surf | ||||
tower | 🔌 | Requires extra setup; See sentry-tower ’s documentation. | ||
ureq | ureq transport support using rustls by default | |||
ureq-native-tls |
§Default features
backtrace
: Enables backtrace support.contexts
: Enables capturing device, OS, and Rust contexts.panic
: Enables support for capturing panics.transport
: Enables the default transport, which is currentlyreqwest
withnative-tls
.debug-images
: Enables capturing metadata about the loaded shared libraries.
§Debugging/Testing
anyhow
: Enables support for theanyhow
crate.test
: Enables testing support.
§Logging
log
: Enables support for thelog
crate.slog
: Enables support for theslog
crate.debug-logs
: Deprecated. Uses thelog
crate for internal logging.
§Transports
reqwest
: Default. Enables thereqwest
transport.native-tls
: Default. Uses thenative-tls
crate. This only affects thereqwest
transport.rustls
: Enablesrustls
support forreqwest
. Please note thatnative-tls
is a default feature, anddefault-features = false
must be set to completely disable buildingnative-tls
dependencies.curl
: Enables thecurl
transport.surf
: Enables thesurf
transport.ureq
: Enables theureq
transport usingrustls
.ureq-native-tls
: Enables theureq
transport usingnative-tls
.
§Integrations
tower
: Enables support for thetower
crate and those using it.
Modules§
- cadence
cadence
integration for Sentry.- integrations
- Available Sentry Integrations.
- metrics
- Utilities to track metrics in Sentry.
- protocol
- The current latest sentry protocol version.
- test
- This provides testing functionality for building tests.
- transports
- The provided transports.
- types
- This crate provides common types for working with the Sentry protocol or the Sentry server. It’s used by the Sentry Relay infrastructure as well as the rust Sentry client.
Macros§
- release_
name - Returns the intended release for Sentry as an
Option<Cow<'static, str>>
.
Structs§
- Breadcrumb
- Represents a single breadcrumb.
- Client
- The Sentry Client.
- Client
Init Guard - Helper struct that is returned from
init
. - Client
Options - Configuration settings for the client.
- Data
- A smart pointer to a span’s
data
field. - Envelope
- A Sentry Envelope.
- Hub
- The central object that can manage scopes and clients.
- HubSwitch
Guard - A Hub switch guard used to temporarily swap active hub in thread local storage.
- Scope
- Holds contextual data for the current scope.
- Scope
Guard - A scope guard.
- Sentry
Future - A future that binds a
Hub
to its execution. - Span
- A running Performance Monitoring Span.
- Trace
Headers Iter - An Iterator over HTTP header names and values needed for distributed tracing.
- Transaction
- A running Performance Monitoring Transaction.
- Transaction
Context - The Transaction Context used to start a new Performance Monitoring Transaction.
- Transaction
Context Builder - A transaction context builder created by
TransactionContext::builder
. - Transaction
Data - Iterable for a transaction’s
extra
field. - User
- Represents user info.
Enums§
- Level
- Represents the level of severity of an event or breadcrumb.
- Session
Mode - The Session Mode of the SDK.
- Transaction
OrSpan - A wrapper that groups a
Transaction
and aSpan
together.
Traits§
- Integration
- Integration abstraction.
- Into
Breadcrumbs - A helper trait that converts self into an Iterator of Breadcrumbs.
- IntoDsn
- Helper trait to convert a string into an
Option<Dsn>
. - Sentry
Future Ext - Future extensions for Sentry.
- Transport
- The trait for transports.
- Transport
Factory - A factory creating transport instances.
Functions§
- add_
breadcrumb - Records a breadcrumb by calling a function.
- apply_
defaults - Apply default client options.
- capture_
error - Captures a
std::error::Error
. - capture_
event - Captures an event on the currently active client if any.
- capture_
message - Captures an arbitrary message.
- configure_
scope - Invokes a function that can modify the current scope.
- end_
session - End the current Release Health Session.
- end_
session_ with_ status - End the current Release Health Session with the given
SessionStatus
. - event_
from_ error - Create a sentry
Event
from astd::error::Error
. - init
- Creates the Sentry client for a given client config and binds it.
- last_
event_ id - Returns the last event ID captured.
- parse_
type_ from_ debug - Parse the types name from
Debug
output. - start_
session - Start a new session for Release Health.
- start_
transaction - Start a new Performance Monitoring Transaction.
- with_
integration - Looks up an integration on the current Hub.
- with_
scope - Temporarily pushes a scope for a single call optionally reconfiguring it.
Type Aliases§
- Before
Callback - Type alias for before event/breadcrumb handlers.
- Custom
Transaction Context - Arbitrary data passed by the caller, when starting a transaction.
- Traces
Sampler - A function to be run for each new transaction, to determine the rate at which it should be sampled.