diff --git a/autoconnect/autoconnect-ws/autoconnect-ws-sm/src/identified/mod.rs b/autoconnect/autoconnect-ws/autoconnect-ws-sm/src/identified/mod.rs index d7b0c76f0..7be27c58e 100644 --- a/autoconnect/autoconnect-ws/autoconnect-ws-sm/src/identified/mod.rs +++ b/autoconnect/autoconnect-ws/autoconnect-ws-sm/src/identified/mod.rs @@ -255,12 +255,12 @@ impl WebPushClient { } /// Add User information and tags for this Client to a Sentry Event - pub fn add_sentry_info(&self, event: &mut sentry::protocol::Event) { + pub fn add_sentry_info(self, event: &mut sentry::protocol::Event) { event.user = Some(sentry::User { id: Some(self.uaid.as_simple().to_string()), ..Default::default() }); - let ua_info = self.ua_info.clone(); + let ua_info = self.ua_info; event .tags .insert("ua_name".to_owned(), ua_info.browser_name); diff --git a/autoconnect/autoconnect-ws/src/error.rs b/autoconnect/autoconnect-ws/src/error.rs index 542b78dbc..2d8b6960c 100644 --- a/autoconnect/autoconnect-ws/src/error.rs +++ b/autoconnect/autoconnect-ws/src/error.rs @@ -3,8 +3,8 @@ use std::fmt; use actix_ws::CloseCode; use backtrace::Backtrace; -use autoconnect_ws_sm::SMError; -use autopush_common::errors::ReportableError; +use autoconnect_ws_sm::{SMError, WebPushClient}; +use autopush_common::{errors::ReportableError, sentry::event_from_error}; /// WebPush WebSocket Handler Errors #[derive(Debug, thiserror::Error)] @@ -51,6 +51,18 @@ impl WSError { pub fn close_description(&self) -> &str { self.kind.as_ref() } + + /// Emit an event for this Error to Sentry if set to + pub fn capture_sentry_event(&self, client: Option) { + if !self.is_sentry_event() { + return; + } + let mut event = event_from_error(self); + if let Some(client) = client { + client.add_sentry_info(&mut event); + } + sentry::capture_event(event); + } } impl ReportableError for WSError { diff --git a/autoconnect/autoconnect-ws/src/handler.rs b/autoconnect/autoconnect-ws/src/handler.rs index fd8a2f24e..3b701b8b1 100644 --- a/autoconnect/autoconnect-ws/src/handler.rs +++ b/autoconnect/autoconnect-ws/src/handler.rs @@ -7,7 +7,6 @@ use tokio::{select, time::timeout}; use autoconnect_common::protocol::{ServerMessage, ServerNotification}; use autoconnect_settings::AppState; use autoconnect_ws_sm::{UnidentifiedClient, WebPushClient}; -use autopush_common::{errors::ReportableError, sentry::event_from_error}; use crate::{ error::{WSError, WSErrorKind}, @@ -61,7 +60,13 @@ pub(crate) async fn webpush_ws( // NOTE: UnidentifiedClient doesn't require shutdown/cleanup, so its // Error's propagated. We don't propagate Errors afterwards to handle // shutdown/cleanup of WebPushClient - let (mut client, smsgs) = unidentified_ws(client, &mut msg_stream).await?; + let (mut client, smsgs) = match unidentified_ws(client, &mut msg_stream).await { + Ok(t) => t, + Err(e) => { + e.capture_sentry_event(None); + return Err(e); + } + }; // Client now identified: add them to the registry to recieve ServerNotifications let mut snotif_stream = client.registry_connect().await; @@ -75,11 +80,7 @@ pub(crate) async fn webpush_ws( client.shutdown(result.as_ref().err().map(|e| e.to_string())); if let Err(ref e) = result { - if e.is_sentry_event() { - let mut event = event_from_error(e); - client.add_sentry_info(&mut event); - sentry::capture_event(event); - } + e.capture_sentry_event(Some(client)); } result }