@@ -60,15 +60,15 @@ def configured?
60
60
!!configuration . api_key
61
61
end
62
62
63
- def track_exception ( exception_instance , env = { } , user = nil , retry_count = 1 )
63
+ def track_exception ( exception_instance , env = { } , user = nil , retries_remaining = configuration . error_report_max_attempts - 1 )
64
64
log ( 'tracking exception' )
65
65
66
66
exception_instance . set_backtrace ( caller ) if exception_instance . is_a? ( Exception ) && exception_instance . backtrace . nil?
67
67
68
68
result = if configuration . send_in_background
69
- track_exception_async ( exception_instance , env , user , retry_count )
69
+ track_exception_async ( exception_instance , env , user , retries_remaining )
70
70
else
71
- track_exception_sync ( exception_instance , env , user , retry_count )
71
+ track_exception_sync ( exception_instance , env , user , retries_remaining )
72
72
end
73
73
74
74
result
@@ -128,10 +128,10 @@ def wait_for_futures
128
128
129
129
private
130
130
131
- def track_exception_async ( exception_instance , env , user , retry_count )
131
+ def track_exception_async ( exception_instance , env , user , retries_remaining )
132
132
env [ :rg_breadcrumb_store ] = Raygun ::Breadcrumbs ::Store . take_until_size ( Client ::MAX_BREADCRUMBS_SIZE ) if Raygun ::Breadcrumbs ::Store . any?
133
133
134
- future = Concurrent ::Future . execute { track_exception_sync ( exception_instance , env , user , retry_count ) }
134
+ future = Concurrent ::Future . execute { track_exception_sync ( exception_instance , env , user , retries_remaining ) }
135
135
future . add_observer ( lambda do |_ , value , reason |
136
136
if value == nil || !value . responds_to? ( :response ) || value . response . code != "202"
137
137
log ( "unexpected response from Raygun, could indicate error: #{ value . inspect } " )
@@ -143,7 +143,7 @@ def track_exception_async(exception_instance, env, user, retry_count)
143
143
future
144
144
end
145
145
146
- def track_exception_sync ( exception_instance , env , user , retry_count )
146
+ def track_exception_sync ( exception_instance , env , user , retries_remaining )
147
147
if should_report? ( exception_instance )
148
148
log ( 'attempting to send exception' )
149
149
resp = Client . new . track_exception ( exception_instance , env , user )
@@ -158,18 +158,25 @@ def track_exception_sync(exception_instance, env, user, retry_count)
158
158
failsafe_log ( "Problem reporting exception to Raygun: #{ e . class } : #{ e . message } \n \n #{ e . backtrace . join ( "\n " ) } " )
159
159
end
160
160
161
- if retry_count > 0
161
+ if retries_remaining > 0
162
162
new_exception = e . exception ( "raygun4ruby encountered an exception processing your exception" )
163
163
new_exception . set_backtrace ( e . backtrace )
164
164
165
165
env [ :custom_data ] ||= { }
166
- env [ :custom_data ] . merge! ( original_stacktrace : exception_instance . backtrace )
166
+ env [ :custom_data ] . merge! ( original_stacktrace : exception_instance . backtrace , retries_remaining : retries_remaining )
167
167
168
168
::Raygun ::Breadcrumbs ::Store . clear
169
169
170
- track_exception ( new_exception , env , user , retry_count - 1 )
170
+ track_exception ( new_exception , env , user , retries_remaining - 1 )
171
171
else
172
- raise e
172
+ if configuration . raise_on_failed_error_report
173
+ raise e
174
+ else
175
+ retries = configuration . error_report_max_attempts - retries_remaining
176
+ if configuration . failsafe_logger
177
+ failsafe_log ( "Gave up reporting exception to Raygun after #{ retries } #{ retries == 1 ? "retry" : "retries" } : #{ e . class } : #{ e . message } \n \n #{ e . backtrace . join ( "\n " ) } " )
178
+ end
179
+ end
173
180
end
174
181
end
175
182
0 commit comments