|
| 1 | +require "concurrent" |
1 | 2 | require "httparty" |
2 | 3 | require "logger" |
3 | 4 | require "json" |
@@ -54,25 +55,10 @@ def configured? |
54 | 55 | end |
55 | 56 |
|
56 | 57 | def track_exception(exception_instance, env = {}, user = nil, retry_count = 1) |
57 | | - if should_report?(exception_instance) |
58 | | - log("[Raygun] Tracking Exception...") |
59 | | - Client.new.track_exception(exception_instance, env, user) |
60 | | - end |
61 | | - rescue Exception => e |
62 | | - if configuration.failsafe_logger |
63 | | - failsafe_log("Problem reporting exception to Raygun: #{e.class}: #{e.message}\n\n#{e.backtrace.join("\n")}") |
64 | | - end |
65 | | - |
66 | | - if retry_count > 0 |
67 | | - new_exception = e.exception("raygun4ruby encountered an exception processing your exception") |
68 | | - new_exception.set_backtrace(e.backtrace) |
69 | | - |
70 | | - env[:custom_data] ||= {} |
71 | | - env[:custom_data].merge!(original_stacktrace: exception_instance.backtrace) |
72 | | - |
73 | | - track_exception(new_exception, env, user, retry_count - 1) |
| 58 | + if configuration.send_in_background |
| 59 | + track_exception_async(exception_instance, env, user, retry_count) |
74 | 60 | else |
75 | | - raise e |
| 61 | + track_exception_sync(exception_instance, env, user, retry_count) |
76 | 62 | end |
77 | 63 | end |
78 | 64 |
|
@@ -122,6 +108,39 @@ def deprecation_warning(message) |
122 | 108 |
|
123 | 109 | private |
124 | 110 |
|
| 111 | + def track_exception_async(*args) |
| 112 | + future = Concurrent::Future.execute { track_exception_sync(*args) } |
| 113 | + future.add_observer(lambda do |_, value, reason| |
| 114 | + if value == nil || value.response.code != "202" |
| 115 | + log("[Raygun] unexpected response from Raygun, could indicate error: #{value.inspect}") |
| 116 | + end |
| 117 | + end, :call) |
| 118 | + end |
| 119 | + |
| 120 | + def track_exception_sync(exception_instance, env, user, retry_count) |
| 121 | + if should_report?(exception_instance) |
| 122 | + log("[Raygun] Tracking Exception...") |
| 123 | + Client.new.track_exception(exception_instance, env, user) |
| 124 | + end |
| 125 | + rescue Exception => e |
| 126 | + if configuration.failsafe_logger |
| 127 | + failsafe_log("Problem reporting exception to Raygun: #{e.class}: #{e.message}\n\n#{e.backtrace.join("\n")}") |
| 128 | + end |
| 129 | + |
| 130 | + if retry_count > 0 |
| 131 | + new_exception = e.exception("raygun4ruby encountered an exception processing your exception") |
| 132 | + new_exception.set_backtrace(e.backtrace) |
| 133 | + |
| 134 | + env[:custom_data] ||= {} |
| 135 | + env[:custom_data].merge!(original_stacktrace: exception_instance.backtrace) |
| 136 | + |
| 137 | + track_exception(new_exception, env, user, retry_count - 1) |
| 138 | + else |
| 139 | + raise e |
| 140 | + end |
| 141 | + end |
| 142 | + |
| 143 | + |
125 | 144 | def print_api_key_warning |
126 | 145 | $stderr.puts(NO_API_KEY_MESSAGE) |
127 | 146 | end |
|
0 commit comments