{ "html": "
\n

Installation

\n

Sentry-Rust is distributed as a normal crate from crates.io. You can add\nit to your project as a dependency in your Cargo.toml file:

\n
[dependencies]\nsentry = "0.3"\n
\n
\n

Additionally you can configure a bunch of features to enable or disable\nfunctionality in the crate. By default the most common features are\ncompiled into the crate. For a list of features that are available refer\nto the API Documentation.

\n
\n\n\n
\n

Configuring the Client

\n

The client is configured by calling sentry::init with a value that can\nbe converted into a configuration object. These are the most common\nvalues:

\n\n

This is the most common case for client configuration:

\n
extern crate sentry;\n\nfn main() {\n    sentry::init("___PUBLIC_DSN___");\n    // code using sentry goes here.\n}\n
\n
\n

To configure releases automatically you can use the\nsentry_crate_release! macro in combination with the tuple config\nsyntax:

\n
#[macro_use] extern crate sentry;\n\nfn main() {\n    sentry::init(("___PUBLIC_DSN___", sentry::ClientOptions {\n        release: sentry_crate_release!(),\n        ..Default::default()\n    }));\n    // code using sentry goes here.\n}\n
\n
\n
\n\n\n
\n

Reporting Errors

\n

Once Sentry is configured errors and other events can be emitted. Since\nRust has different mechanisms by which errors can be issued different\nfunctionality is provided for them. By default support for the new\nfailure error system is provided.

\n

For instance to report a failure::Error this code can be used:

\n
use sentry::integrations::failure::capture_error;\n\nlet result = match a_function_that_might_fail() {\n    Ok(val) => val,\n    Err(err) => {\n        capture_error(&err);\n        return Err(err);\n    }\n};\n
\n
\n

For this particular case a shortcut is also provided:

\n
use sentry::integrations::failure::tap_error;\n\nlet result = tap_error(a_function_that_might_fail())?;\n
\n
\n

Similarly the functions capture_fail and tap_fail can be used to\nwork with Fail trait objects instead.

\n
\n\n\n
\n

Catching Panics

\n

To automatically catch panics the panic integration can be used:

\n
use sentry::integrations::panic::register_panic_handler;\n\nfn main() {\n    sentry::init(...);\n    register_panic_handler();\n}\n
\n
\n
\n", "link": "https://docs.getsentry.com/clients/rust/", "id": "rust", "name": "Rust" }