bugsnag-dogstatsd 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 30450f543e12edb5dc01518fdd3566b5c4ea5dc26271fad082860ec30a31d61e
4
+ data.tar.gz: 7757b16a5a72af22b19d0638f66f2e98e476992cecf80ad786e8bba6648e4861
5
+ SHA512:
6
+ metadata.gz: 196022e34c1fd9a94ee2530725e11257e1da17fb5a81742ab4d3132242e780d251ab2594c16075cce60531b34879a92bbf39292adcb6da1b5852fb8737054a39
7
+ data.tar.gz: b065db8599317bcd248430e72e15da5f22e77c46ef1697176099e2ca07b188839d6284668f9a6a090d6e3271af77df51c2bc0a69ece8e883ef080e9cd53cc922
@@ -0,0 +1,19 @@
1
+ name: Ruby
2
+
3
+ on: [ push, pull_request ]
4
+
5
+ jobs:
6
+ test:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - name: Set up Ruby
13
+ uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.6
16
+ - name: Install dependencies
17
+ run: bundle install
18
+ - name: Run tests
19
+ run: bundle exec rake
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bugsnag-statsd.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2020 FiveGoodFriends Pty Ltd
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Bugsnag::DogStatsd
2
+
3
+ ![Ruby](https://github.com/fivegoodfriends/bugsnag-dogstatsd/workflows/Ruby/badge.svg)
4
+
5
+ Bugsnag middleware that increments a Datadog flavoured Statsd counter for each exception.
6
+
7
+ ## Installation
8
+
9
+ First, this line to your application's Gemfile:
10
+
11
+ gem 'bugsnag-dogstatsd'
12
+
13
+ Then, install your application's dependencies:
14
+
15
+ $ bundle
16
+
17
+ Then, add the bugsnag-dogtatsd middleware when you configure Bugsnag:
18
+
19
+ Bugsnag.configure do |config|
20
+ config.middleware.use Bugsnag::DogStatsd::Builder.new(statsd: $statsd)
21
+ end
22
+
23
+ Finally, when Bugsnag is notified of an exception your Statsd counter will be incremented:
24
+
25
+ "ruby.exception:1|c|#severity:warning"
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bundle` to install dependencies. Then, run `rake test` to run the tests.
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it (https://github.com/fivegoodfriends/bugsnag-dogstatsd/fork)
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the MIT License. See LICENSE.txt.
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.test_files = FileList["test/**/*_test.rb"]
6
+ end
7
+
8
+ task default: :test
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bugsnag/dogstatsd/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bugsnag-dogstatsd"
8
+ spec.version = Bugsnag::DogStatsd::VERSION
9
+ spec.authors = ["Tate Johnson"]
10
+ spec.email = ["tate.johnson@fivegoodfriends.com.au"]
11
+ spec.summary = %q{Bugsnag middleware that increments a Datadog flavoured Statsd counter for each exception.}
12
+ spec.description = %q{Bugsnag middleware that increments a Datadog flavoured Statsd counter for each exception.}
13
+ spec.homepage = "https://github.com/fivegoodfriends/bugsnag-dogstatsd"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "bugsnag", ">= 6.0"
22
+ spec.add_dependency "dogstatsd-ruby", ">= 4.0"
23
+ spec.add_development_dependency "bundler", "~> 2.1"
24
+ spec.add_development_dependency "minitest", "~> 5.0"
25
+ spec.add_development_dependency "rake", "~> 13.0"
26
+ end
@@ -0,0 +1,27 @@
1
+ require_relative "dogstatsd/version"
2
+
3
+ module Bugsnag
4
+ module DogStatsd
5
+ class Builder
6
+ def initialize(options)
7
+ @options = options
8
+ end
9
+
10
+ def new(bugsnag)
11
+ Middleware.new(bugsnag, @options)
12
+ end
13
+ end
14
+
15
+ class Middleware
16
+ def initialize(bugsnag, options)
17
+ @bugsnag = bugsnag
18
+ @statsd = options.fetch(:statsd)
19
+ end
20
+
21
+ def call(report)
22
+ @statsd.increment('ruby.exception', tags: ["severity:#{report.severity}"])
23
+ @bugsnag.call(report)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ module Bugsnag
2
+ module DogStatsd
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,60 @@
1
+ require_relative "../../lib/bugsnag/dogstatsd"
2
+ require "minitest/autorun"
3
+ require "bugsnag"
4
+ require "datadog/statsd"
5
+
6
+ class Bugsnag::DogStatsdTest < Minitest::Test
7
+ class FakeUDPSocket # See https://github.com/DataDog/dogstatsd-ruby/blob/master/spec/support/fake_udp_socket.rb
8
+ def initialize
9
+ @buffer = []
10
+ @error_on_send = nil
11
+ end
12
+
13
+ def send(message, *)
14
+ raise @error_on_send if @error_on_send
15
+ @buffer.push [message]
16
+ end
17
+
18
+ def recv
19
+ @buffer.shift
20
+ end
21
+
22
+ def to_s
23
+ inspect
24
+ end
25
+
26
+ def inspect
27
+ "<FakeUDPSocket: #{@buffer.inspect}>"
28
+ end
29
+
30
+ def error_on_send(err)
31
+ @error_on_send = err
32
+ end
33
+
34
+ def connect(*args)
35
+ end
36
+
37
+ def close
38
+ end
39
+ end
40
+
41
+ def generate_valid_bugsnag_api_key
42
+ (0..32).map { "a" }.join
43
+ end
44
+
45
+ def test_middleware
46
+ socket = FakeUDPSocket.new
47
+ statsd = Datadog::Statsd.new
48
+ statsd.connection.instance_variable_set(:@socket, socket)
49
+
50
+ Bugsnag.configure do |config|
51
+ config.api_key = generate_valid_bugsnag_api_key
52
+ config.delivery_method = :synchronous
53
+ config.release_stage = "production"
54
+ config.middleware.use Bugsnag::DogStatsd::Builder.new(statsd: statsd)
55
+ end
56
+ Bugsnag.notify(StandardError.new)
57
+
58
+ assert_equal ["ruby.exception:1|c|#severity:warning"], socket.recv
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bugsnag-dogstatsd
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tate Johnson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bugsnag
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dogstatsd-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '13.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '13.0'
83
+ description: Bugsnag middleware that increments a Datadog flavoured Statsd counter
84
+ for each exception.
85
+ email:
86
+ - tate.johnson@fivegoodfriends.com.au
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".github/workflows/ruby.yml"
92
+ - ".gitignore"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bugsnag-statsd.gemspec
98
+ - lib/bugsnag/dogstatsd.rb
99
+ - lib/bugsnag/dogstatsd/version.rb
100
+ - test/bugsnag/dogstatsd_test.rb
101
+ homepage: https://github.com/fivegoodfriends/bugsnag-dogstatsd
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubygems_version: 3.0.3
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Bugsnag middleware that increments a Datadog flavoured Statsd counter for
124
+ each exception.
125
+ test_files:
126
+ - test/bugsnag/dogstatsd_test.rb