Skip to content

Commit

Permalink
Submit Benefits Intake Claim logging fixes (#16107)
Browse files Browse the repository at this point in the history
* level set

* level set with master

* removing yarn.lock

* Changed the message text

* Added attempt logging

* Fix for statsd key prefix

* Moving from sentry to Rails.logger calls directly

* Change to method name
  • Loading branch information
micahaspyr authored Mar 29, 2024
1 parent db4fea2 commit e35b7e8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
31 changes: 17 additions & 14 deletions app/sidekiq/lighthouse/submit_benefits_intake_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SubmitBenefitsIntakeClaim
class BenefitsIntakeClaimError < StandardError; end

FOREIGN_POSTALCODE = '00000'
STATSD_KEY_PREFIX = 'worker.central_mail.submit_benefits_intake_claim'
STATSD_KEY_PREFIX = 'worker.lighthouse.submit_benefits_intake_claim'

# Sidekiq has built in exponential back-off functionality for retries
# A max retry attempt of 14 will result in a run time of ~25 hours
Expand All @@ -23,9 +23,8 @@ class BenefitsIntakeClaimError < StandardError; end
sidekiq_options retry: RETRY

sidekiq_retries_exhausted do |msg, _ex|
Rails.logger.send(
:error,
"Failed all retries on CentralMail::SubmitBenefitsIntakeClaim, last error: #{msg['error_message']}"
Rails.logger.error(
"Failed all retries on Lighthouse::SubmitBenefitsIntakeClaim, last error: #{msg['error_message']}"
)
StatsD.increment("#{STATSD_KEY_PREFIX}.exhausted")
end
Expand All @@ -39,7 +38,7 @@ def perform(saved_claim_id)
end

@lighthouse_service = BenefitsIntakeService::Service.new(with_upload_location: true)
create_form_submission_attempt(@lighthouse_service.uuid)
create_form_submission_attempt

payload = {
upload_url: @lighthouse_service.location,
Expand All @@ -51,14 +50,13 @@ def perform(saved_claim_id)
response = @lighthouse_service.upload_doc(**payload)

if response.success?
log_message_to_sentry('CentralMail::SubmitSavedClaimJob succeeded', :info, generate_sentry_details)
Rails.logger.info('Lighthouse::SubmitBenefitsIntakeClaim succeeded', generate_log_details)
@claim.send_confirmation_email if @claim.respond_to?(:send_confirmation_email)
else
raise BenefitsIntakeClaimError, response.body
end
rescue => e
log_message_to_sentry('CentralMail::SubmitBenefitsIntakeClaim failed, retrying...', :warn,
generate_sentry_details(e))
Rails.logger.warn('Lighthouse::SubmitBenefitsIntakeClaim failed, retrying...', generate_log_details(e))
raise
ensure
cleanup_file_paths
Expand Down Expand Up @@ -100,21 +98,26 @@ def split_file_and_path(path)

private

def generate_sentry_details(e = nil)
def generate_log_details(e = nil)
details = {
'guid' => @claim&.guid,
'docType' => @claim&.form_id,
'savedClaimId' => @saved_claim_id
claim_id: @claim.id,
benefits_intake_uuid: @lighthouse_service.uuid,
confirmation_number: @claim.confirmation_number
}
details['error'] = e.message if e
details
end

def create_form_submission_attempt(intake_uuid)
def create_form_submission_attempt
Rails.logger.info('Lighthouse::SubmitBenefitsIntakeClaim job starting', {
claim_id: @claim.id,
benefits_intake_uuid: @lighthouse_service.uuid,
confirmation_number: @claim.confirmation_number
})
form_submission = FormSubmission.create(
form_type: @claim.form_id,
form_data: @claim.to_json,
benefits_intake_uuid: intake_uuid,
benefits_intake_uuid: @lighthouse_service.uuid,
saved_claim: @claim
)
@form_submission_attempt = FormSubmissionAttempt.create(form_submission:)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
it 'logs a distinct error when retries are exhausted' do
Lighthouse::SubmitBenefitsIntakeClaim.within_sidekiq_retries_exhausted_block do
expect(Rails.logger).to receive(:error).exactly(:once)
expect(StatsD).to receive(:increment).with('worker.central_mail.submit_benefits_intake_claim.exhausted')
expect(StatsD).to receive(:increment).with('worker.lighthouse.submit_benefits_intake_claim.exhausted')
end
end
end
Expand Down

0 comments on commit e35b7e8

Please sign in to comment.