mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 02:57:57 +00:00 
			
		
		
		
	 d188600559
			
		
	
	d188600559
	
	
	
		
			
			Right now, if sentry is configured exception won't be logged. This results in the log management tool missing every error captured with ChatwootExceptionTracker. This change logs the exception, even if Sentry is configured or not. Fixes https://linear.app/chatwoot/issue/CW-2145/improve-logging-info-debug-trace
		
			
				
	
	
		
			33 lines
		
	
	
		
			925 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			925 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| ###############
 | |
| # 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?
 | |
|     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
 | |
|   end
 | |
| end
 |