Skip to content

Commit

Permalink
feat: include error in trace (#212)
Browse files Browse the repository at this point in the history
* feat: error trace

* fix: change order of trace
  • Loading branch information
de-sh authored Apr 29, 2023
1 parent 57750b3 commit c9b83f1
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions uplink/src/base/mqtt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use std::path::Path;

use crate::{Action, Config};
use rumqttc::{
AsyncClient, Event, EventLoop, Incoming, Key, MqttOptions, Publish, QoS, TlsConfiguration,
Transport,
AsyncClient, ConnectionError, Event, EventLoop, Incoming, Key, MqttOptions, Publish, QoS,
TlsConfiguration, Transport,
};
use std::sync::Arc;

Expand Down Expand Up @@ -137,8 +137,7 @@ impl Mqtt {
}
Err(e) => {
self.metrics.add_reconnection();
self.check_disconnection_metrics();
debug!("Connection error = {:?}", e.to_string());
self.check_disconnection_metrics(e);
tokio::time::sleep(Duration::from_secs(3)).await;
continue;
}
Expand Down Expand Up @@ -173,11 +172,10 @@ impl Mqtt {
}

// Enable actual metrics timers when there is data. This method is called every minute by the bridge
pub fn check_disconnection_metrics(&mut self) {
pub fn check_disconnection_metrics(&mut self, error: ConnectionError) {
let metrics = self.metrics.clone();
error!(
"{:>35}: reconnects = {:<3} publishes = {:<3} pubacks = {:<3} pingreqs = {:<3} pingresps = {:<3}",
"disconnected",
"disconnected: reconnects = {:<3} publishes = {:<3} pubacks = {:<3} pingreqs = {:<3} pingresps = {:<3} error = \"{error:>20}\"",
metrics.connection_retries,
metrics.publishes,
metrics.pubacks,
Expand Down

0 comments on commit c9b83f1

Please sign in to comment.