Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(crash-reporting): reuse embed's shared sentry client options

Steven Enamakel5ec3d5536d53
diff --git a/crates/openhuman-tui/src/crash_reporting.rs b/crates/openhuman-tui/src/crash_reporting.rs
index 96b3ff5dc9..3064f947ff 100644
--- a/crates/openhuman-tui/src/crash_reporting.rs
+++ b/crates/openhuman-tui/src/crash_reporting.rs
@@ -1,77 +1,55 @@
//! Crash-reporting client ownership for the standalone terminal binary.
+//!
+//! The client options come from embed's shared chain
+//! (`openhuman_rpc::embed::process::sentry`): the same noise filters, secret
+//! scrubbing, PII-off defaults and transport as the CLI and the desktop shell.
+//! Only the DSN, release and environment are resolved here.
+
+#[cfg(feature = "crash-reporting")]
+use openhuman_rpc::embed::process::{self, sentry};
/// Initialize the Sentry client before the TUI installs its tracing subscriber.
///
/// The returned guard must live for the whole process. A build without the
/// `crash-reporting` feature retains the same call site and compiles to a no-op.
#[cfg(feature = "crash-reporting")]
-pub fn init_crash_reporting() -> sentry::ClientInitGuard {
+pub fn init_crash_reporting() -> sentry::sdk::ClientInitGuard {
// Match the core binary: startup consumers must see a repository-local
// `.env`, while explicit process variables continue to take precedence.
- let _ = dotenvy::dotenv();
+ // Failure is not fatal here; `run_from_cli` loads it again and reports it.
+ let _ = process::load_dotenv_for_cli();
- sentry::init(sentry::ClientOptions {
- dsn: sentry_dsn(),
- release: Some(std::borrow::Cow::Owned(build_release_tag())),
- environment: Some(std::borrow::Cow::Owned(resolve_environment())),
- send_default_pii: false,
- before_send: Some(std::sync::Arc::new(|mut event| {
- event.server_name = None;
- for exception in &mut event.exception.values {
- if let Some(value) = exception.value.take() {
- exception.value =
- Some(openhuman_core::core::log_redaction::scrub_secrets(&value));
- }
- }
- if let Some(message) = event.message.take() {
- event.message = Some(openhuman_core::core::log_redaction::scrub_secrets(&message));
- }
- Some(event)
- })),
- sample_rate: 1.0,
- transport: Some(std::sync::Arc::new(
- openhuman_core::core::sentry_transport::factory,
- )),
- ..sentry::ClientOptions::default()
- })
+ let config = sentry::SentryConfig::new(
+ sentry_dsn(),
+ build_release_tag(),
+ resolve_environment(std::env::var("OPENHUMAN_APP_ENV").ok()),
+ );
+ sentry::sdk::init(sentry::client_options(config))
}
#[cfg(not(feature = "crash-reporting"))]
pub fn init_crash_reporting() {}
+/// `OPENHUMAN_CORE_SENTRY_DSN`, then the legacy `OPENHUMAN_SENTRY_DSN`, at
+/// runtime and then baked in at compile time.
#[cfg(feature = "crash-reporting")]
-fn sentry_dsn() -> Option<sentry::types::Dsn> {
- std::env::var("OPENHUMAN_CORE_SENTRY_DSN")
- .ok()
- .filter(|value| !value.is_empty())
- .or_else(|| std::env::var("OPENHUMAN_SENTRY_DSN").ok())
- .filter(|value| !value.is_empty())
- .or_else(|| option_env!("OPENHUMAN_CORE_SENTRY_DSN").map(str::to_owned))
- .filter(|value| !value.is_empty())
- .or_else(|| option_env!("OPENHUMAN_SENTRY_DSN").map(str::to_owned))
- .filter(|value| !value.is_empty())
- .and_then(|value| value.parse().ok())
+fn sentry_dsn() -> Option<String> {
+ sentry::first_non_blank([
+ std::env::var("OPENHUMAN_CORE_SENTRY_DSN").ok(),
+ std::env::var("OPENHUMAN_SENTRY_DSN").ok(),
+ option_env!("OPENHUMAN_CORE_SENTRY_DSN").map(str::to_owned),
+ option_env!("OPENHUMAN_SENTRY_DSN").map(str::to_owned),
+ ])
}
#[cfg(feature = "crash-reporting")]
fn build_release_tag() -> String {
- let version = env!("CARGO_PKG_VERSION");
- let short_sha: String = option_env!("OPENHUMAN_BUILD_SHA")
- .unwrap_or("")
- .trim()
- .chars()
- .take(12)
- .collect();
- if short_sha.is_empty() {
- format!("openhuman@{version}")
- } else {
- format!("openhuman@{version}+{short_sha}")
- }
+ sentry::release_tag(env!("CARGO_PKG_VERSION"), option_env!("OPENHUMAN_BUILD_SHA"))
}
#[cfg(feature = "crash-reporting")]
-fn resolve_environment() -> String {
- if let Ok(value) = std::env::var("OPENHUMAN_APP_ENV") {
+fn resolve_environment(app_env: Option<String>) -> String {
+ if let Some(value) = app_env {
let value = value.trim().to_ascii_lowercase();
if !value.is_empty() {
return value;
diff --git a/crates/openhuman-tui/src/crash_reporting_tests.rs b/crates/openhuman-tui/src/crash_reporting_tests.rs
index 9914d6c528..5677642e63 100644
--- a/crates/openhuman-tui/src/crash_reporting_tests.rs
+++ b/crates/openhuman-tui/src/crash_reporting_tests.rs
@@ -13,3 +13,14 @@ fn release_tag_uses_the_package_version_without_a_build_sha() {
);
}
}
+
+#[test]
+fn environment_prefers_app_env_lowercased() {
+ assert_eq!(resolve_environment(Some(" Staging ".into())), "staging");
+ let fallback = if cfg!(debug_assertions) {
+ "development"
+ } else {
+ "production"
+ };
+ assert_eq!(resolve_environment(Some(" ".into())), fallback);
+}