Skip to content

Commit

Permalink
Merge pull request #269 from fablabbcn/chore/log-device-ids-in-sentry…
Browse files Browse the repository at this point in the history
…-breadcrumbs

add device id when logging breadcrumbs for errors in mqtt
  • Loading branch information
oscgonfer authored Oct 26, 2023
2 parents 34da5ee + ff4550c commit 93d547d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/lib/mqtt_messages_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ def self.handle_topic(topic, message)
return if device.nil?

if topic.to_s.include?('raw')
handle_readings(device, parse_raw_readings(message))
handle_readings(device, parse_raw_readings(message, device.id))
elsif topic.to_s.include?('readings')
handle_readings(device, message)
elsif topic.to_s.include?('info')
json_message = JSON.parse(message)
crumb = Sentry::Breadcrumb.new(
category: "MqttMessagesHandler.handle_topic",
message: "Parsing info message",
data: { topic: topic, message: message, json: json_message }
data: {
topic: topic,
message: message,
json: json_message,
device_id: device.id
}
)
Sentry.add_breadcrumb(crumb)
device.update hardware_info: json_message
Expand All @@ -53,11 +58,11 @@ def self.handle_readings(device, message)
end

# takes a raw packet and converts into JSON
def self.parse_raw_readings(message)
def self.parse_raw_readings(message, device_id=nil)
crumb = Sentry::Breadcrumb.new(
category: "MqttMessagesHandler.parse_raw_readings",
message: "Parsing raw readings",
data: { message: message }
data: { message: message, device_id: device_id }
)
Sentry.add_breadcrumb(crumb)
clean_tm = message[1..-2].split(",")[0].gsub("t:", "").strip
Expand All @@ -74,7 +79,7 @@ def self.parse_raw_readings(message)
crumb = Sentry::Breadcrumb.new(
category: "MqttMessagesHandler.parse_raw_readings",
message: "Readings data constructed",
data: { message: message, reading: reading }
data: { message: message, reading: reading, device_id: device_id }
)
Sentry.add_breadcrumb(crumb)

Expand Down

0 comments on commit 93d547d

Please sign in to comment.