{ "html": "
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
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.
\nThe client is configured by calling sentry::init
with a value that can\nbe converted into a configuration object. These are the most common\nvalues:
SENTRY_DSN
environment variable.This is the most common case for client configuration:
\nextern crate sentry;\n\nfn main() {\n sentry::init("___PUBLIC_DSN___");\n // code using sentry goes here.\n}\n
To configure releases automatically you can use the\nsentry_crate_release!
macro in combination with the tuple config\nsyntax:
#[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
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.
\nFor instance to report a failure::Error
this code can be used:
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
For this particular case a shortcut is also provided:
\nuse sentry::integrations::failure::tap_error;\n\nlet result = tap_error(a_function_that_might_fail())?;\n
Similarly the functions capture_fail
and tap_fail
can be used to\nwork with Fail trait objects instead.
To automatically catch panics the panic integration can be used:
\nuse sentry::integrations::panic::register_panic_handler;\n\nfn main() {\n sentry::init(...);\n register_panic_handler();\n}\n