Skip to content

Commit fe8f209

Browse files
added metrics for failed invoices
1 parent 34de74d commit fe8f209

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

app/services/eis_billing/base_service.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,26 @@ module EisBilling
44
module BaseService
55
def struct_response(response)
66
if response['error'].present?
7+
increment_failure_counter(error_type: 'provider_error')
78
wrap(result: false, instance: nil, errors: response['error'])
89
else
910
wrap(result: true, instance: response, errors: nil)
1011
end
1112
rescue StandardError => e
13+
increment_failure_counter(error_type: 'exception', exception_class: e.class.name)
1214
wrap(result: false, instance: nil, errors: e)
1315
end
1416

17+
private
18+
19+
def increment_failure_counter(error_type:, exception_class: nil)
20+
Yabeda.eis_billing.payment_failures_total.increment(
21+
service: self.class.name.demodulize,
22+
error_type: error_type,
23+
exception_class: exception_class || 'none'
24+
)
25+
end
26+
1527
def wrap(**kwargs)
1628
result = kwargs[:result]
1729
instance = kwargs[:instance]

config/initializers/yabeda.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
tags: [:sql_type],
1313
buckets: [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5]
1414
end
15+
16+
group :eis_billing do
17+
counter :payment_failures_total,
18+
comment: 'Total payment failures from EIS Billing provider',
19+
tags: [:service, :error_type, :exception_class]
20+
end
1521
end
1622

1723
ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|

0 commit comments

Comments
 (0)