libobservability-rs 0.1.1

A library for observability
Documentation
use sentry::IntoDsn;
use std::env;

pub fn guard() {
    // Try to get the current git hash.
    let git_hash = env::var("GIT_HASH").unwrap_or_default();
    // Initialize sentry.
    let sentry_dsn = env::var("SENTRY_DSN").unwrap_or_default();
    let _guard = sentry::init(sentry::ClientOptions {
        dsn: sentry_dsn.into_dsn().unwrap(),
        traces_sample_rate: 1.0,
        release: Some(git_hash.into()), // git_hash.into() is not working
        environment: Some(
            env::var("SENTRY_ENV")
                .unwrap_or_else(|_| "development".to_string())
                .into(),
        ),
        default_integrations: true,
        ..sentry::ClientOptions::default()
    });

    if env::var("SENTRY_TEST").is_ok() {
        sentry::capture_message(
            "This is a test event with SENTRY_TEST enabled",
            sentry::Level::Info,
        );
    }
}