use errsight::{Breadcrumb, Config, Level, User};
fn main() {
let _guard = errsight::init(
Config::builder()
.environment("development")
.release(env!("CARGO_PKG_VERSION"))
.min_level(Level::Info)
.debug(true) .build(),
);
errsight::configure_scope(|scope| {
scope.set_tag("example", "basic");
scope.set_user(User::new().id("demo-user").email("demo@example.com"));
});
errsight::add_breadcrumb(Breadcrumb::new("lifecycle", "application started"));
errsight::capture_message("hello from errsight-rust", Level::Info);
if let Err(err) = do_risky_thing() {
errsight::capture_error(&err);
eprintln!("captured error: {err}");
}
errsight::with_scope(|| {
errsight::configure_scope(|s| {
s.set_tag("phase", "checkout");
});
errsight::capture_message("checkout failed", Level::Error);
});
errsight::flush(None);
}
#[derive(Debug)]
struct DiskError(String);
impl std::fmt::Display for DiskError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "disk error: {}", self.0)
}
}
impl std::error::Error for DiskError {}
fn do_risky_thing() -> Result<(), DiskError> {
Err(DiskError("device is on fire".to_string()))
}