Push Notification stats instrumentation (#13118)

This commit is contained in:
Josh Puetz 2021-04-19 09:42:01 -05:00 committed by GitHub
parent 1d1771eb97
commit c3174cade8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 8 deletions

View file

@ -30,11 +30,11 @@ class Device < ApplicationRecord
n.data = {
aps: {
alert: {
title: ApplicationConfig["COMMUNITY_NAME"],
title: SiteConfig.community_name,
subtitle: title,
body: body
},
'thread-id': ApplicationConfig["COMMUNITY_NAME"]
'thread-id': SiteConfig.community_name
},
data: payload
}
@ -61,7 +61,7 @@ class Device < ApplicationRecord
app = Rpush::Apns2::App.new
app.name = app_bundle
sanitized_pem = ApplicationConfig["RPUSH_IOS_PEM"].to_s.gsub("\\n", "\n")
app.certificate = Base64.decode64(sanitized_pem)
app.certificate = sanitized_pem
app.environment = Rails.env.production? ? "production" : "development"
app.password = ""
app.bundle_id = app_bundle

View file

@ -49,7 +49,10 @@ module Notifications
user_ids: targets,
title: "@#{comment.user.username}",
body: "Re: #{comment.parent_or_root_article.title.strip}",
payload: { url: URL.url(url_path) },
payload: {
url: URL.url(url_path),
type: "new comment"
},
)
end

View file

@ -52,8 +52,15 @@ Rpush.reflect do |on|
# end
# Called when a notification is successfully delivered.
# on.notification_delivered do |notification|
# end
on.notification_delivered do |notification|
ForemStatsClient.increment(
"push_notifications.delivered",
tags: [
"app_bundle:#{notification.app&.bundle_id}",
"type:#{JSON.parse(notification.payload).dig('data', 'type') || 'unknown'}",
],
)
end
# Called when notification delivery failed.
# Call 'error_code' and 'error_description' on the notification for the cause.
@ -64,11 +71,15 @@ Rpush.reflect do |on|
Device.where(token: notification.device_token, platform: "iOS").destroy_all
end
HoneyBadger.notify(error_message:
"error_description: #{notification.error_description}, error_code: #{notification.error_code}")
ForemStatsClient.increment(
"push_notifications.errors",
tags: [
"error:#{e.class}",
"message:#{e.error_description}",
"app_bundle:#{notification.app&.bundle_id}",
"error_code:#{notification.error_code}",
"error_description:#{notification.error_description}",
],
)
end