airbrake-ruby 4.5.1 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffbab1be170a9aef318ba4f64637e80a8d272c4a
4
- data.tar.gz: c79758680cc22faea98b5d93877a7c46a26949e4
3
+ metadata.gz: cf81123734caec939f2b487e0ca743ea26659f46
4
+ data.tar.gz: ba8e315a20b3f59d0863d027010e54311ba15d9d
5
5
  SHA512:
6
- metadata.gz: 057622e0593896c5acbe522e1e248f37fcbafdf64f7d9cfed980a19bbfa0da07e07e46091d1feaa5a4a42890078f5e4acc99b85cfaea00d7919b3469046f171a
7
- data.tar.gz: 859ab7e7f71ce69259481901f289746ac1cb2148a2690c8134db1cab087935d2e2944d2f821c875b7aeed41cfb0226fcb73399ffe247da373d23a7e5ec3993bd
6
+ metadata.gz: 551704a67996c2064820507d4fb3dd0218df863e7433d77356dd45bc62ecab112508372125a98c8d2f651c2693716e96c86b8e0172ffd265b60de0258d1b7acf
7
+ data.tar.gz: c32da13a83d385bc91b7cc2f236324ae29918005bac9450076d03fc0b707f49b2474049dac7c13fb78f1b0c848c2a1e95579f3c5f1c2315581c8db7d8c1eb3e0
@@ -83,18 +83,24 @@ module Airbrake
83
83
  # @since v2.5.0
84
84
  attr_accessor :code_hunks
85
85
 
86
- # @return [Boolean] true if the library should send performance stats
87
- # information to Airbrake (routes, SQL queries), false otherwise
86
+ # @return [Boolean] true if the library should send route performance stats
87
+ # to Airbrake, false otherwise
88
88
  # @api public
89
89
  # @since v3.2.0
90
90
  attr_accessor :performance_stats
91
91
 
92
92
  # @return [Integer] how many seconds to wait before sending collected route
93
93
  # stats
94
- # @api public
94
+ # @api private
95
95
  # @since v3.2.0
96
96
  attr_accessor :performance_stats_flush_period
97
97
 
98
+ # @return [Boolean] true if the library should send SQL stats to Airbrake,
99
+ # false otherwise
100
+ # @api public
101
+ # @since v4.6.0
102
+ attr_accessor :query_stats
103
+
98
104
  class << self
99
105
  # @return [Config]
100
106
  attr_writer :instance
@@ -132,6 +138,7 @@ module Airbrake
132
138
  self.versions = {}
133
139
  self.performance_stats = true
134
140
  self.performance_stats_flush_period = 15
141
+ self.query_stats = false
135
142
 
136
143
  merge(user_config)
137
144
  end
@@ -197,6 +204,20 @@ module Airbrake
197
204
  check_notify_ability
198
205
  end
199
206
 
207
+ # @return [Promise] resolved promise if neither of the performance options
208
+ # reject it, false otherwise
209
+ def check_performance_options(resource)
210
+ promise = Airbrake::Promise.new
211
+
212
+ if !performance_stats
213
+ promise.reject("The Performance Stats feature is disabled")
214
+ elsif resource.is_a?(Airbrake::Query) && !query_stats
215
+ promise.reject("The Query Stats feature is disabled")
216
+ else
217
+ promise
218
+ end
219
+ end
220
+
200
221
  private
201
222
 
202
223
  def set_option(option, value)
@@ -25,10 +25,8 @@ module Airbrake
25
25
  promise = @config.check_configuration
26
26
  return promise if promise.rejected?
27
27
 
28
- promise = Airbrake::Promise.new
29
- unless @config.performance_stats
30
- return promise.reject("The Performance Stats feature is disabled")
31
- end
28
+ promise = @config.check_performance_options(resource)
29
+ return promise if promise.rejected?
32
30
 
33
31
  @filter_chain.refine(resource)
34
32
  return if resource.ignored?
@@ -2,5 +2,5 @@
2
2
  # More information: http://semver.org/
3
3
  module Airbrake
4
4
  # @return [String] the library version
5
- AIRBRAKE_RUBY_VERSION = '4.5.1'.freeze
5
+ AIRBRAKE_RUBY_VERSION = '4.6.0'.freeze
6
6
  end
@@ -21,6 +21,7 @@ RSpec.describe Airbrake::Config do
21
21
  its(:whitelist_keys) { is_expected.to be_empty }
22
22
  its(:performance_stats) { is_expected.to eq(true) }
23
23
  its(:performance_stats_flush_period) { is_expected.to eq(15) }
24
+ its(:query_stats) { is_expected.to eq(false) }
24
25
 
25
26
  describe "#new" do
26
27
  context "when user config is passed" do
@@ -106,4 +107,48 @@ RSpec.describe Airbrake::Config do
106
107
  its(:check_configuration) { is_expected.not_to be_rejected }
107
108
  end
108
109
  end
110
+
111
+ describe "#check_performance_options" do
112
+ it "returns a promise" do
113
+ resource = Airbrake::Query.new(
114
+ method: '', route: '', query: '', start_time: Time.now
115
+ )
116
+ expect(subject.check_performance_options(resource))
117
+ .to be_an(Airbrake::Promise)
118
+ end
119
+
120
+ context "when performance stats are disabled" do
121
+ before { subject.performance_stats = false }
122
+
123
+ let(:resource) do
124
+ Airbrake::Request.new(
125
+ method: 'GET', route: '/foo', status_code: 200, start_time: Time.new
126
+ )
127
+ end
128
+
129
+ it "returns a rejected promise" do
130
+ promise = subject.check_performance_options(resource)
131
+ expect(promise.value).to eq(
132
+ 'error' => "The Performance Stats feature is disabled"
133
+ )
134
+ end
135
+ end
136
+
137
+ context "when query stats are disabled" do
138
+ before { subject.query_stats = false }
139
+
140
+ let(:resource) do
141
+ Airbrake::Query.new(
142
+ method: 'GET', route: '/foo', query: '', start_time: Time.new
143
+ )
144
+ end
145
+
146
+ it "returns a rejected promise" do
147
+ promise = subject.check_performance_options(resource)
148
+ expect(promise.value).to eq(
149
+ 'error' => "The Query Stats feature is disabled"
150
+ )
151
+ end
152
+ end
153
+ end
109
154
  end
@@ -12,7 +12,8 @@ RSpec.describe Airbrake::PerformanceNotifier do
12
12
  project_id: 1,
13
13
  project_key: 'banana',
14
14
  performance_stats: true,
15
- performance_stats_flush_period: 0
15
+ performance_stats_flush_period: 0,
16
+ query_stats: true
16
17
  )
17
18
  end
18
19
 
@@ -284,34 +285,13 @@ RSpec.describe Airbrake::PerformanceNotifier do
284
285
  expect(promise.value).to eq('' => nil)
285
286
  end
286
287
 
287
- it "doesn't send route stats when performance stats are disabled" do
288
- Airbrake::Config.instance.merge(performance_stats: false)
289
-
290
- promise = subject.notify(
291
- Airbrake::Request.new(
292
- method: 'GET', route: '/foo', status_code: 200, start_time: Time.new
293
- )
288
+ it "checks performance stat configuration" do
289
+ request = Airbrake::Request.new(
290
+ method: 'GET', route: '/foo', status_code: 200, start_time: Time.new
294
291
  )
295
-
296
- expect(a_request(:put, routes)).not_to have_been_made
297
- expect(promise.value).to eq(
298
- 'error' => "The Performance Stats feature is disabled"
299
- )
300
- end
301
-
302
- it "doesn't send route stats when current environment is ignored" do
303
- Airbrake::Config.instance.merge(
304
- performance_stats: true, environment: 'test', ignore_environments: %w[test]
305
- )
306
-
307
- promise = subject.notify(
308
- Airbrake::Request.new(
309
- method: 'GET', route: '/foo', status_code: 200, start_time: Time.new
310
- )
311
- )
312
-
313
- expect(a_request(:put, routes)).not_to have_been_made
314
- expect(promise.value).to eq('error' => "current environment 'test' is ignored")
292
+ expect(Airbrake::Config.instance).to receive(:check_performance_options)
293
+ .with(request).and_return(Airbrake::Promise.new)
294
+ subject.notify(request)
315
295
  end
316
296
 
317
297
  it "sends environment when it's specified" 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.5.1
4
+ version: 4.6.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: 2019-07-29 00:00:00.000000000 Z
11
+ date: 2019-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbtree3