airbrake-ruby 1.8.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/airbrake-ruby.rb +16 -57
- data/lib/airbrake-ruby/backtrace.rb +8 -2
- data/lib/airbrake-ruby/config.rb +2 -2
- data/lib/airbrake-ruby/notice.rb +4 -22
- data/lib/airbrake-ruby/promise.rb +3 -1
- data/lib/airbrake-ruby/version.rb +1 -1
- data/spec/airbrake_spec.rb +0 -45
- data/spec/backtrace_spec.rb +26 -0
- data/spec/config_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abc8e8ee3aac5103d60b365927bb65426a3118d4
|
4
|
+
data.tar.gz: 3b6721865f222b5dc2fd26c4456de385a0761ddf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54a86bed42a190518bf82281abb3354fc74b951ffde54cc9b83c796c0d0cd8c8960bac7e1a635b614c6eebc8b985495646006c0ccfde4ed0f2df2221ba2c31c9
|
7
|
+
data.tar.gz: 20e077993ec39e48f2d548b5978f4815a181bd1ca51e23b88054d1f4d249dabfc5cb0247d9b9a5efb3800b2a6397d91b33865e0379548ae745d18356a56eab09
|
data/lib/airbrake-ruby.rb
CHANGED
@@ -115,26 +115,20 @@ module Airbrake
|
|
115
115
|
# existing notifier
|
116
116
|
# @note There's no way to reconfigure a notifier
|
117
117
|
# @note There's no way to read config values outside of this library
|
118
|
-
def configure(
|
118
|
+
def configure(notifier_name = :default)
|
119
119
|
yield config = Airbrake::Config.new
|
120
120
|
|
121
|
-
if
|
121
|
+
if @notifiers.key?(notifier_name)
|
122
122
|
raise Airbrake::Error,
|
123
|
-
"the '#{
|
123
|
+
"the '#{notifier_name}' notifier was already configured"
|
124
124
|
else
|
125
|
-
@notifiers[
|
125
|
+
@notifiers[notifier_name] = Notifier.new(config)
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
-
# @!macro proxy_method
|
130
|
-
# @param [Symbol] notifier The name of the notifier
|
131
|
-
# @raise [Airbrake::Error] if +notifier+ doesn't exist
|
132
|
-
# @see Airbrake::Notifier#$0
|
133
|
-
|
134
129
|
##
|
135
130
|
# Sends an exception to Airbrake asynchronously.
|
136
131
|
#
|
137
|
-
# @macro proxy_method
|
138
132
|
# @example Sending an exception
|
139
133
|
# Airbrake.notify(RuntimeError.new('Oops!'))
|
140
134
|
# @example Sending a string
|
@@ -151,24 +145,21 @@ module Airbrake
|
|
151
145
|
# tab in your project's dashboard
|
152
146
|
# @return [Airbrake::Promise]
|
153
147
|
# @see .notify_sync
|
154
|
-
def notify(exception, params = {}
|
155
|
-
|
156
|
-
call_notifier(notifier, __method__, exception, params)
|
148
|
+
def notify(exception, params = {})
|
149
|
+
@notifiers[:default] && @notifiers[:default].notify(exception, params)
|
157
150
|
end
|
158
151
|
|
159
152
|
##
|
160
153
|
# Sends an exception to Airbrake synchronously.
|
161
154
|
#
|
162
|
-
# @macro proxy_method
|
163
155
|
# @example
|
164
156
|
# Airbrake.notify_sync('App crashed!')
|
165
157
|
# #=> {"id"=>"123", "url"=>"https://airbrake.io/locate/321"}
|
166
158
|
#
|
167
159
|
# @return [Hash{String=>String}] the reponse from the server
|
168
160
|
# @see .notify
|
169
|
-
def notify_sync(exception, params = {}
|
170
|
-
|
171
|
-
call_notifier(notifier, __method__, exception, params)
|
161
|
+
def notify_sync(exception, params = {})
|
162
|
+
@notifiers[:default] && @notifiers[:default].notify_sync(exception, params)
|
172
163
|
end
|
173
164
|
|
174
165
|
##
|
@@ -176,7 +167,6 @@ module Airbrake
|
|
176
167
|
# useful if you want to ignore specific notices or filter the data the
|
177
168
|
# notice contains.
|
178
169
|
#
|
179
|
-
# @macro proxy_method
|
180
170
|
# @example Ignore all notices
|
181
171
|
# Airbrake.add_filter(&:ignore!)
|
182
172
|
# @example Ignore based on some condition
|
@@ -198,9 +188,8 @@ module Airbrake
|
|
198
188
|
# @yieldreturn [void]
|
199
189
|
# @return [void]
|
200
190
|
# @note Once a filter was added, there's no way to delete it
|
201
|
-
def add_filter(filter = nil,
|
202
|
-
|
203
|
-
call_notifier(notifier, __method__, filter, &block)
|
191
|
+
def add_filter(filter = nil, &block)
|
192
|
+
@notifiers[:default] && @notifiers[:default].add_filter(filter, &block)
|
204
193
|
end
|
205
194
|
|
206
195
|
##
|
@@ -208,7 +197,6 @@ module Airbrake
|
|
208
197
|
# value only for a specific notice. When you're done modifying the notice,
|
209
198
|
# send it with {.notify} or {.notify_sync}.
|
210
199
|
#
|
211
|
-
# @macro proxy_method
|
212
200
|
# @example
|
213
201
|
# notice = airbrake.build_notice('App crashed!')
|
214
202
|
# notice[:params][:username] = user.name
|
@@ -219,9 +207,8 @@ module Airbrake
|
|
219
207
|
# @param [Hash] params The additional params attached to the notice
|
220
208
|
# @return [Airbrake::Notice] the notice built with help of the given
|
221
209
|
# arguments
|
222
|
-
def build_notice(exception, params = {}
|
223
|
-
|
224
|
-
call_notifier(notifier, __method__, exception, params)
|
210
|
+
def build_notice(exception, params = {})
|
211
|
+
@notifiers[:default] && @notifiers[:default].build_notice(exception, params)
|
225
212
|
end
|
226
213
|
|
227
214
|
##
|
@@ -229,22 +216,19 @@ module Airbrake
|
|
229
216
|
# {.notify_sync} methods anymore. It also stops the notifier's worker
|
230
217
|
# threads.
|
231
218
|
#
|
232
|
-
# @macro proxy_method
|
233
219
|
# @example
|
234
220
|
# Airbrake.close
|
235
221
|
# Airbrake.notify('App crashed!') #=> raises Airbrake::Error
|
236
222
|
#
|
237
223
|
# @return [void]
|
238
|
-
def close
|
239
|
-
|
240
|
-
call_notifier(notifier, __method__)
|
224
|
+
def close
|
225
|
+
@notifiers[:default] && @notifiers[:default].close
|
241
226
|
end
|
242
227
|
|
243
228
|
##
|
244
229
|
# Pings the Airbrake Deploy API endpoint about the occurred deploy. This
|
245
230
|
# method is used by the airbrake gem for various integrations.
|
246
231
|
#
|
247
|
-
# @macro proxy_method
|
248
232
|
# @param [Hash{Symbol=>String}] deploy_params The params for the API
|
249
233
|
# @option deploy_params [Symbol] :environment
|
250
234
|
# @option deploy_params [Symbol] :username
|
@@ -252,33 +236,8 @@ module Airbrake
|
|
252
236
|
# @option deploy_params [Symbol] :revision
|
253
237
|
# @option deploy_params [Symbol] :version
|
254
238
|
# @return [void]
|
255
|
-
def create_deploy(deploy_params
|
256
|
-
|
257
|
-
call_notifier(notifier, __method__, deploy_params)
|
258
|
-
end
|
259
|
-
|
260
|
-
private
|
261
|
-
|
262
|
-
##
|
263
|
-
# Calls +method+ on +notifier+ with provided +args+. If +notifier+ is not
|
264
|
-
# configured, returns nil.
|
265
|
-
def call_notifier(notifier, method, *args, &block)
|
266
|
-
return unless configured?(notifier)
|
267
|
-
@notifiers[notifier].__send__(method, *args, &block)
|
268
|
-
end
|
269
|
-
|
270
|
-
def configured?(notifier)
|
271
|
-
@notifiers.key?(notifier)
|
272
|
-
end
|
273
|
-
|
274
|
-
def deprecation_warn(method, notifier)
|
275
|
-
warn(
|
276
|
-
"#{LOG_LABEL} `Airbrake.#{method}` method signature was changed. " \
|
277
|
-
"Passing `notifier_name` is deprecated and will be removed in the " \
|
278
|
-
"next MAJOR release.\n" \
|
279
|
-
"Use `Airbrake[:#{notifier}]` to access the :#{notifier} notifier " \
|
280
|
-
"and call same methods directly on it."
|
281
|
-
)
|
239
|
+
def create_deploy(deploy_params)
|
240
|
+
@notifiers[:default] && @notifiers[:default].create_deploy(deploy_params)
|
282
241
|
end
|
283
242
|
end
|
284
243
|
end
|
@@ -128,8 +128,14 @@ module Airbrake
|
|
128
128
|
# @param [Exception] exception
|
129
129
|
# @return [Boolean]
|
130
130
|
def self.java_exception?(exception)
|
131
|
-
defined?(Java::JavaLang::Throwable) &&
|
132
|
-
|
131
|
+
if defined?(Java::JavaLang::Throwable) &&
|
132
|
+
exception.is_a?(Java::JavaLang::Throwable)
|
133
|
+
return true
|
134
|
+
end
|
135
|
+
|
136
|
+
return false unless exception.respond_to?(:backtrace)
|
137
|
+
|
138
|
+
(Patterns::JAVA =~ exception.backtrace.first) != nil
|
133
139
|
end
|
134
140
|
|
135
141
|
class << self
|
data/lib/airbrake-ruby/config.rb
CHANGED
@@ -96,9 +96,9 @@ module Airbrake
|
|
96
96
|
self.blacklist_keys = []
|
97
97
|
self.whitelist_keys = []
|
98
98
|
|
99
|
-
self.root_directory = (
|
99
|
+
self.root_directory = File.realpath(
|
100
100
|
(defined?(Bundler) && Bundler.root) ||
|
101
|
-
|
101
|
+
Dir.pwd
|
102
102
|
)
|
103
103
|
|
104
104
|
merge(user_config)
|
data/lib/airbrake-ruby/notice.rb
CHANGED
@@ -67,7 +67,7 @@ module Airbrake
|
|
67
67
|
|
68
68
|
@payload = {
|
69
69
|
errors: NestedException.new(exception, @config.logger).as_json,
|
70
|
-
context: context
|
70
|
+
context: context,
|
71
71
|
environment: {},
|
72
72
|
session: {},
|
73
73
|
params: params
|
@@ -148,19 +148,8 @@ module Airbrake
|
|
148
148
|
|
149
149
|
private
|
150
150
|
|
151
|
-
def context
|
152
|
-
|
153
|
-
if params.key?(:component) || params.key?(:action)
|
154
|
-
@config.logger.warn(
|
155
|
-
"#{LOG_LABEL} passing component/action keys in the params hash is " \
|
156
|
-
"deprecated and will be removed soon. Please update your code to use " \
|
157
|
-
"`Airbrake.build_notice` and set these keys like this:\n" \
|
158
|
-
" notice[:context][:component] = 'mycomponent'\n" \
|
159
|
-
" notice[:context][:action] = 'myaction'"
|
160
|
-
)
|
161
|
-
end
|
162
|
-
|
163
|
-
ctx = {
|
151
|
+
def context
|
152
|
+
{
|
164
153
|
version: @config.app_version,
|
165
154
|
# We ensure that root_directory is always a String, so it can always be
|
166
155
|
# converted to JSON in a predictable manner (when it's a Pathname and in
|
@@ -168,16 +157,9 @@ module Airbrake
|
|
168
157
|
rootDirectory: @config.root_directory.to_s,
|
169
158
|
environment: @config.environment,
|
170
159
|
|
171
|
-
# DEPRECATION: remove the following code in the next MINOR release.
|
172
|
-
# Legacy Airbrake v4 behaviour.
|
173
|
-
component: params.delete(:component),
|
174
|
-
action: params.delete(:action),
|
175
|
-
|
176
160
|
# Make sure we always send hostname.
|
177
161
|
hostname: HOSTNAME
|
178
|
-
}
|
179
|
-
|
180
|
-
ctx.merge(CONTEXT).delete_if { |_key, val| val.nil? || val.empty? }
|
162
|
+
}.merge(CONTEXT).delete_if { |_key, val| val.nil? || val.empty? }
|
181
163
|
end
|
182
164
|
|
183
165
|
def raise_if_ignored
|
@@ -9,8 +9,10 @@ module Airbrake
|
|
9
9
|
# @since v1.7.0
|
10
10
|
class Promise
|
11
11
|
##
|
12
|
+
# @api private
|
12
13
|
# @return [Hash<String,String>] either successful response containing the
|
13
|
-
#
|
14
|
+
# +id+ key or unsuccessful response containing the +error+ key
|
15
|
+
# @note This is a non-blocking call!
|
14
16
|
attr_reader :value
|
15
17
|
|
16
18
|
def initialize
|
data/spec/airbrake_spec.rb
CHANGED
@@ -45,31 +45,6 @@ RSpec.describe Airbrake do
|
|
45
45
|
expect(a_request(:post, endpoint)).to have_been_made.once
|
46
46
|
end
|
47
47
|
|
48
|
-
context "given the notifier argument" do
|
49
|
-
it "sends exceptions via that notifier, ignoring other ones" do
|
50
|
-
bingo_string = StringIO.new
|
51
|
-
bango_string = StringIO.new
|
52
|
-
|
53
|
-
described_class.configure(:bingo) do |c|
|
54
|
-
c.project_id = 113743
|
55
|
-
c.project_key = 'fd04e13d806a90f96614ad8e529b2822'
|
56
|
-
c.logger = Logger.new(bingo_string)
|
57
|
-
end
|
58
|
-
|
59
|
-
described_class.configure(:bango) do |c|
|
60
|
-
c.project_id = 113743
|
61
|
-
c.project_key = 'fd04e13d806a90f96614ad8e529b2822'
|
62
|
-
c.logger = Logger.new(bango_string)
|
63
|
-
end
|
64
|
-
|
65
|
-
stub_request(:post, endpoint).to_return(status: 201, body: '{"id":1}')
|
66
|
-
|
67
|
-
described_class.notify_sync('bango', {}, :bango)
|
68
|
-
expect(bingo_string.string).to be_empty
|
69
|
-
expect(bango_string.string).to match(/\*\*Airbrake: {"id"=>1}/)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
48
|
describe "clean backtrace" do
|
74
49
|
shared_examples 'backtrace building' do |msg, argument|
|
75
50
|
it(msg) do
|
@@ -106,26 +81,6 @@ RSpec.describe Airbrake do
|
|
106
81
|
)
|
107
82
|
end
|
108
83
|
end
|
109
|
-
|
110
|
-
context "special params" do
|
111
|
-
it "sends context/component and doesn't contain params/component" do
|
112
|
-
described_class.notify_sync('bingo', component: 'bango')
|
113
|
-
|
114
|
-
expect(
|
115
|
-
a_request(:post, endpoint).
|
116
|
-
with(body: /"context":{.*"component":"bango".+"params":{}/)
|
117
|
-
).to have_been_made.once
|
118
|
-
end
|
119
|
-
|
120
|
-
it "sends context/action and doesn't contain params/action" do
|
121
|
-
described_class.notify_sync('bingo', action: 'bango')
|
122
|
-
|
123
|
-
expect(
|
124
|
-
a_request(:post, endpoint).
|
125
|
-
with(body: /"context":{.*"action":"bango".+"params":{}/)
|
126
|
-
).to have_been_made.once
|
127
|
-
end
|
128
|
-
end
|
129
84
|
end
|
130
85
|
|
131
86
|
describe ".configure" do
|
data/spec/backtrace_spec.rb
CHANGED
@@ -106,6 +106,32 @@ RSpec.describe Airbrake::Backtrace do
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
+
context "JRuby non-throwable exceptions" do
|
110
|
+
let(:backtrace) do
|
111
|
+
# rubocop:disable Metrics/LineLength
|
112
|
+
['org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(org/postgresql/core/v3/ConnectionFactoryImpl.java:257)',
|
113
|
+
'org.postgresql.core.ConnectionFactory.openConnection(org/postgresql/core/ConnectionFactory.java:65)',
|
114
|
+
'org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(org/postgresql/jdbc2/AbstractJdbc2Connection.java:149)']
|
115
|
+
# rubocop:enable Metrics/LineLength
|
116
|
+
end
|
117
|
+
|
118
|
+
let(:parsed_backtrace) do
|
119
|
+
# rubocop:disable Metrics/LineLength
|
120
|
+
[{ file: 'org/postgresql/core/v3/ConnectionFactoryImpl.java', line: 257, function: 'org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl' },
|
121
|
+
{ file: 'org/postgresql/core/ConnectionFactory.java', line: 65, function: 'org.postgresql.core.ConnectionFactory.openConnection' },
|
122
|
+
{ file: 'org/postgresql/jdbc2/AbstractJdbc2Connection.java', line: 149, function: 'org.postgresql.jdbc2.AbstractJdbc2Connection.<init>' }]
|
123
|
+
# rubocop:enable Metrics/LineLength
|
124
|
+
end
|
125
|
+
|
126
|
+
let(:ex) { AirbrakeTestError.new.tap { |e| e.set_backtrace(backtrace) } }
|
127
|
+
|
128
|
+
it "returns a properly formatted array of hashes" do
|
129
|
+
expect(
|
130
|
+
described_class.parse(ex, Logger.new('/dev/null'))
|
131
|
+
).to eq(parsed_backtrace)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
109
135
|
context "generic backtrace" do
|
110
136
|
context "when function is absent" do
|
111
137
|
# rubocop:disable Metrics/LineLength
|
data/spec/config_spec.rb
CHANGED
@@ -52,7 +52,7 @@ RSpec.describe Airbrake::Config do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
it "sets the default root_directory" do
|
55
|
-
expect(config.root_directory).to eq Bundler.root
|
55
|
+
expect(config.root_directory).to eq Bundler.root.realpath.to_s
|
56
56
|
end
|
57
57
|
|
58
58
|
it "doesn't set the default environment" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: airbrake-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Airbrake Technologies, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|