airbrake-statsd 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby-18mode
7
+ - jruby-19mode
8
+ - rbx-18mode
9
+ - ree
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in airbrake-statsd.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # Airbrake-Statsd
2
+
3
+ [![Build Status](https://secure.travis-ci.org/jimeh/airbrake-statsd.png)](http://travis-ci.org/jimeh/airbrake-statsd)
4
+
5
+ Extends the [Airbrake][] gem to also report exceptions Esty's [Statsd][]
6
+ statistics aggregator.
7
+
8
+ ## Installation
9
+
10
+ gem install airbrake-statsd
11
+
12
+ ## Usage
13
+
14
+ It's assumed you know what both Airbrake and StatsD are before attempting to
15
+ use this gem. If you don't, come back when you do know :)
16
+
17
+ All that's needed is to require `airbrake-statsd` and call
18
+ `Airbrake::Statsd.configure` and Airbrake notifications will automatically be
19
+ sent to StatsD and Airbrake.
20
+
21
+ ```ruby
22
+ require 'airbrake'
23
+ require 'airbrake-statsd'
24
+
25
+ Airbrake::Statsd.configure do |config|
26
+ config.host = 'my-statsd-server'
27
+ config.port = 8125
28
+ config.namespace = 'my_awesome_app'
29
+ end
30
+
31
+ Airbrake.notify({})
32
+ ```
33
+
34
+ ## Credit & Thanks
35
+
36
+ * [Global Personals][gp] for hosting a hack day.
37
+
38
+ ## License and Copyright
39
+
40
+ Copyright (c) 2012 Jim Myhrberg & Global Personals, Ltd.
41
+
42
+ Permission is hereby granted, free of charge, to any person obtaining
43
+ a copy of this software and associated documentation files (the
44
+ "Software"), to deal in the Software without restriction, including
45
+ without limitation the rights to use, copy, modify, merge, publish,
46
+ distribute, sublicense, and/or sell copies of the Software, and to
47
+ permit persons to whom the Software is furnished to do so, subject to
48
+ the following conditions:
49
+
50
+ The above copyright notice and this permission notice shall be
51
+ included in all copies or substantial portions of the Software.
52
+
53
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
54
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
55
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
56
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
57
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
58
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
59
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
60
+
61
+
62
+ [airbrake]: http://airbrake.io/
63
+ [statsd]: https://github.com/etsy/statsd
64
+ [gp]: http://globalpersonals.co.uk/
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ # Default task
5
+ task :default => 'spec'
6
+
7
+ # Rspec
8
+ require "rspec/core/rake_task"
9
+
10
+ RSpec::Core::RakeTask.new(:spec)
11
+
12
+ namespace :spec do
13
+ RSpec::Core::RakeTask.new(:integration) do |spec|
14
+ spec.pattern = 'spec/integration/**/*_spec.rb'
15
+ end
16
+
17
+ RSpec::Core::RakeTask.new(:unit) do |spec|
18
+ spec.pattern = 'spec/unit/**/*_spec.rb'
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/airbrake-statsd/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ['Jim Myhrberg']
6
+ gem.email = ['contact@jimeh.me']
7
+ gem.description = 'Increment an exception counter in StatsD whenever ' +
8
+ 'the Airbrake gem reports and exception.'
9
+ gem.summary = 'Increment an exception counter in StatsD whenever ' +
10
+ 'the Airbrake gem reports and exception.'
11
+ gem.homepage = 'http://github.com/jimeh/airbrake-statsd'
12
+
13
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ gem.name = 'airbrake-statsd'
17
+ gem.require_paths = ['lib']
18
+ gem.version = Airbrake::Statsd::VERSION
19
+
20
+ gem.add_development_dependency 'rake'
21
+ gem.add_development_dependency 'rspec'
22
+ gem.add_development_dependency 'simplecov'
23
+
24
+ gem.add_runtime_dependency 'airbrake'
25
+ gem.add_runtime_dependency 'statsd-ruby'
26
+ end
@@ -0,0 +1,21 @@
1
+ module Airbrake
2
+ class << self
3
+
4
+ def notify_with_statds(*args)
5
+ Airbrake::Statsd.increment
6
+ notify_without_statsd(*args)
7
+ end
8
+
9
+ alias :notify_without_statsd :notify
10
+ alias :notify :notify_with_statds
11
+
12
+ def notify_or_ignore_with_statsd(*args)
13
+ Airbrake::Statsd.increment
14
+ notify_or_ignore_without_statsd(*args)
15
+ end
16
+
17
+ alias :notify_or_ignore_without_statsd :notify_or_ignore
18
+ alias :notify_or_ignore :notify_or_ignore_with_statsd
19
+
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ module Airbrake
2
+ module Statsd
3
+ class Configuration
4
+
5
+ attr_accessor :namespace
6
+
7
+ def host
8
+ @host ||= 'localhost'
9
+ end
10
+ attr_writer :host
11
+
12
+ def port
13
+ @port ||= 8125
14
+ end
15
+ attr_writer :port
16
+
17
+ end # Configuration
18
+ end # Statsd
19
+ end # Airbrake
@@ -0,0 +1,5 @@
1
+ module Airbrake
2
+ module Statsd
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,40 @@
1
+ require 'airbrake'
2
+ require 'statsd'
3
+
4
+ require 'airbrake-statsd/version'
5
+ require 'airbrake-statsd/configuration'
6
+ require 'airbrake-statsd/airbrake_ext'
7
+
8
+ module Airbrake
9
+ module Statsd
10
+ class << self
11
+
12
+ def configure(&block)
13
+ @configured = true
14
+ block.call(config) if block_given?
15
+ end
16
+
17
+ def configured?
18
+ !!@configured
19
+ end
20
+
21
+ def config
22
+ @config ||= Configuration.new
23
+ end
24
+
25
+ def client
26
+ @client ||= begin
27
+ client = ::Statsd.new(config.host, config.port)
28
+ client.namespace = config.namespace if config.namespace
29
+ client
30
+ end
31
+ end
32
+
33
+ def increment
34
+ return unless configured?
35
+ client.increment('exceptions')
36
+ end
37
+
38
+ end # << self
39
+ end # Statsd
40
+ end # Airbrake
@@ -0,0 +1,10 @@
1
+ require 'rspec'
2
+ require 'rspec/autorun'
3
+
4
+ require 'simplecov'
5
+ SimpleCov.start do
6
+ add_filter 'spec'
7
+ add_filter 'vendor'
8
+ end
9
+
10
+ require 'airbrake-statsd'
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe Airbrake do
4
+
5
+ subject { Airbrake }
6
+
7
+ it '#notify is an alias to #notify_with_statsd' do
8
+ subject.method(:notify).should == subject.method(:notify_with_statds)
9
+ end
10
+
11
+ it '#notify_or_ignore is an alias to #notify_or_ignore_with_statsd' do
12
+ subject.method(:notify_or_ignore).
13
+ should == subject.method(:notify_or_ignore_with_statsd)
14
+ end
15
+
16
+ describe '#notify_without_statsd' do
17
+ it 'does not call Airbrake::Statsd.increment' do
18
+ Airbrake.stub(:send_notice).and_return(nil)
19
+
20
+ Airbrake.should_receive(:build_notice_for).with('oops', {})
21
+ Airbrake::Statsd.should_not_receive(:increment)
22
+
23
+ Airbrake.notify_without_statsd('oops', {})
24
+ end
25
+ end
26
+
27
+ describe '#notify' do
28
+ it 'calls Airbrake::Statsd.increment' do
29
+ Airbrake.stub(:send_notice).and_return(nil)
30
+
31
+ Airbrake.should_receive(:build_notice_for).with('oops', {})
32
+ Airbrake::Statsd.should_receive(:increment)
33
+
34
+ Airbrake.notify('oops', {})
35
+ end
36
+ end
37
+
38
+ describe '#notify_or_ignore_without_statsd' do
39
+ it 'does not call Airbrake::Statsd.increment' do
40
+ Airbrake.stub(:send_notice).and_return(nil)
41
+
42
+ Airbrake.should_receive(:build_notice_for).with('oops', {}).
43
+ and_return(mock('Notice', :ignore? => false))
44
+ Airbrake::Statsd.should_not_receive(:increment)
45
+
46
+ Airbrake.notify_or_ignore_without_statsd('oops', {})
47
+ end
48
+ end
49
+
50
+ describe '#notify_or_ignore' do
51
+ it 'calls Airbrake::Statsd.increment' do
52
+ Airbrake.stub(:send_notice).and_return(nil)
53
+
54
+ Airbrake.should_receive(:build_notice_for).with('oops', {}).
55
+ and_return(mock('Notice', :ignore? => false))
56
+ Airbrake::Statsd.should_receive(:increment)
57
+
58
+ Airbrake.notify_or_ignore('oops', {})
59
+ end
60
+ end
61
+
62
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ module Airbrake
4
+ module Statsd
5
+ describe Configuration do
6
+
7
+ describe '`host` option' do
8
+ it 'defaults to "localhost"' do
9
+ subject.host.should == 'localhost'
10
+ end
11
+
12
+ it 'can be set' do
13
+ subject.host = 'not-default.com'
14
+ subject.host.should == 'not-default.com'
15
+ end
16
+ end
17
+
18
+ describe '`port` option' do
19
+ it 'defaults to 8125' do
20
+ subject.port.should == 8125
21
+ end
22
+
23
+ it 'can be set' do
24
+ subject.port = 88125
25
+ subject.port.should == 88125
26
+ end
27
+ end
28
+
29
+ describe '`namespace` option' do
30
+ it 'defaults to "nil"' do
31
+ subject.namespace.should be_nil
32
+ end
33
+
34
+ it 'can be set' do
35
+ subject.namespace = 'my_awesome_app'
36
+ subject.namespace.should == 'my_awesome_app'
37
+ end
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ module Airbrake
4
+ describe Statsd do
5
+
6
+ subject { Statsd }
7
+
8
+ before do
9
+ subject.instance_variable_set('@configured', nil)
10
+ subject.instance_variable_set('@config', nil)
11
+ subject.instance_variable_set('@client', nil)
12
+ end
13
+
14
+ describe '#configured?' do
15
+ context 'when #configure has been called' do
16
+ it 'returns true' do
17
+ subject.configure
18
+ subject.configured?.should be_true
19
+ end
20
+ end # configure called
21
+
22
+ context 'when #configure has not been called' do
23
+ it 'returns false' do
24
+ subject.configured?.should be_false
25
+ end
26
+ end # configure not called
27
+ end # configured?
28
+
29
+ describe '#config' do
30
+ it 'creates new Configuration instance if not set' do
31
+ subject.config.should be_a(Statsd::Configuration)
32
+ end
33
+ end
34
+
35
+ describe '#client' do
36
+ it 'creates a new ::Statsd client instance if not set' do
37
+ subject.config.should_receive(:host).once.and_return('testhost')
38
+ subject.config.should_receive(:port).once.and_return(1234)
39
+ ::Statsd.should_receive(:new).with('testhost', 1234)
40
+ subject.client
41
+ end
42
+
43
+ context 'when a namespace is set in #config instance' do
44
+ before do
45
+ subject.configure { |config| config.namespace = 'test' }
46
+ end
47
+
48
+ it 'sets namespace on client' do
49
+ ::Statsd.any_instance.should_receive(:namespace=).with('test').once
50
+ subject.client
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#increment' do
56
+ context 'when #configure has been called' do
57
+ before { subject.configure }
58
+
59
+ it 'calls #increment on #client instance' do
60
+ subject.client.should_receive(:increment).once
61
+ subject.increment
62
+ end
63
+
64
+ it 'default bucket name used is "exceptions"' do
65
+ subject.client.should_receive(:increment).with('exceptions').once
66
+ subject.increment
67
+ end
68
+ end # configure called
69
+ end # increment
70
+
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: airbrake-statsd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jim Myhrberg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70264029721400 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70264029721400
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70264029719960 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70264029719960
36
+ - !ruby/object:Gem::Dependency
37
+ name: simplecov
38
+ requirement: &70264029719260 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70264029719260
47
+ - !ruby/object:Gem::Dependency
48
+ name: airbrake
49
+ requirement: &70264029718620 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70264029718620
58
+ - !ruby/object:Gem::Dependency
59
+ name: statsd-ruby
60
+ requirement: &70264029717780 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70264029717780
69
+ description: Increment an exception counter in StatsD whenever the Airbrake gem reports
70
+ and exception.
71
+ email:
72
+ - contact@jimeh.me
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .travis.yml
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - airbrake-statsd.gemspec
83
+ - lib/airbrake-statsd.rb
84
+ - lib/airbrake-statsd/airbrake_ext.rb
85
+ - lib/airbrake-statsd/configuration.rb
86
+ - lib/airbrake-statsd/version.rb
87
+ - spec/spec_helper.rb
88
+ - spec/unit/airbrake-statsd/airbrake_ext_spec.rb
89
+ - spec/unit/airbrake-statsd/configuration_spec.rb
90
+ - spec/unit/airbrake-statsd_spec.rb
91
+ homepage: http://github.com/jimeh/airbrake-statsd
92
+ licenses: []
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ segments:
104
+ - 0
105
+ hash: 2958165307938427188
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ segments:
113
+ - 0
114
+ hash: 2958165307938427188
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 1.8.11
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Increment an exception counter in StatsD whenever the Airbrake gem reports
121
+ and exception.
122
+ test_files:
123
+ - spec/spec_helper.rb
124
+ - spec/unit/airbrake-statsd/airbrake_ext_spec.rb
125
+ - spec/unit/airbrake-statsd/configuration_spec.rb
126
+ - spec/unit/airbrake-statsd_spec.rb