[privacy] make observability local-only

This commit is contained in:
Kunthawat Greethong
2026-08-16 02:29:29 +07:00
parent 372f3165ce
commit 19dc44969a
29 changed files with 96 additions and 541 deletions

View File

@@ -1,32 +1,23 @@
###############
# 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
# Local-only exception compatibility surface.
# The optional user/account arguments remain accepted for callsite compatibility,
# but are intentionally not retained, serialized, or sent anywhere.
############
class ChatwootExceptionTracker
def initialize(exception, user: nil, account: nil)
@exception = exception
@user = user
@account = account
discard_optional_context(user)
discard_optional_context(account)
end
def capture_exception
capture_exception_with_sentry if ENV['SENTRY_DSN'].present?
Rails.logger.error @exception
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
def discard_optional_context(_value)
nil
end
end