chore: Upgrade Exception tracking (#4638)

- Upgrade Sentry Libraries
- Enable provision for account and user info in error tracking
- Add ChatwootExceptionTracker

fixes: #4375
This commit is contained in:
Sojan Jose
2022-05-09 14:23:19 +05:30
committed by GitHub
parent 360b438a55
commit 04dfb034cc
25 changed files with 173 additions and 108 deletions

View File

@@ -29,7 +29,7 @@ class Messages::Facebook::MessageBuilder < Messages::Messenger::MessageBuilder
rescue Koala::Facebook::AuthenticationError
Rails.logger.error "Facebook Authorization expired for Inbox #{@inbox.id}"
rescue StandardError => e
Sentry.capture_exception(e)
ChatwootExceptionTracker.new(e, account: @inbox.account).capture_exception
true
end
@@ -128,10 +128,10 @@ class Messages::Facebook::MessageBuilder < Messages::Messenger::MessageBuilder
result = {}
# OAuthException, code: 100, error_subcode: 2018218, message: (#100) No profile available for this user
# We don't need to capture this error as we don't care about contact params in case of echo messages
Sentry.capture_exception(e) unless @outgoing_echo
ChatwootExceptionTracker.new(e, account: @inbox.account).capture_exception unless @outgoing_echo
rescue StandardError => e
result = {}
Sentry.capture_exception(e)
ChatwootExceptionTracker.new(e, account: @inbox.account).capture_exception
end
process_contact_params_result(result)
end

View File

@@ -24,7 +24,7 @@ class Messages::Instagram::MessageBuilder < Messages::Messenger::MessageBuilder
@inbox.channel.authorization_error!
raise
rescue StandardError => e
Sentry.capture_exception(e)
ChatwootExceptionTracker.new(e, account: @inbox.account).capture_exception
true
end

View File

@@ -53,16 +53,7 @@ class Messages::Messenger::MessageBuilder
def fetch_story_link(attachment)
message = attachment.message
begin
k = Koala::Facebook::API.new(@inbox.channel.page_access_token) if @inbox.facebook?
result = k.get_object(message.source_id, fields: %w[story from]) || {}
rescue Koala::Facebook::AuthenticationError
@inbox.channel.authorization_error!
raise
rescue StandardError => e
result = {}
Sentry.capture_exception(e)
end
result = get_story_object_from_source_id(message.source_id)
story_id = result['story']['mention']['id']
story_sender = result['from']['username']
message.content_attributes[:story_sender] = story_sender
@@ -70,4 +61,15 @@ class Messages::Messenger::MessageBuilder
message.content = I18n.t('conversations.messages.instagram_story_content', story_sender: story_sender)
message.save!
end
def get_story_object_from_source_id(source_id)
k = Koala::Facebook::API.new(@inbox.channel.page_access_token) if @inbox.facebook?
k.get_object(source_id, fields: %w[story from]) || {}
rescue Koala::Facebook::AuthenticationError
@inbox.channel.authorization_error!
raise
rescue StandardError => e
ChatwootExceptionTracker.new(e, account: @inbox.account).capture_exception
{}
end
end

View File

@@ -15,7 +15,7 @@ class Api::V1::Accounts::CallbacksController < Api::V1::Accounts::BaseController
set_instagram_id(page_access_token, facebook_channel)
set_avatar(@facebook_inbox, page_id)
rescue StandardError => e
Sentry.capture_exception(e)
ChatwootExceptionTracker.new(e).capture_exception
end
end
@@ -60,7 +60,7 @@ class Api::V1::Accounts::CallbacksController < Api::V1::Accounts::BaseController
set_instagram_id(access_token, fb_page)
fb_page&.reauthorized!
rescue StandardError => e
Sentry.capture_exception(e)
ChatwootExceptionTracker.new(e).capture_exception
end
end

View File

@@ -10,7 +10,7 @@ class Api::V1::WebhooksController < ApplicationController
twitter_consumer.consume
head :ok
rescue StandardError => e
Sentry.capture_exception(e)
ChatwootExceptionTracker.new(e).capture_exception
head :ok
end

View File

@@ -9,8 +9,7 @@ module RequestExceptionHandler
def handle_with_exception
yield
rescue ActiveRecord::RecordNotFound => e
Sentry.capture_exception(e)
rescue ActiveRecord::RecordNotFound
render_not_found_error('Resource could not be found')
rescue Pundit::NotAuthorizedError
render_unauthorized('You are not authorized to do this action')

View File

@@ -11,7 +11,7 @@ class Inboxes::FetchImapEmailsJob < ApplicationJob
channel.authorization_error!
rescue StandardError => e
channel.authorization_error!
Sentry.capture_exception(e)
ChatwootExceptionTracker.new(e, account: channel.account).capture_exception
end
private

View File

@@ -12,7 +12,7 @@ class AutomationRules::ActionService
begin
send(action[:action_name], action[:action_params])
rescue StandardError => e
Sentry.capture_exception(e)
ChatwootExceptionTracker.new(e, account: @account).capture_exception
end
end
ensure

View File

@@ -9,7 +9,7 @@ class Facebook::SendOnFacebookService < Base::SendOnChannelService
send_message_to_facebook fb_text_message_params if message.content.present?
send_message_to_facebook fb_attachment_message_params if message.attachments.present?
rescue Facebook::Messenger::FacebookError => e
Sentry.capture_exception(e)
ChatwootExceptionTracker.new(e, account: message.account, user: message.sender).capture_exception
# TODO : handle specific errors or else page will get disconnected
# channel.authorization_error!
end

View File

@@ -38,7 +38,7 @@ class Instagram::MessageText < Instagram::WebhooksBaseService
raise
rescue StandardError => e
result = {}
Sentry.capture_exception(e)
ChatwootExceptionTracker.new(e, account: @inbox.account).capture_exception
end
find_or_create_contact(result)

View File

@@ -17,7 +17,7 @@ class Instagram::SendOnInstagramService < Base::SendOnChannelService
send_to_facebook_page attachament_message_params if message.attachments.present?
send_to_facebook_page message_params
rescue StandardError => e
Sentry.capture_exception(e)
ChatwootExceptionTracker.new(e, account: message.account, user: message.sender).capture_exception
# TODO : handle specific errors or else page will get disconnected
# channel.authorization_error!
end

View File

@@ -7,7 +7,7 @@ class MessageTemplates::Template::EmailCollect
conversation.messages.create!(email_input_box_template_message_params)
end
rescue StandardError => e
Sentry.capture_exception(e)
ChatwootExceptionTracker.new(e, account: conversation.account).capture_exception
true
end

View File

@@ -6,7 +6,7 @@ class MessageTemplates::Template::Greeting
conversation.messages.create!(greeting_message_params)
end
rescue StandardError => e
Sentry.capture_exception(e)
ChatwootExceptionTracker.new(e, account: conversation.account).capture_exception
true
end

View File

@@ -6,7 +6,7 @@ class MessageTemplates::Template::OutOfOffice
conversation.messages.create!(out_of_office_message_params)
end
rescue StandardError => e
Sentry.capture_exception(e)
ChatwootExceptionTracker.new(e, account: conversation.account).capture_exception
true
end

View File

@@ -9,7 +9,7 @@ class Twilio::SendOnTwilioService < Base::SendOnChannelService
begin
twilio_message = client.messages.create(**message_params)
rescue Twilio::REST::TwilioError => e
Sentry.capture_exception(e)
ChatwootExceptionTracker.new(e, user: message.sender, account: message.account).capture_exception
end
message.update!(source_id: twilio_message.sid) if twilio_message
end