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:
parent
360b438a55
commit
04dfb034cc
25 changed files with 173 additions and 108 deletions
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
|
Loading…
Add table
Add a link
Reference in a new issue