Skip to content

Commit

Permalink
Merge pull request #1079 from spkenv/sentry-config
Browse files Browse the repository at this point in the history
Remove imageworks-specific sentry configuration
  • Loading branch information
jrray authored Jul 19, 2024
2 parents 0615c98 + 2ca1fe0 commit 3bf7e23
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 26 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 16 additions & 10 deletions crates/spfs-cli/common/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ pub fn configure_sentry(

use sentry::IntoDsn;

let Ok(config) = spfs::get_config() else {
return None;
};

// SENTRY_USERNAME_OVERRIDE_VAR should hold the name of another
// environment variable that can hold a username. If it does and
// the other environment variable exists, its value will be used
Expand All @@ -199,14 +203,13 @@ pub fn configure_sentry(

let sentry_init_result = catch_unwind(|| {
let mut opts = sentry::ClientOptions {
dsn: "http://3dd72e3b4b9a4032947304fabf29966e@sentry.spimageworks.com/4"
.into_dsn()
.unwrap_or(None),
environment: Some(
std::env::var("SENTRY_ENVIRONMENT")
.unwrap_or_else(|_| "production".to_string())
.into(),
),
dsn: config.sentry.dsn.as_str().into_dsn().unwrap_or_default(),
environment: config
.sentry
.environment
.as_ref()
.map(ToOwned::to_owned)
.map(std::borrow::Cow::Owned),
// spdev follows sentry recommendation of using the release
// tag as the name of the release in sentry
release: Some(format!("v{}", spfs::VERSION).into()),
Expand Down Expand Up @@ -251,8 +254,11 @@ pub fn configure_sentry(

sentry::configure_scope(|scope| {
scope.set_user(Some(sentry::protocol::User {
// TODO: make this configurable in future
email: Some(format!("{}@imageworks.com", &username)),
email: config
.sentry
.email_domain
.as_ref()
.map(|domain| format!("{username}@{domain}")),
username: Some(username),
..Default::default()
}));
Expand Down
21 changes: 21 additions & 0 deletions crates/spfs/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,26 @@ impl Default for Monitor {
}
}

#[derive(Clone, Default, Debug, Deserialize, Serialize)]
#[serde(default)]
pub struct Sentry {
/// Sentry DSN
pub dsn: String,

/// Sentry environment
pub environment: Option<String>,

/// Environment variable name to use as sentry username, if set.
///
/// This is useful in CI if the CI system has a variable that contains
/// the username of the person who triggered the build.
pub username_override_var: Option<String>,

/// Set the email address domain used to generate email addresses for
/// sentry events.
pub email_domain: Option<String>,
}

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(default)]
pub struct Config {
Expand All @@ -412,6 +432,7 @@ pub struct Config {
pub remote: std::collections::HashMap<String, Remote>,
pub fuse: Fuse,
pub monitor: Monitor,
pub sentry: Sentry,
}

impl Config {
Expand Down
1 change: 1 addition & 0 deletions crates/spfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,5 @@ pub use self::config::{
Config,
RemoteAddress,
RemoteConfig,
Sentry,
};
5 changes: 5 additions & 0 deletions crates/spk-cli/common/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ pub fn configure_sentry() -> Option<sentry::ClientInitGuard> {

sentry::configure_scope(|scope| {
scope.set_user(Some(sentry::User {
email: config
.sentry
.email_domain
.as_ref()
.map(|domain| format!("{username}@{domain}")),
username: Some(username),
..Default::default()
}));
Expand Down
1 change: 1 addition & 0 deletions crates/spk-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ config = { workspace = true }
dirs = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
spfs = { workspace = true }
once_cell = { workspace = true }
thiserror = { workspace = true }
miette = { workspace = true }
Expand Down
17 changes: 1 addition & 16 deletions crates/spk-config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::sync::{Arc, RwLock};
use config::Environment;
use once_cell::sync::OnceCell;
use serde::{Deserialize, Serialize};
use spfs::Sentry;

use crate::Result;

Expand All @@ -16,22 +17,6 @@ mod config_test;

static CONFIG: OnceCell<RwLock<Arc<Config>>> = OnceCell::new();

#[derive(Clone, Default, Debug, Deserialize, Serialize)]
#[serde(default)]
pub struct Sentry {
/// Sentry DSN
pub dsn: String,

/// Sentry environment
pub environment: Option<String>,

/// Environment variable name to use as sentry username, if set.
///
/// This is useful in CI if the CI system has a variable that contains
/// the username of the person who triggered the build.
pub username_override_var: Option<String>,
}

#[derive(Clone, Default, Debug, Deserialize, Serialize)]
#[serde(default)]
pub struct Metadata {
Expand Down

0 comments on commit 3bf7e23

Please sign in to comment.