datadog-notifications 0.4.4 → 0.4.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 272c499c77016ad164fc1ab11d9daf1e4fd2030e
4
- data.tar.gz: 453640237e120a83ff833d9b9dc311349e0fa175
3
+ metadata.gz: 48de82448ce774595bad633515891226c23c33d6
4
+ data.tar.gz: 717fdf4a07d04db7d39043d814bf508bcabd44fa
5
5
  SHA512:
6
- metadata.gz: 5d3630229b5be58bc741717488414e57dbb5cbc270b275be3f5717d7a725489d5f087e2391182b798d9c08a4ca116f57691a92d61c8c501c9d04e93424dc5d90
7
- data.tar.gz: c1520297c7612fb23e4e59db32979302e069a91c49f6c9f1a1a15256f5ab91167c8f17f586ce6234ea9030232132253b97d135bd6fee194f1cd3a3233c8116d4
6
+ metadata.gz: d2d93bacaa972855f6776ea639a70294ee3e8258cd55fb8584e1495b13ff8722fc64d9c1168acdbb0897b63f8cf5e2ce4ed29400e5839bca6a809a04e4fb3f48
7
+ data.tar.gz: 7c5ade1127be0fca2f56f622806489bd267e9e4aee2b368f24a7f952d45605def26c0877f2384bd639032ae770636d7c4582980934ce1e9bc56d9682c02b8a6f
data/Gemfile.lock CHANGED
@@ -1,20 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- datadog-notifications (0.4.4)
4
+ datadog-notifications (0.4.5)
5
5
  activesupport
6
6
  dogstatsd-ruby (~> 2.0.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (5.0.1)
12
- activesupport (= 5.0.1)
13
- activerecord (5.0.1)
14
- activemodel (= 5.0.1)
15
- activesupport (= 5.0.1)
11
+ activemodel (5.0.2)
12
+ activesupport (= 5.0.2)
13
+ activerecord (5.0.2)
14
+ activemodel (= 5.0.2)
15
+ activesupport (= 5.0.2)
16
16
  arel (~> 7.0)
17
- activesupport (5.0.1)
17
+ activesupport (5.0.2)
18
18
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
19
  i18n (~> 0.7)
20
20
  minitest (~> 5.1)
@@ -24,16 +24,16 @@ GEM
24
24
  descendants_tracker (~> 0.0.4)
25
25
  ice_nine (~> 0.11.0)
26
26
  thread_safe (~> 0.3, >= 0.3.1)
27
- builder (3.2.2)
27
+ builder (3.2.3)
28
28
  coercible (1.0.0)
29
29
  descendants_tracker (~> 0.0.1)
30
- concurrent-ruby (1.0.4)
30
+ concurrent-ruby (1.0.5)
31
31
  descendants_tracker (0.0.4)
32
32
  thread_safe (~> 0.3, >= 0.3.1)
33
- diff-lcs (1.2.5)
33
+ diff-lcs (1.3)
34
34
  dogstatsd-ruby (2.0.0)
35
35
  equalizer (0.0.11)
36
- grape (0.19.0)
36
+ grape (0.19.1)
37
37
  activesupport
38
38
  builder
39
39
  hashie (>= 2.1.0)
@@ -43,8 +43,8 @@ GEM
43
43
  rack (>= 1.3.0)
44
44
  rack-accept
45
45
  virtus (>= 1.0.0)
46
- hashie (3.4.6)
47
- i18n (0.7.0)
46
+ hashie (3.5.5)
47
+ i18n (0.8.1)
48
48
  ice_nine (0.11.2)
49
49
  minitest (5.10.1)
50
50
  multi_json (1.12.1)
@@ -72,8 +72,8 @@ GEM
72
72
  diff-lcs (>= 1.2.0, < 2.0)
73
73
  rspec-support (~> 3.5.0)
74
74
  rspec-support (3.5.0)
75
- sqlite3 (1.3.12)
76
- thread_safe (0.3.5)
75
+ sqlite3 (1.3.13)
76
+ thread_safe (0.3.6)
77
77
  tool (0.2.3)
78
78
  tzinfo (1.2.2)
79
79
  thread_safe (~> 0.1)
@@ -97,4 +97,4 @@ DEPENDENCIES
97
97
  sqlite3
98
98
 
99
99
  BUNDLED WITH
100
- 1.11.2
100
+ 1.14.5
@@ -1,15 +1,17 @@
1
1
  module Datadog::Notifications::Plugins
2
2
  class Grape < Base
3
3
 
4
- attr_reader :metric_name
4
+ attr_reader :metric_name, :exception_handler
5
5
 
6
6
  # Options:
7
7
  #
8
8
  # *<tt>:metric_name</tt> - the metric name, defaults to "grape.request"
9
+ # *<tt>:exception_handler</tt> - a custom exception handler proc which accepts an exception object and returns a status
9
10
  # *<tt>:tags</tt> - additional tags
10
11
  def initialize(opts = {})
11
12
  super
12
13
  @metric_name = opts[:metric_name] || "grape.request"
14
+ @exception_handler = opts[:exception_handler] || ->_ { 500 }
13
15
 
14
16
  Datadog::Notifications.subscribe 'endpoint_run.grape' do |reporter, event|
15
17
  record reporter, event
@@ -24,6 +26,11 @@ module Datadog::Notifications::Plugins
24
26
  route = endpoint.route
25
27
  version = route.version
26
28
  method = route.request_method
29
+ status = endpoint.status
30
+
31
+ if payload[:exception_object]
32
+ status = exception_handler.call(payload[:exception_object])
33
+ end
27
34
 
28
35
  path = route.pattern.path.dup
29
36
  path.sub!(/\(\.\:format\)$/, '')
@@ -31,7 +38,7 @@ module Datadog::Notifications::Plugins
31
38
  path.gsub!(/:(\w+)/) {|m| m[1..-1].upcase }
32
39
  path.gsub!(/[^\w\/\-]+/, '_')
33
40
 
34
- tags = self.tags + %W|method:#{method} path:#{path} status:#{endpoint.status}|
41
+ tags = self.tags + %W|method:#{method} path:#{path} status:#{status}|
35
42
  tags.push "version:#{version}" if version
36
43
 
37
44
  reporter.batch do
@@ -1,5 +1,5 @@
1
1
  module Datadog
2
2
  class Notifications
3
- VERSION = "0.4.4"
3
+ VERSION = "0.4.5"
4
4
  end
5
5
  end
@@ -4,6 +4,8 @@ describe Datadog::Notifications::Plugins::Grape do
4
4
  include Rack::Test::Methods
5
5
 
6
6
  let(:app) do
7
+ unauthorized = Class.new(RuntimeError)
8
+
7
9
  sub_api = Class.new(Grape::API) do
8
10
  version 'v1'
9
11
  prefix 'api'
@@ -12,10 +14,19 @@ describe Datadog::Notifications::Plugins::Grape do
12
14
  end
13
15
 
14
16
  Class.new(Grape::API) do
17
+
18
+ rescue_from unauthorized do |e|
19
+ error!({ message: "unauthorized", error: '401 Unauthorized' }, 401)
20
+ end
21
+
15
22
  get 'echo/:key1/:key2' do
16
23
  "#{params['key1']} #{params['key2']}"
17
24
  end
18
25
 
26
+ get '/rescued' do
27
+ raise unauthorized.new("unauthorized")
28
+ end
29
+
19
30
  namespace :sub do
20
31
  mount sub_api
21
32
 
@@ -59,4 +70,21 @@ describe Datadog::Notifications::Plugins::Grape do
59
70
  ])
60
71
  end
61
72
 
73
+ it 'should handle rescued errors' do
74
+ get '/rescued'
75
+ expect(last_response.status).to eq(401)
76
+
77
+ expect(buffered).to eq([
78
+ "api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:GET,path:/rescued,status:401",
79
+ "api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,path:/rescued,status:401",
80
+ ])
81
+ end
82
+
83
+ it 'should not report paths on 404s' do
84
+ get '/sub/missing'
85
+ expect(last_response.status).to eq(404)
86
+
87
+ expect(buffered).to eq([])
88
+ end
89
+
62
90
  end
data/spec/spec_helper.rb CHANGED
@@ -62,5 +62,8 @@ Datadog::Notifications.configure do |c|
62
62
  c.tags = ["custom:tag"]
63
63
 
64
64
  c.use Datadog::Notifications::Plugins::ActiveRecord
65
- c.use Datadog::Notifications::Plugins::Grape, tags: ["more:tags"], metric_name: "api.request"
65
+ c.use Datadog::Notifications::Plugins::Grape,
66
+ tags: ["more:tags"],
67
+ metric_name: "api.request",
68
+ exception_handler: ->e { e.message.include?("unauthorized") ? 401 : 500 }
66
69
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datadog-notifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-03 00:00:00.000000000 Z
11
+ date: 2017-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
187
  version: '0'
188
188
  requirements: []
189
189
  rubyforge_project:
190
- rubygems_version: 2.5.1
190
+ rubygems_version: 2.6.8
191
191
  signing_key:
192
192
  specification_version: 4
193
193
  summary: Generic ActiveSupport::Notifications Datadog handler