wire-framework 0.1.0

A DI library for Rust
Documentation
use std::borrow::Cow;

use sentry::{ClientInitGuard, types::Dsn};
pub use sentry::{Level as AlertLevel, capture_message};

#[derive(Debug)]
pub struct Sentry {
    url: Dsn,
    environment: Option<String>,
}

impl Sentry {
    pub fn new(url: &str) -> Result<Self, sentry::types::ParseDsnError> {
        Ok(Self {
            url: url.parse()?,
            environment: None,
        })
    }

    pub fn with_environment(mut self, environment: Option<String>) -> Self {
        self.environment = environment;
        self
    }

    pub fn install(self) -> ClientInitGuard {
        // Initialize the Sentry.
        let options = sentry::ClientOptions {
            release: sentry::release_name!(),
            environment: self.environment.map(Cow::from),
            attach_stacktrace: true,
            ..Default::default()
        };

        sentry::init((self.url, options))
    }
}