Skip to content

Commit

Permalink
Add more metadata when tracking PDF share event
Browse files Browse the repository at this point in the history
We need to track a few fields in order to give us metrics on how mayn
accounts are linked, as well as the number of paystubs and account
descriptions.

This logic gets me worried for bugs, since it's in a critical place, so
I'm putting it in a rescue block so it doesn't break the sending of the
actual documents.
  • Loading branch information
tdooner committed Aug 22, 2024
1 parent 509bf70 commit f314d61
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/app/controllers/cbv/summaries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,21 @@ def transmit_to_caseworker
@cbv_flow.touch(:transmitted_at)
end

track_transmitted_event(@cbv_flow, @payments)
end

def track_transmitted_event(cbv_flow, payments)
NewRelicEventTracker.track("IncomeSummarySharedWithCaseworker", {
timestamp: Time.now.to_i,
site_id: @cbv_flow.site_id,
cbv_flow_id: @cbv_flow.id
site_id: cbv_flow.site_id,
cbv_flow_id: cbv_flow.id,
account_count: payments.map { |p| p[:account_id] }.uniq.count,
paystub_count: payments.count,
account_count_with_additional_information:
cbv_flow.additional_information.values.count { |info| info["comment"].present? }
})
rescue => ex
Rails.logger.error "Failed to track NewRelic event: #{ex.message}"
end

def generate_confirmation_code(prefix = nil)
Expand Down
13 changes: 13 additions & 0 deletions app/spec/controllers/cbv/summaries_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,19 @@
patch :update
expect(response).to redirect_to({ controller: :successes, action: :show })
end

it "sends a NewRelic event" do
allow(NewRelicEventTracker).to receive(:track)
patch :update
expect(NewRelicEventTracker).to have_received(:track).with("IncomeSummarySharedWithCaseworker", {
timestamp: be_a(Integer),
site_id: cbv_flow.site_id,
cbv_flow_id: cbv_flow.id,
account_count: 1,
paystub_count: 1,
account_count_with_additional_information: 0
})
end
end
end
end

0 comments on commit f314d61

Please sign in to comment.