Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b603832b2e | ||
|
|
09a610a442 | ||
|
|
74c689e4ad | ||
|
|
ca2e7522a0 | ||
|
|
41367739d1 | ||
|
|
fb0f4234d3 | ||
|
|
99a54a9501 |
@@ -33,12 +33,19 @@ class NotificationListener < BaseListener
|
|||||||
return if event.data[:notifiable_assignee_change].blank?
|
return if event.data[:notifiable_assignee_change].blank?
|
||||||
return if conversation.pending?
|
return if conversation.pending?
|
||||||
|
|
||||||
|
Rails.logger.info "[NotificationListener] Assignee changed for conversation: #{conversation.id} to #{assignee&.id} [#{assignee&.email}]"
|
||||||
|
|
||||||
NotificationBuilder.new(
|
NotificationBuilder.new(
|
||||||
notification_type: 'conversation_assignment',
|
notification_type: 'conversation_assignment',
|
||||||
user: assignee,
|
user: assignee,
|
||||||
account: account,
|
account: account,
|
||||||
primary_actor: conversation
|
primary_actor: conversation
|
||||||
).perform
|
).perform
|
||||||
|
rescue NoMethodError => e
|
||||||
|
Rails.logger.error "[NotificationListener] Error in assignee_changed: #{e.message}"
|
||||||
|
exception_tracker = ChatwootExceptionTracker.new(e, account: account,
|
||||||
|
additional_context: { 'conversation': conversation, 'assignee': assignee })
|
||||||
|
exception_tracker.capture_exception
|
||||||
end
|
end
|
||||||
|
|
||||||
def message_created(event)
|
def message_created(event)
|
||||||
|
|||||||
@@ -5,10 +5,11 @@
|
|||||||
############
|
############
|
||||||
|
|
||||||
class ChatwootExceptionTracker
|
class ChatwootExceptionTracker
|
||||||
def initialize(exception, user: nil, account: nil)
|
def initialize(exception, user: nil, account: nil, additional_context: {})
|
||||||
@exception = exception
|
@exception = exception
|
||||||
@user = user
|
@user = user
|
||||||
@account = account
|
@account = account
|
||||||
|
@additional_context = additional_context
|
||||||
end
|
end
|
||||||
|
|
||||||
def capture_exception
|
def capture_exception
|
||||||
@@ -20,13 +21,29 @@ class ChatwootExceptionTracker
|
|||||||
|
|
||||||
def capture_exception_with_sentry
|
def capture_exception_with_sentry
|
||||||
Sentry.with_scope do |scope|
|
Sentry.with_scope do |scope|
|
||||||
if @account.present?
|
append_account_context(scope)
|
||||||
scope.set_context('account', { id: @account.id, name: @account.name })
|
append_additional_context(scope)
|
||||||
scope.set_tags(account_id: @account.id)
|
append_user_context(scope)
|
||||||
end
|
|
||||||
|
|
||||||
scope.set_user(id: @user.id, email: @user.email) if @user.is_a?(User)
|
|
||||||
Sentry.capture_exception(@exception)
|
Sentry.capture_exception(@exception)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def append_account_context(scope)
|
||||||
|
return if @account.blank?
|
||||||
|
|
||||||
|
scope.set_context('account', { id: @account.id, name: @account.name })
|
||||||
|
scope.set_tags(account_id: @account.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def append_additional_context(scope)
|
||||||
|
@additional_context.each do |key, value|
|
||||||
|
scope.set_context(key.to_s, value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def append_user_context(scope)
|
||||||
|
return unless @user.is_a?(User)
|
||||||
|
|
||||||
|
scope.set_user(id: @user.id, email: @user.email)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,5 +22,20 @@ describe ChatwootExceptionTracker do
|
|||||||
described_class.new('random').capture_exception
|
described_class.new('random').capture_exception
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'sets additional context when provided' do
|
||||||
|
additional_context = { key1: 'value1', key2: 'value2' }
|
||||||
|
|
||||||
|
with_modified_env SENTRY_DSN: 'random dsn' do
|
||||||
|
scope = instance_double(Sentry::Scope)
|
||||||
|
allow(Sentry).to receive(:with_scope).and_yield(scope)
|
||||||
|
|
||||||
|
expect(scope).to receive(:set_context).with('key1', 'value1')
|
||||||
|
expect(scope).to receive(:set_context).with('key2', 'value2')
|
||||||
|
expect(Sentry).to receive(:capture_exception).with('random')
|
||||||
|
|
||||||
|
described_class.new('random', additional_context: additional_context).capture_exception
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user