Module: DecisionReviewV1::Appeals::LoggingUtils
- Included in:
- DecisionReview::NodEmailLoaderJob, DecisionReview::NodSendEmailJob, DecisionReview::Service, DecisionReview::SubmitUpload, Helpers, SupplementalClaimServices, Service, V1::DecisionReviewEvidencesController, V1::DecisionReviewNotificationCallbacksController
- Defined in:
- lib/decision_review_v1/utilities/logging_utils.rb
Instance Method Summary collapse
- #benchmark? ⇒ Boolean private
-
#benchmark_to_log_data_hash(bm) ⇒ result, benchmark
Takes a block and runs it.
- #extract_uuid_from_central_mail_message(data, uuid) ⇒ Object private
-
#log_formatted(key:, user_uuid:, form_id:, is_success:, upstream_system: nil, downstream_system: nil, response_error: nil, status_code: nil, body: nil, params: {}) ⇒ void
Logs formatted information about an appeal.
-
#parse_form412_response_to_log_msg(appeal_submission_id:, data:, uuid: nil, bm: nil) ⇒ Object
rubocop:enable Metrics/ParameterLists rubocop:enable Layout/LineLength.
- #parse_lighthouse_response_to_log_msg(data:, bm: nil) ⇒ Object
- #run_and_benchmark_if_enabled(&block) ⇒ Object
Instance Method Details
#benchmark? ⇒ Boolean (private)
118 119 120 |
# File 'lib/decision_review_v1/utilities/logging_utils.rb', line 118 def benchmark? Settings.decision_review.benchmark_performance end |
#benchmark_to_log_data_hash(bm) ⇒ result, benchmark
Takes a block and runs it. If benchmarking is enabled it will benchmark and return the results. Returns a tuple of what the block returns, and either nil (if benchmarking disabled), or the benchmark results
106 107 108 |
# File 'lib/decision_review_v1/utilities/logging_utils.rb', line 106 def benchmark_to_log_data_hash(bm) { benchmark: { user: bm.utime, system: bm.stime, total: bm.total, real: bm.real } } end |
#extract_uuid_from_central_mail_message(data, uuid) ⇒ Object (private)
112 113 114 115 116 |
# File 'lib/decision_review_v1/utilities/logging_utils.rb', line 112 def (data, uuid) return uuid unless uuid.nil? data.body[/(?<=\[).*?(?=\])/].split(': ').last end |
#log_formatted(key:, user_uuid:, form_id:, is_success:, upstream_system: nil, downstream_system: nil, response_error: nil, status_code: nil, body: nil, params: {}) ⇒ void
This method returns an undefined value.
Logs formatted information about an appeal.
rubocop:disable Metrics/ParameterLists rubocop:disable Layout/LineLength
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/decision_review_v1/utilities/logging_utils.rb', line 24 def log_formatted(key:, user_uuid:, form_id:, is_success:, upstream_system: nil, downstream_system: nil, response_error: nil, status_code: nil, body: nil, params: {}) action = key.to_s.humanize result = is_success ? 'success' : 'failure' log_level = is_success ? :info : :error # The HTTP clients used across VA raise various response error objects with varying interfaces, hence the ORs # below. Preference is given to `original_status` and `original_body`, if present, as they represent the status # and body returned by the third party service, which is most helpful for logging purposes. It is always # possible that the error thrown has nothing to do with the HTTP request, hence the `message` call. Both # `status_code` and `body` can be overriden. status_code ||= response_error.try(:original_status) || response_error.try(:status_code) || response_error.try(:status) body ||= response_error.try(:original_body) || response_error.try(:message) StatsD.increment("decision_review.form_#{form_id}.#{key}.#{result}") Rails.logger.send(log_level, { message: "#{action} #{result}!", user_uuid:, action:, form_id:, upstream_system:, downstream_system:, is_success:, http: { status_code:, body: } }.merge(params)) end |
#parse_form412_response_to_log_msg(appeal_submission_id:, data:, uuid: nil, bm: nil) ⇒ Object
rubocop:enable Metrics/ParameterLists rubocop:enable Layout/LineLength
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/decision_review_v1/utilities/logging_utils.rb', line 55 def parse_form412_response_to_log_msg(appeal_submission_id:, data:, uuid: nil, bm: nil) log_data = { message: 'Supplemental Claim 4142 submitted.', lighthouse_submission: { id: appeal_submission_id }, form_id: FORM4142_ID, parent_form_id: SUPP_CLAIM_FORM_ID, response_body: data.body, response_status: data.status } log_data[:extracted_uuid] = (data, uuid) if data.success? log_data[:meta] = benchmark_to_log_data_hash(bm) unless bm.nil? log_data end |
#parse_lighthouse_response_to_log_msg(data:, bm: nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/decision_review_v1/utilities/logging_utils.rb', line 68 def parse_lighthouse_response_to_log_msg(data:, bm: nil) log_data = { form_id: SUPP_CLAIM_FORM_ID, message: 'Successful Lighthouse Supplemental Claim Submission', lighthouse_submission: { id: data['id'], appeal_type: data['type'], attributes: { status: data['attributes']['status'], updatedAt: data['attributes']['updatedAt'], createdAt: data['attributes']['createdAt'] } } } log_data[:meta] = benchmark_to_log_data_hash(bm) unless bm.nil? log_data end |
#run_and_benchmark_if_enabled(&block) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/decision_review_v1/utilities/logging_utils.rb', line 86 def run_and_benchmark_if_enabled(&block) bm = nil block_result = nil if benchmark? bm = Benchmark.measure do block_result = block.call end else block_result = block.call end [block_result, bm] end |