stratus/infra/sentry/
sentry_config.rs1use clap::Parser;
2use display_json::DebugAsJson;
3use sentry::ClientInitGuard;
4
5use crate::config::Environment;
6use crate::ext::not;
7use crate::infra::build_info;
8
9#[derive(DebugAsJson, Clone, Parser, serde::Serialize)]
10pub struct SentryConfig {
11 #[arg(long = "sentry-url", env = "SENTRY_URL", required = false)]
13 pub sentry_url: String,
14}
15
16impl SentryConfig {
17 pub fn init(&self, env: Environment) -> anyhow::Result<ClientInitGuard> {
19 let release = build_info::service_name_with_version();
20 tracing::info!(url = %self.sentry_url, %env, %release, "creating sentry exporter");
21
22 let guard = sentry::init((
23 self.sentry_url.clone(),
24 sentry::ClientOptions {
25 max_breadcrumbs: 0,
26 release: Some(release.clone().into()),
27 environment: Some(env.to_string().into()),
28 ..Default::default()
29 },
30 ));
31 if not(guard.is_enabled()) {
32 tracing::error!(url = %self.sentry_url, %env, %release, "failed to create sentry exporter");
33 }
34
35 Ok(guard)
36 }
37}