Skip to content

Commit 37487ed

Browse files
reitingRachelstevelong00
authored
Tech Debt: Remove Datadog Tracing (#20727)
* removed datadog tracing * restoring tracking calls and remove do ends * fixing linting errors * Update modules/ivc_champva/app/controllers/ivc_champva/v1/uploads_controller.rb Co-authored-by: Steve Long <[email protected]> * Update modules/ivc_champva/app/controllers/ivc_champva/v1/uploads_controller.rb Co-authored-by: Steve Long <[email protected]> * Update modules/ivc_champva/app/services/ivc_champva/email.rb Co-authored-by: Steve Long <[email protected]> * Update modules/ivc_champva/app/services/ivc_champva/email.rb Co-authored-by: Steve Long <[email protected]> * Update modules/ivc_champva/app/services/ivc_champva/s3.rb Co-authored-by: Steve Long <[email protected]> * Update modules/ivc_champva/app/services/ivc_champva/s3.rb Co-authored-by: Steve Long <[email protected]> * Update modules/ivc_champva/app/services/ivc_champva/s3.rb Co-authored-by: Steve Long <[email protected]> * Update modules/ivc_champva/app/controllers/ivc_champva/v1/pega_controller.rb Co-authored-by: Steve Long <[email protected]> * Update modules/ivc_champva/app/controllers/ivc_champva/v1/pega_controller.rb Co-authored-by: Steve Long <[email protected]> * Update modules/ivc_champva/app/controllers/ivc_champva/v1/pega_controller.rb Co-authored-by: Steve Long <[email protected]> * Update modules/ivc_champva/app/controllers/ivc_champva/v1/pega_controller.rb Co-authored-by: Steve Long <[email protected]> * Linter autocorrections * Removed unit test references to Datadog tracing * linter warnings --------- Co-authored-by: Rachel <[email protected]> Co-authored-by: Steve Long <[email protected]>
1 parent b0f0159 commit 37487ed

File tree

5 files changed

+58
-73
lines changed

5 files changed

+58
-73
lines changed

modules/ivc_champva/app/controllers/ivc_champva/v1/pega_controller.rb

+19-21
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,30 @@ class PegaController < SignIn::ServiceAccountApplicationController
99
VALID_KEYS = %w[form_uuid file_names status case_id].freeze
1010

1111
def update_status
12-
Datadog::Tracing.trace('Start PEGA Status Update') do
13-
data = JSON.parse(params.to_json)
12+
data = JSON.parse(params.to_json)
1413

15-
tags = ['service:veteran-ivc-champva-forms', 'function:form submission to Pega']
14+
tags = ['service:veteran-ivc-champva-forms', 'function:form submission to Pega']
1615

17-
unless data.is_a?(Hash)
18-
# Log the failure due to invalid JSON format
16+
unless data.is_a?(Hash)
17+
# Log the failure due to invalid JSON format
18+
StatsD.increment('silent_failure_avoided_no_confirmation', tags: tags)
19+
render json: JSON.generate({ status: 500, error: 'Invalid JSON format: Expected a JSON object' })
20+
return
21+
end
22+
23+
response =
24+
if valid_keys?(data)
25+
update_data(data['form_uuid'], data['file_names'], data['status'], data['case_id'])
26+
else
1927
StatsD.increment('silent_failure_avoided_no_confirmation', tags: tags)
20-
render json: JSON.generate({ status: 500, error: 'Invalid JSON format: Expected a JSON object' })
21-
return
28+
{ json: { error_message: 'Invalid JSON keys' }, status: :bad_request }
2229
end
2330

24-
response =
25-
if valid_keys?(data)
26-
update_data(data['form_uuid'], data['file_names'], data['status'], data['case_id'])
27-
else
28-
StatsD.increment('silent_failure_avoided_no_confirmation', tags: tags)
29-
{ json: { error_message: 'Invalid JSON keys' }, status: :bad_request }
30-
end
31-
32-
render json: response[:json], status: response[:status]
33-
rescue JSON::ParserError => e
34-
# Log the JSON parsing error
35-
StatsD.increment('silent_failure_avoided_no_confirmation', tags: tags)
36-
render json: { error_message: "JSON parsing error: #{e.message}" }, status: :internal_server_error
37-
end
31+
render json: response[:json], status: response[:status]
32+
rescue JSON::ParserError => e
33+
# Log the JSON parsing error
34+
StatsD.increment('silent_failure_avoided_no_confirmation', tags: tags)
35+
render json: { error_message: "JSON parsing error: #{e.message}" }, status: :internal_server_error
3836
end
3937

4038
private

modules/ivc_champva/app/controllers/ivc_champva/v1/uploads_controller.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ class UploadsController < ApplicationController
1616
}.freeze
1717

1818
def submit
19-
Datadog::Tracing.trace('Start IVC File Submission') do
19+
begin
2020
form_id = get_form_id
21-
Datadog::Tracing.active_trace&.set_tag('form_id', form_id)
2221
parsed_form_data = JSON.parse(params.to_json)
2322
statuses, error_message = handle_file_uploads(form_id, parsed_form_data)
2423

modules/ivc_champva/app/services/ivc_champva/email.rb

+17-19
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,24 @@ def initialize(data)
2424
end
2525

2626
def send_email
27-
Datadog::Tracing.trace('Send PEGA Status Update Email') do
28-
return false unless valid_environment?
27+
return false unless valid_environment?
2928

30-
VANotify::EmailJob.perform_async(
31-
data[:email],
32-
(data[:template_id] ? EMAIL_TEMPLATE_MAP[data[:template_id]] : EMAIL_TEMPLATE_MAP[data[:form_number]]),
33-
# Create a subset of `data` - Using .index_with rather than .slice so that keys
34-
# default to `nil` if not present in `data`. This helps us w/ testing.
35-
%i[first_name last_name file_count pega_status date_submitted form_uuid]
36-
.index_with { |k| data[k] },
37-
Settings.vanotify.services.ivc_champva.api_key,
38-
# If no callback_klass is provided, should fail safely per va_notify implementation.
39-
# See: https://github.com/department-of-veterans-affairs/vets-api/tree/master/modules/va_notify#how-teams-can-integrate-with-callbacks
40-
{ callback_klass: data[:callback_klass], callback_metadata: data[:callback_metadata] }
41-
)
42-
true
43-
rescue => e
44-
Rails.logger.error "Pega Status Update Email Error: #{e.message}"
45-
Rails.logger.error e.backtrace.join("\n")
46-
end
29+
VANotify::EmailJob.perform_async(
30+
data[:email],
31+
(data[:template_id] ? EMAIL_TEMPLATE_MAP[data[:template_id]] : EMAIL_TEMPLATE_MAP[data[:form_number]]),
32+
# Create a subset of `data` - Using .index_with rather than .slice so that keys
33+
# default to `nil` if not present in `data`. This helps us w/ testing.
34+
%i[first_name last_name file_count pega_status date_submitted form_uuid]
35+
.index_with { |k| data[k] },
36+
Settings.vanotify.services.ivc_champva.api_key,
37+
# If no callback_klass is provided, should fail safely per va_notify implementation.
38+
# See: https://github.com/department-of-veterans-affairs/vets-api/tree/master/modules/va_notify#how-teams-can-integrate-with-callbacks
39+
{ callback_klass: data[:callback_klass], callback_metadata: data[:callback_metadata] }
40+
)
41+
true
42+
rescue => e
43+
Rails.logger.error "Pega Status Update Email Error: #{e.message}"
44+
Rails.logger.error e.backtrace.join("\n")
4745
end
4846

4947
private

modules/ivc_champva/app/services/ivc_champva/s3.rb

+21-25
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,34 @@ def initialize(region:, bucket:)
1212
end
1313

1414
def put_object(key, file, metadata = {})
15-
Datadog::Tracing.trace('S3 Put File(s)') do
16-
metadata&.transform_values! { |value| value || '' }
15+
metadata&.transform_values! { |value| value || '' }
1716

18-
begin
19-
response = client.put_object(
20-
bucket:,
21-
key:,
22-
body: File.read(file),
23-
metadata: metadata
24-
)
25-
result = { success: true }
26-
rescue => e
27-
result = { success: false, error_message: "S3 PutObject failure for #{file}: #{e.message}" }
28-
end
17+
begin
18+
response = client.put_object(
19+
bucket:,
20+
key:,
21+
body: File.read(file),
22+
metadata: metadata
23+
)
24+
result = { success: true }
25+
rescue => e
26+
result = { success: false, error_message: "S3 PutObject failure for #{file}: #{e.message}" }
27+
end
2928

30-
if Flipper.enabled?(:champva_log_all_s3_uploads, @current_user)
31-
response ? handle_put_object_response(response, key, file) : handle_put_object_error(e)
32-
else
33-
result
34-
end
29+
if Flipper.enabled?(:champva_log_all_s3_uploads, @current_user)
30+
response ? handle_put_object_response(response, key, file) : handle_put_object_error(e)
31+
else
32+
result
3533
end
3634
end
3735

3836
def upload_file(key, file)
39-
Datadog::Tracing.trace('S3 Upload File(s)') do
40-
obj = resource.bucket(bucket).object(key)
41-
obj.upload_file(file)
37+
obj = resource.bucket(bucket).object(key)
38+
obj.upload_file(file)
4239

43-
{ success: true }
44-
rescue => e
45-
{ success: false, error_message: "S3 UploadFile failure for #{file}: #{e.message}" }
46-
end
40+
{ success: true }
41+
rescue => e
42+
{ success: false, error_message: "S3 UploadFile failure for #{file}: #{e.message}" }
4743
end
4844

4945
def monitor

modules/ivc_champva/spec/services/email_spec.rb

-6
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
allow(Rails).to receive(:env).and_return('staging')
2626
end
2727

28-
it 'traces the sending email process' do
29-
expect(Datadog::Tracing).to receive(:trace).with('Send PEGA Status Update Email').and_yield
30-
subject.send_email
31-
end
32-
3328
it 'enqueues VANotify::EmailJob with correct parameters' do
3429
expect(VANotify::EmailJob).to receive(:perform_async).with(
3530
data[:email],
@@ -60,7 +55,6 @@
6055
end
6156

6257
it 'handles the error and logs it' do
63-
allow(Datadog::Tracing).to receive(:trace).and_yield
6458
allow(Rails.logger).to receive(:error)
6559

6660
expect { subject.send_email }.not_to raise_error

0 commit comments

Comments
 (0)