Skip to main content

wire_framework/vlog/
sentry.rs

1use std::borrow::Cow;
2
3use sentry::{ClientInitGuard, types::Dsn};
4pub use sentry::{Level as AlertLevel, capture_message};
5
6#[derive(Debug)]
7pub struct Sentry {
8    url: Dsn,
9    environment: Option<String>,
10}
11
12impl Sentry {
13    pub fn new(url: &str) -> Result<Self, sentry::types::ParseDsnError> {
14        Ok(Self {
15            url: url.parse()?,
16            environment: None,
17        })
18    }
19
20    pub fn with_environment(mut self, environment: Option<String>) -> Self {
21        self.environment = environment;
22        self
23    }
24
25    pub fn install(self) -> ClientInitGuard {
26        // Initialize the Sentry.
27        let options = sentry::ClientOptions {
28            release: sentry::release_name!(),
29            environment: self.environment.map(Cow::from),
30            attach_stacktrace: true,
31            ..Default::default()
32        };
33
34        sentry::init((self.url, options))
35    }
36}