[][src]Function sentry::init

pub fn init<C: Into<Client>>(cfg: C) -> ClientInitGuard

Creates the Sentry client for a given client config and binds it.

This returns a client init guard that must kept in scope 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 set on it.

If you don't want (or can) keep the guard around it's permissible to call mem::forget on it.

Examples

fn main() {
    let _sentry = sentry::init("https://key@sentry.io/1234");
}

Of if draining on shutdown should be ignored:

use std::mem;

fn main() {
    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:

use sentry::integrations::panic::register_panic_handler;

fn main() {
    let sentry = sentry::init(sentry::ClientOptions {
        release: Some("foo-bar-baz@1.0.0".into()),
        ..Default::default()
    });
    if sentry.is_enabled() {
        register_panic_handler();
    }
}

This behaves similar to creating a client by calling Client::from_config and to then bind it to the hub except it's also possible to directly pass a client. For more information about the formats accepted see Client::from_config.