Skip to content

Commit

Permalink
trying out datadog logging and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nichelous-herndon committed Dec 30, 2024
1 parent b15c6d6 commit a504f83
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 17 deletions.
16 changes: 0 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,6 @@ PATH
veteran_confirmation (0.0.1)
vye (0.1.0)

GEM
remote: https://enterprise.contribsys.com/
specs:
sidekiq-ent (7.2.4)
einhorn (~> 1.0)
gserver
sidekiq (>= 7.2.0, < 8)
sidekiq-pro (>= 7.2.0, < 8)
sidekiq-pro (7.2.1)
base64
sidekiq (>= 7.2.0, < 8)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -426,7 +414,6 @@ GEM
dry-initializer (~> 3.0)
dry-schema (>= 1.12, < 2)
zeitwerk (~> 2.6)
einhorn (1.0.0)
erubi (1.13.0)
et-orbi (1.2.11)
tzinfo
Expand Down Expand Up @@ -550,7 +537,6 @@ GEM
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
gserver (0.0.1)
guard (2.18.1)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
Expand Down Expand Up @@ -1313,8 +1299,6 @@ DEPENDENCIES
shoulda-matchers
shrine
sidekiq (~> 7.2.0)
sidekiq-ent!
sidekiq-pro!
sign_in_service
simple_forms_api!
simplecov
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ def get_status_type_text(appeal_status, aoj)
appeal_status_description = 'Unknown Status'
unknown_status_error = StandardError.new("Unknown status: #{appeal_status} with AOJ: #{aoj}")
log_exception_to_sentry(unknown_status_error, { appeal_status => appeal_status, aoj => aoj })
# also log to datadog
::Rails.logger.error(
message: unknown_status_error.message
)
end

if appeal_status_description.include? '{aoj_desc}'
Expand All @@ -191,8 +195,12 @@ def set_user_credentials

def service_exception_handler(exception)
context = 'An error occurred while attempting to retrieve the appeal(s)'
# also log to datadog
datadog_message = { message: "#{context}: #{exception.message}" }
datadog_message[:backtrace] = exception.backtrace if exception.backtrace
::Rails.logger.error(datadog_message)
log_exception_to_sentry(exception, 'context' => context)
render nothing: true, status: :internal_server_error
head :internal_server_error
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,21 @@ def service_exception_handler(exception)
context = 'An error occurred while attempting to retrieve the claim(s).'
log_exception_to_sentry(exception, 'context' => context)
render nothing: true, status: :service_unavailable
# also log to datadog
::Rails.logger.error(
message: context + ": #{exception.message}",
backtrace: exception.backtrace
)
end

def report_exception_handler(exception)
context = 'An error occurred while attempting to report the claim(s).'
log_exception_to_sentry(exception, 'context' => context)
# also log to datadog
::Rails.logger.error(
message: context + ": #{exception.message}",
backtrace: exception.backtrace
)
end

class ServiceException < RuntimeError; end
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/v0/virtual_agent_speech_token_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def service_exception_handler(exception)
context = 'An error occurred with the Microsoft service that issues chatbot tokens'
log_exception_to_sentry(exception, 'context' => context)
render nothing: true, status: :service_unavailable
# also log to datadog
::Rails.logger.error(
message: context + ": #{exception.message}",
backtrace: exception.backtrace
)
end

class ServiceException < RuntimeError; end
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/v0/virtual_agent_token_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def service_exception_handler(exception)
context = 'An error occurred with the Microsoft service that issues chatbot tokens'
log_exception_to_sentry(exception, 'context' => context)
render nothing: true, status: :service_unavailable
# also log to datadog
::Rails.logger.error(
message: context + ": #{exception.message}",
backtrace: exception.backtrace
)
end

class ServiceException < RuntimeError; end
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/v0/virtual_agent_token_msft_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def service_exception_handler(exception)
context = 'An error occurred with the Microsoft service that issues chatbot tokens'
log_exception_to_sentry(exception, 'context' => context)
render nothing: true, status: :service_unavailable
# also log to datadog
::Rails.logger.error(
message: context + ": #{exception.message}",
backtrace: exception.backtrace
)
end

class ServiceException < RuntimeError; end
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/v0/virtual_agent_token_nlu_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def service_exception_handler(exception)
context = 'An error occurred with the Microsoft service that issues chatbot tokens'
log_exception_to_sentry(exception, 'context' => context)
render nothing: true, status: :service_unavailable
# also log to datadog
::Rails.logger.error(
message: context + ": #{exception.message}",
backtrace: exception.backtrace
)
end

class ServiceException < RuntimeError; end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe V0::VirtualAgent::VirtualAgentAppealController, type: :controller do
# let(:exception) { StandardError.new('Test error') }
# let(:context) { 'An error occurred while attempting to retrieve the appeal(s)' }

describe '#service_exception_handler' do
let(:exception) { StandardError.new('An error occurred') }

it 'calls service_exception_handler with the exception' do
allow(Rails.logger).to receive(:error)
expect(controller).to receive(:service_exception_handler).with(exception)
expect(Rails.logger).to have_received(:error)
controller.send(:service_exception_handler, exception)
end
end

# before do
# # Simulate a request to ensure the response object is available
# # allow(controller).to receive(:head).with(:internal_server_error)

# get :index
# rescue
# nil
# end

# describe '#service_exception_handler' do
# it 'logs the error to Rails logger' do
# # expect(Rails.logger).to receive(:error).with(
# # exception.message
# # )

# controller.send(:service_exception_handler, exception)

# expect(Rails.logger).to receive(:error).with(
# hash_including(message: a_string_including('Test error'))
# )
# end

# # it 'renders internal server error' do
# # expect(controller).to receive(:head).with(:internal_server_error)

# # controller.send(:service_exception_handler, exception)
# # end
# end
end

0 comments on commit a504f83

Please sign in to comment.