diff --git a/rust/connlib/clients/shared/src/callbacks.rs b/rust/connlib/clients/shared/src/callbacks.rs index ac9bb16a0..93aebe56c 100644 --- a/rust/connlib/clients/shared/src/callbacks.rs +++ b/rust/connlib/clients/shared/src/callbacks.rs @@ -48,3 +48,13 @@ pub enum DisconnectError { #[error("connection to the portal failed: {0}")] PortalConnectionFailed(#[from] phoenix_channel::Error), } + +impl DisconnectError { + pub fn is_authentication_error(&self) -> bool { + let Self::PortalConnectionFailed(e) = self else { + return false; + }; + + e.is_authentication_error() + } +} diff --git a/rust/connlib/clients/shared/src/lib.rs b/rust/connlib/clients/shared/src/lib.rs index 0630f05f5..202b7c178 100644 --- a/rust/connlib/clients/shared/src/lib.rs +++ b/rust/connlib/clients/shared/src/lib.rs @@ -150,7 +150,15 @@ async fn connect_supervisor( tracing::info!("connlib exited gracefully"); } Ok(Err(e)) => { - telemetry::capture_error(&e); + if e.is_authentication_error() { + telemetry::capture_message( + "Portal authentication error", + telemetry::Level::Warning, + ); + } else { + telemetry::capture_error(&e); + } + tracing::error!("connlib failed: {e}"); callbacks.on_disconnect(&e); } diff --git a/rust/headless-client/src/lib.rs b/rust/headless-client/src/lib.rs index 7fbeb3702..69c61a0b4 100644 --- a/rust/headless-client/src/lib.rs +++ b/rust/headless-client/src/lib.rs @@ -9,7 +9,7 @@ //! Otherwise we would just make it a normal binary crate. use anyhow::{Context as _, Result}; -use connlib_client_shared::{Callbacks, DisconnectError}; +use connlib_client_shared::Callbacks; use connlib_model::ResourceView; use firezone_bin_shared::platform::DnsControlMethod; use std::{ @@ -97,16 +97,10 @@ pub struct CallbackHandler { impl Callbacks for CallbackHandler { fn on_disconnect(&self, error: &connlib_client_shared::DisconnectError) { tracing::error!(?error, "Got `on_disconnect` from connlib"); - let is_authentication_error = if let DisconnectError::PortalConnectionFailed(error) = error - { - error.is_authentication_error() - } else { - false - }; self.cb_tx .try_send(ConnlibMsg::OnDisconnect { error_msg: error.to_string(), - is_authentication_error, + is_authentication_error: error.is_authentication_error(), }) .expect("should be able to send OnDisconnect"); } diff --git a/rust/telemetry/src/lib.rs b/rust/telemetry/src/lib.rs index ac3f1d759..c3c8e6d3d 100644 --- a/rust/telemetry/src/lib.rs +++ b/rust/telemetry/src/lib.rs @@ -2,8 +2,9 @@ use arc_swap::ArcSwapOption; use std::time::Duration; pub use sentry::{ - add_breadcrumb, capture_error, configure_scope, end_session, end_session_with_status, - start_transaction, types::protocol::v7::SessionStatus, Breadcrumb, Hub, TransactionContext, + add_breadcrumb, capture_error, capture_message, configure_scope, end_session, + end_session_with_status, start_transaction, types::protocol::v7::SessionStatus, Breadcrumb, + Hub, Level, TransactionContext, }; pub struct Dsn(&'static str);