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:
32
lib/chatwoot_exception_tracker.rb
Normal file
32
lib/chatwoot_exception_tracker.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
###############
|
||||
# One library to capture_exception and send to the specific service.
|
||||
# # e as exception, u for user and a for account (user and account are optional)
|
||||
# Usage: ChatwootExceptionTracker(e, user: u, account: a).capture_exception
|
||||
############
|
||||
|
||||
class ChatwootExceptionTracker
|
||||
def initialize(exception, user: nil, account: nil)
|
||||
@exception = exception
|
||||
@user = user
|
||||
@account = account
|
||||
end
|
||||
|
||||
def capture_exception
|
||||
capture_exception_with_sentry if ENV['SENTRY_DSN'].present?
|
||||
# Implement other providers like honeybadger, rollbar etc in future
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def capture_exception_with_sentry
|
||||
Sentry.with_scope do |scope|
|
||||
if @account.present?
|
||||
scope.set_context('account', { id: @account.id, name: @account.name })
|
||||
scope.set_tags(account_id: @account.id)
|
||||
end
|
||||
|
||||
scope.set_user(id: @user.id, email: @user.email) if @user.is_a?(User)
|
||||
Sentry.capture_exception(@exception)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -42,7 +42,7 @@ class ChatwootHub
|
||||
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS => e
|
||||
Rails.logger.error "Exception: #{e.message}"
|
||||
rescue StandardError => e
|
||||
Sentry.capture_exception(e)
|
||||
ChatwootExceptionTracker.new(e).capture_exception
|
||||
end
|
||||
version
|
||||
end
|
||||
@@ -53,7 +53,7 @@ class ChatwootHub
|
||||
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS => e
|
||||
Rails.logger.error "Exception: #{e.message}"
|
||||
rescue StandardError => e
|
||||
Sentry.capture_exception(e)
|
||||
ChatwootExceptionTracker.new(e).capture_exception
|
||||
end
|
||||
|
||||
def self.send_browser_push(fcm_token_list, fcm_options)
|
||||
@@ -62,7 +62,7 @@ class ChatwootHub
|
||||
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS => e
|
||||
Rails.logger.error "Exception: #{e.message}"
|
||||
rescue StandardError => e
|
||||
Sentry.capture_exception(e)
|
||||
ChatwootExceptionTracker.new(e).capture_exception
|
||||
end
|
||||
|
||||
def self.emit_event(event_name, event_data)
|
||||
@@ -73,6 +73,6 @@ class ChatwootHub
|
||||
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS => e
|
||||
Rails.logger.error "Exception: #{e.message}"
|
||||
rescue StandardError => e
|
||||
Sentry.capture_exception(e)
|
||||
ChatwootExceptionTracker.new(e).capture_exception
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,7 +15,7 @@ class Integrations::Facebook::MessageCreator
|
||||
create_contact_message
|
||||
end
|
||||
# rescue => e
|
||||
# Sentry.capture_exception(e)
|
||||
# ChatwootExceptionTracker.new(e).capture_exception
|
||||
# end
|
||||
end
|
||||
|
||||
|
||||
@@ -11,6 +11,6 @@ class Webhooks::Trigger
|
||||
Rails.logger.error "Exception: invalid webhook url #{url} : #{e.message}"
|
||||
rescue StandardError => e
|
||||
Rails.logger.error "Exception: invalid webhook url #{url} : #{e.message}"
|
||||
Sentry.capture_exception(e)
|
||||
ChatwootExceptionTracker.new(e).capture_exception
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user