Skip to content

Commit

Permalink
Add telemetry tracking of errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zargony committed Dec 22, 2024
1 parent 4c854db commit 5b2db1d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
14 changes: 11 additions & 3 deletions firmware/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::http::Http;
use crate::mixpanel::{self, Mixpanel};
use crate::{article, json, nfc, user};
use alloc::collections::VecDeque;
use alloc::string::String;
use embassy_time::{Duration, Instant};
use embedded_io_async::Write;
use log::{debug, info, warn};
Expand All @@ -28,6 +29,8 @@ pub enum Event {
UserAuthenticated(user::UserId, nfc::Uid),
/// Article purchased (user id, article id, amount, total price)
ArticlePurchased(user::UserId, article::ArticleId, f32, f32),
/// Error occured (optional user id, error message)
Error(Option<user::UserId>, String),
}

impl Event {
Expand All @@ -39,18 +42,20 @@ impl Event {
Event::AuthenticationFailed(..) => "authentication_failed",
Event::UserAuthenticated(..) => "user_authenticated",
Event::ArticlePurchased(..) => "article_purchased",
Event::Error(..) => "error",
}
}

/// User id associated with this event, if any
pub fn user_id(&self) -> Option<&user::UserId> {
pub fn user_id(&self) -> Option<user::UserId> {
#[allow(clippy::match_same_arms)]
match self {
Event::SystemStart => None,
Event::DataRefreshed(..) => None,
Event::AuthenticationFailed(..) => None,
Event::UserAuthenticated(user_id, ..) => Some(user_id),
Event::ArticlePurchased(user_id, ..) => Some(user_id),
Event::UserAuthenticated(user_id, ..) => Some(*user_id),
Event::ArticlePurchased(user_id, ..) => Some(*user_id),
Event::Error(user_id, ..) => *user_id,
}
}

Expand Down Expand Up @@ -85,6 +90,9 @@ impl Event {
.field("total_price", total_price)
.await?;
}
Event::Error(_user_id, message) => {
object.field("error_message", message).await?;
}
}
Ok(())
}
Expand Down
5 changes: 4 additions & 1 deletion firmware/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::telemetry::{Event, Telemetry};
use crate::user::{UserId, Users};
use crate::vereinsflieger::Vereinsflieger;
use crate::wifi::Wifi;
use alloc::string::String;
use alloc::string::{String, ToString};
use core::convert::Infallible;
use embassy_futures::select::{select, Either};
use embassy_time::{with_timeout, Duration, TimeoutError, Timer};
Expand Down Expand Up @@ -116,6 +116,9 @@ impl<'a, RNG: RngCore, I2C: I2c, IRQ: Wait<Error = Infallible>> Ui<'a, RNG, I2C,
let _ = self.buzzer.error().await;
}

self.telemetry
.track(Event::Error(error.user_id(), error.to_string()));

// Wait at least 1s without responding to keypad
let min_time = Duration::from_secs(1);
Timer::after(min_time).await;
Expand Down

0 comments on commit 5b2db1d

Please sign in to comment.