pub fn init<C>(opts: C) -> ClientInitGuardwhere
C: Into<ClientOptions>,
Expand description
Creates the Sentry client for a given client config and binds it.
This returns a client init guard that must be kept in scope and that will help the client send events before the application closes. When the guard is dropped, then the transport that was initialized shuts down and no further events can be sent on it.
If you don’t want (or can not) keep the guard around, it’s permissible to
call mem::forget
on it.
§Examples
let _sentry = sentry::init("https://key@sentry.io/1234");
Or if draining on shutdown should be ignored: This is not recommended, as events or session updates that have been queued might be lost.
std::mem::forget(sentry::init("https://key@sentry.io/1234"));
The guard returned can also be inspected to see if a client has been created to enable further configuration:
let sentry = sentry::init(sentry::ClientOptions {
release: Some("foo-bar-baz@1.0.0".into()),
..Default::default()
});
if sentry.is_enabled() {
// some other initialization
}
This behaves similar to creating a client by calling Client::from_config
and to then bind it to the hub except it also applies default integrations,
a default transport, as well as other options populated from environment
variables.
For more information about the formats accepted see Client::from_config
,
and ClientOptions
.
§Panics
This will panic when the provided DSN is invalid.
If you want to handle invalid DSNs you need to parse them manually by
calling parse
on each of them and handle the error.