airbrake-ruby 3.0.0.rc.8 → 3.0.0.rc.9

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: 69c06924329d27b11545cd91cfd49754c866c26c
4
- data.tar.gz: 21cdca47905867c45562f9459f190221d43d6632
3
+ metadata.gz: 5f8f0a23f9d134d54cd586ca311b27cf82d0c3e8
4
+ data.tar.gz: 06d0f6fbf5b7f7809b0df03806e9991c564eb018
5
5
  SHA512:
6
- metadata.gz: 4c1ef75e369d21f7c6336cbe10b7dc038d67e73a62f53ae315cdf78b51a372f063f99513132776122edf352f3b695cba579a34505558ca94117528bbb78bd6cd
7
- data.tar.gz: 608e533648034f9ee88350a875956d2e800e180b73e4dc6d16e8a3e846c273c0246455c6cd89f1f2f3d9cb3ca355f7c4a233271a88fa0a55693d0ccccbfc0580
6
+ metadata.gz: c9a326402201a26169bd1c65d36e049ebbfdb5ebf27c314e8dd803e30da89366ac0e8e897cebddf6112fdb751fabc6421e0e4aafea8bf65b5201672aaf731b8c
7
+ data.tar.gz: 4648f252843e74ad697e519769126acdc3d007ea00316eaf694c7a672c3ffff87272d0e1278e80d7ccd7dca828834104c93e2b179064d462a3c3e3a1652b9f94
@@ -83,6 +83,12 @@ 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 route stats information
87
+ # to Airbrake, false otherwise
88
+ # @api public
89
+ # @since v3.0.0
90
+ attr_accessor :route_stats
91
+
86
92
  # @return [Integer] how many seconds to wait before sending collected route
87
93
  # stats
88
94
  # @api public
@@ -91,6 +97,7 @@ module Airbrake
91
97
 
92
98
  # @param [Hash{Symbol=>Object}] user_config the hash to be used to build the
93
99
  # config
100
+ # rubocop:disable Metrics/AbcSize
94
101
  def initialize(user_config = {})
95
102
  @validator = Config::Validator.new(self)
96
103
 
@@ -119,10 +126,12 @@ module Airbrake
119
126
  )
120
127
 
121
128
  self.versions = {}
129
+ self.route_stats = true
122
130
  self.route_stats_flush_period = 15
123
131
 
124
132
  merge(user_config)
125
133
  end
134
+ # rubocop:enable Metrics/AbcSize
126
135
 
127
136
  # The full URL to the Airbrake Notice API. Based on the +:host+ option.
128
137
  # @return [URI] the endpoint address
@@ -1,3 +1,5 @@
1
+ require 'date'
2
+
1
3
  module Airbrake
2
4
  module Filters
3
5
  # Attaches git checkout info to `context`. The info includes:
@@ -101,7 +101,17 @@ module Airbrake
101
101
 
102
102
  # @macro see_public_api_method
103
103
  def notify_request(request_info)
104
- @route_sender.notify_request(request_info)
104
+ promise = Airbrake::Promise.new
105
+
106
+ if @config.ignored_environment?
107
+ return promise.reject("The '#{@config.environment}' environment is ignored")
108
+ end
109
+
110
+ unless @config.route_stats
111
+ return promise.reject("The Route Stats feature is disabled")
112
+ end
113
+
114
+ @route_sender.notify_request(request_info, promise)
105
115
  end
106
116
 
107
117
  # @return [String] customized inspect to lessen the amount of clutter
@@ -49,7 +49,7 @@ module Airbrake
49
49
  using TDigestBigEndianness
50
50
 
51
51
  # The key that represents a route.
52
- RouteKey = Struct.new(:method, :route, :status_code, :time)
52
+ RouteKey = Struct.new(:method, :route, :statusCode, :time)
53
53
 
54
54
  # RouteStat holds data that describes a route's performance.
55
55
  RouteStat = Struct.new(:count, :sum, :sumsq, :tdigest) do
@@ -87,14 +87,14 @@ module Airbrake
87
87
  end
88
88
 
89
89
  # @macro see_public_api_method
90
- def notify_request(request_info)
90
+ # @param [Airbrake::Promise] promise
91
+ def notify_request(request_info, promise = Airbrake::Promise.new)
91
92
  route = create_route_key(
92
93
  request_info[:method],
93
94
  request_info[:route],
94
95
  request_info[:status_code],
95
96
  utc_truncate_minutes(request_info[:start_time])
96
97
  )
97
- promise = Airbrake::Promise.new
98
98
 
99
99
  @mutex.synchronize do
100
100
  @routes[route] ||= RouteStat.new
@@ -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 = '3.0.0.rc.8'.freeze
5
+ AIRBRAKE_RUBY_VERSION = '3.0.0.rc.9'.freeze
6
6
  end
data/spec/config_spec.rb CHANGED
@@ -79,6 +79,10 @@ RSpec.describe Airbrake::Config do
79
79
  expect(config.whitelist_keys).to be_empty
80
80
  end
81
81
 
82
+ it "enables route stats by default" do
83
+ expect(config.route_stats).to be_truthy
84
+ end
85
+
82
86
  it "sets the default route_stats_flush_period" do
83
87
  expect(config.route_stats_flush_period).to eq(15)
84
88
  end
@@ -32,7 +32,9 @@ RSpec.describe Airbrake::Filters::GitLastCheckoutFilter do
32
32
  end
33
33
 
34
34
  it "attaches last checkouted email" do
35
- expect(notice[:context][:lastCheckout][:email]).to match(/\A\w+@\w+\.?\w+?\z/)
35
+ expect(notice[:context][:lastCheckout][:email]).to(
36
+ match(/\A\w+[\w.-]*@\w+\.?\w+?\z/)
37
+ )
36
38
  end
37
39
 
38
40
  it "attaches last checkouted revision" do
@@ -451,18 +451,41 @@ RSpec.describe Airbrake::Notifier do
451
451
  end
452
452
 
453
453
  describe "#notify_request" do
454
- it "forwards 'notify_request' to RouteSender" do
455
- params = {
454
+ let(:params) do
455
+ {
456
456
  method: 'GET',
457
457
  route: '/foo',
458
458
  status_code: 200,
459
459
  start_time: Time.new(2018, 1, 1, 0, 20, 0, 0),
460
460
  end_time: Time.new(2018, 1, 1, 0, 19, 0, 0)
461
461
  }
462
+ end
463
+
464
+ it "forwards 'notify_request' to RouteSender" do
462
465
  expect_any_instance_of(Airbrake::RouteSender)
463
- .to receive(:notify_request).with(params)
466
+ .to receive(:notify_request).with(params, instance_of(Airbrake::Promise))
464
467
  subject.notify_request(params)
465
468
  end
469
+
470
+ context "when route stats are disabled" do
471
+ it "doesn't send route stats" do
472
+ notifier = described_class.new(user_params.merge(route_stats: false))
473
+ expect_any_instance_of(Airbrake::RouteSender)
474
+ .not_to receive(:notify_request)
475
+ notifier.notify_request(params)
476
+ end
477
+ end
478
+
479
+ context "when current environment is ignored" do
480
+ it "doesn't send route stats" do
481
+ notifier = described_class.new(
482
+ user_params.merge(environment: 'test', ignore_environments: %w[test])
483
+ )
484
+ expect_any_instance_of(Airbrake::RouteSender)
485
+ .not_to receive(:notify_request)
486
+ notifier.notify_request(params)
487
+ end
488
+ end
466
489
  end
467
490
 
468
491
  describe "#inspect" do
@@ -73,10 +73,10 @@ RSpec.describe Airbrake::RouteSender do
73
73
  a_request(:put, endpoint).with(
74
74
  body: %r|\A
75
75
  {"routes":\[
76
- {"method":"GET","route":"/foo","status_code":200,
76
+ {"method":"GET","route":"/foo","statusCode":200,
77
77
  "time":"2018-01-01T00:00:00\+00:00","count":1,"sum":1000.0,
78
78
  "sumsq":1000000.0,"tdigest":"AAAAAkA0AAAAAAAAAAAAAUR6AAAB"},
79
- {"method":"GET","route":"/foo","status_code":200,
79
+ {"method":"GET","route":"/foo","statusCode":200,
80
80
  "time":"2018-01-01T00:01:00\+00:00","count":1,"sum":6000.0,
81
81
  "sumsq":36000000.0,"tdigest":"AAAAAkA0AAAAAAAAAAAAAUW7gAAB"}\]}
82
82
  \z|x
@@ -104,10 +104,10 @@ RSpec.describe Airbrake::RouteSender do
104
104
  a_request(:put, endpoint).with(
105
105
  body: %r|\A
106
106
  {"routes":\[
107
- {"method":"GET","route":"/foo","status_code":200,
107
+ {"method":"GET","route":"/foo","statusCode":200,
108
108
  "time":"2018-01-01T00:49:00\+00:00","count":1,"sum":60000.0,
109
109
  "sumsq":3600000000.0,"tdigest":"AAAAAkA0AAAAAAAAAAAAAUdqYAAB"},
110
- {"method":"POST","route":"/foo","status_code":200,
110
+ {"method":"POST","route":"/foo","statusCode":200,
111
111
  "time":"2018-01-01T00:49:00\+00:00","count":1,"sum":60000.0,
112
112
  "sumsq":3600000000.0,"tdigest":"AAAAAkA0AAAAAAAAAAAAAUdqYAAB"}\]}
113
113
  \z|x
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: 3.0.0.rc.8
4
+ version: 3.0.0.rc.9
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: 2018-11-21 00:00:00.000000000 Z
11
+ date: 2018-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tdigest