raygun4ruby 4.0.1 → 4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/raygun/configuration.rb +8 -0
- data/lib/raygun/version.rb +1 -1
- data/lib/raygun.rb +17 -10
- data/raygun4ruby.gemspec +1 -0
- data/test/unit/raygun_test.rb +39 -0
- data/test/unit/sidekiq_failure_test.rb +13 -13
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1f1acdc84e42b8f39dd817b3e3b74e39dd18b07c675f46afa1cb57bf42bb435
|
4
|
+
data.tar.gz: 6ca0a6036d1d56d23e66105c5535ccc8687973b55b32e461d7643543693e475a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 318c63ba10cb3645f7c75b81f1f4da06de5f361650f3ae7b3a32cc229fa9670589b742952e3cbb1929cfb02d581bdac3fd45c120b957645bea5c9339096021ff
|
7
|
+
data.tar.gz: 396e058ef6bb5fe5a802a6430c548d3133e2b50000af67bdca300cb280c211d2f5464fb12afe4c3c694e658c5887c1983f1d7af08e4cbc2b535c88be75917558
|
data/lib/raygun/configuration.rb
CHANGED
@@ -86,6 +86,12 @@ module Raygun
|
|
86
86
|
# How long to wait for the POST request to the API server before timing out
|
87
87
|
config_option :error_report_send_timeout
|
88
88
|
|
89
|
+
# How many times to try sending to Raygun before giving up
|
90
|
+
config_option :error_report_max_attempts
|
91
|
+
|
92
|
+
# Whether or not we should raise an exception if the error reporting fails
|
93
|
+
config_option :raise_on_failed_error_report
|
94
|
+
|
89
95
|
# Should we register an error handler with [Rails' built in API](https://edgeguides.rubyonrails.org/error_reporting.html)
|
90
96
|
config_option :register_rails_error_handler
|
91
97
|
|
@@ -147,6 +153,8 @@ module Raygun
|
|
147
153
|
record_raw_data: false,
|
148
154
|
send_in_background: false,
|
149
155
|
error_report_send_timeout: 10,
|
156
|
+
error_report_max_attempts: 1,
|
157
|
+
raise_on_failed_error_report: false,
|
150
158
|
track_retried_sidekiq_jobs: true
|
151
159
|
)
|
152
160
|
end
|
data/lib/raygun/version.rb
CHANGED
data/lib/raygun.rb
CHANGED
@@ -60,15 +60,15 @@ module Raygun
|
|
60
60
|
!!configuration.api_key
|
61
61
|
end
|
62
62
|
|
63
|
-
def track_exception(exception_instance, env = {}, user = nil,
|
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,
|
69
|
+
track_exception_async(exception_instance, env, user, retries_remaining)
|
70
70
|
else
|
71
|
-
track_exception_sync(exception_instance, env, user,
|
71
|
+
track_exception_sync(exception_instance, env, user, retries_remaining)
|
72
72
|
end
|
73
73
|
|
74
74
|
result
|
@@ -128,10 +128,10 @@ module Raygun
|
|
128
128
|
|
129
129
|
private
|
130
130
|
|
131
|
-
def track_exception_async(exception_instance, env, user,
|
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,
|
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 @@ module Raygun
|
|
143
143
|
future
|
144
144
|
end
|
145
145
|
|
146
|
-
def track_exception_sync(exception_instance, env, user,
|
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 @@ module Raygun
|
|
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
|
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,
|
170
|
+
track_exception(new_exception, env, user, retries_remaining - 1)
|
171
171
|
else
|
172
|
-
|
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
|
|
data/raygun4ruby.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_runtime_dependency "json"
|
25
25
|
spec.add_runtime_dependency "rack"
|
26
26
|
spec.add_runtime_dependency "concurrent-ruby"
|
27
|
+
spec.add_runtime_dependency "ostruct"
|
27
28
|
|
28
29
|
spec.add_development_dependency "bundler", ">= 2.3"
|
29
30
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
data/test/unit/raygun_test.rb
CHANGED
@@ -103,4 +103,43 @@ class RaygunTest < Raygun::UnitTest
|
|
103
103
|
assert_equal Raygun.default_configuration.api_url, Raygun.configuration.api_url
|
104
104
|
refute_equal original_api_url, Raygun.configuration.api_url
|
105
105
|
end
|
106
|
+
|
107
|
+
def test_retries
|
108
|
+
failsafe_logger = FakeLogger.new
|
109
|
+
Raygun.setup do |c|
|
110
|
+
c.error_report_max_attempts = 3
|
111
|
+
c.failsafe_logger = failsafe_logger
|
112
|
+
end
|
113
|
+
|
114
|
+
WebMock.reset!
|
115
|
+
report_request = stub_request(:post, "https://api.raygun.com/entries").to_timeout
|
116
|
+
|
117
|
+
error = StandardError.new
|
118
|
+
Raygun.track_exception(error)
|
119
|
+
|
120
|
+
assert_requested report_request, times: 3
|
121
|
+
|
122
|
+
assert_match(/Gave up reporting exception to Raygun after 3 retries/, failsafe_logger.get)
|
123
|
+
ensure
|
124
|
+
Raygun.reset_configuration
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_raising_on_retry_failure
|
128
|
+
Raygun.setup do |c|
|
129
|
+
c.error_report_max_attempts = 1
|
130
|
+
c.raise_on_failed_error_report = true
|
131
|
+
end
|
132
|
+
|
133
|
+
report_request = stub_request(:post, "https://api.raygun.com/entries").to_timeout
|
134
|
+
|
135
|
+
error = StandardError.new
|
136
|
+
|
137
|
+
assert_raises(StandardError) do
|
138
|
+
Raygun.track_exception(error)
|
139
|
+
assert_requested report_request
|
140
|
+
end
|
141
|
+
|
142
|
+
ensure
|
143
|
+
Raygun.reset_configuration
|
144
|
+
end
|
106
145
|
end
|
@@ -48,16 +48,16 @@ class SidekiqFailureTest < Raygun::UnitTest
|
|
48
48
|
raise Sidekiq::JobRetry::Handled
|
49
49
|
end
|
50
50
|
|
51
|
-
|
51
|
+
rescue Sidekiq::JobRetry::Handled => e
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
response = Raygun::SidekiqReporter.call(
|
54
|
+
e,
|
55
|
+
{ sidekick_name: "robin" },
|
56
|
+
{} # config
|
57
|
+
)
|
58
58
|
|
59
|
-
|
60
|
-
|
59
|
+
assert_requested unwrapped_stub
|
60
|
+
assert response && response.success?, "Expected success, got #{response.class}: #{response.inspect}"
|
61
61
|
end
|
62
62
|
|
63
63
|
def test_failured_backend_ignores_retries_if_configured
|
@@ -69,12 +69,12 @@ class SidekiqFailureTest < Raygun::UnitTest
|
|
69
69
|
raise Sidekiq::JobRetry::Handled
|
70
70
|
end
|
71
71
|
|
72
|
-
|
72
|
+
rescue Sidekiq::JobRetry::Handled => e
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
74
|
+
refute Raygun::SidekiqReporter.call(e,
|
75
|
+
{ sidekick_name: "robin" },
|
76
|
+
{} # config
|
77
|
+
)
|
78
78
|
ensure
|
79
79
|
Raygun.configuration.track_retried_sidekiq_jobs = true
|
80
80
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raygun4ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mindscape
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-11-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -67,6 +67,20 @@ dependencies:
|
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: ostruct
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
70
84
|
- !ruby/object:Gem::Dependency
|
71
85
|
name: bundler
|
72
86
|
requirement: !ruby/object:Gem::Requirement
|