mirror of
https://github.com/jimeh/airbrake-statsd.git
synced 2026-02-19 10:56:43 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7009d8c702 | |||
| c3300d264c | |||
| b783fd85e7 | |||
| fa8a8fc57a | |||
| 119f160dec |
@@ -32,7 +32,7 @@ module Airbrake
|
|||||||
|
|
||||||
def increment
|
def increment
|
||||||
return unless configured?
|
return unless configured?
|
||||||
client.increment('exceptions')
|
client.increment(config.bucket)
|
||||||
end
|
end
|
||||||
|
|
||||||
end # << self
|
end # << self
|
||||||
|
|||||||
@@ -1,21 +1,15 @@
|
|||||||
module Airbrake
|
module Airbrake
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
def notify_with_statds(*args)
|
private
|
||||||
|
|
||||||
|
def send_notice_with_statsd(*args)
|
||||||
Airbrake::Statsd.increment
|
Airbrake::Statsd.increment
|
||||||
notify_without_statsd(*args)
|
send_notice_without_statsd(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
alias :notify_without_statsd :notify
|
alias :send_notice_without_statsd :send_notice
|
||||||
alias :notify :notify_with_statds
|
alias :send_notice :send_notice_with_statsd
|
||||||
|
|
||||||
def notify_or_ignore_with_statsd(*args)
|
|
||||||
Airbrake::Statsd.increment
|
|
||||||
notify_or_ignore_without_statsd(*args)
|
|
||||||
end
|
|
||||||
|
|
||||||
alias :notify_or_ignore_without_statsd :notify_or_ignore
|
|
||||||
alias :notify_or_ignore :notify_or_ignore_with_statsd
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ module Airbrake
|
|||||||
end
|
end
|
||||||
attr_writer :port
|
attr_writer :port
|
||||||
|
|
||||||
|
def bucket
|
||||||
|
@bucket ||= 'exceptions'
|
||||||
|
end
|
||||||
|
attr_writer :bucket
|
||||||
|
|
||||||
end # Configuration
|
end # Configuration
|
||||||
end # Statsd
|
end # Statsd
|
||||||
end # Airbrake
|
end # Airbrake
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module Airbrake
|
module Airbrake
|
||||||
module Statsd
|
module Statsd
|
||||||
VERSION = '0.1.0'
|
VERSION = '0.2.1'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,58 +4,33 @@ describe Airbrake do
|
|||||||
|
|
||||||
subject { Airbrake }
|
subject { Airbrake }
|
||||||
|
|
||||||
it '#notify is an alias to #notify_with_statsd' do
|
let(:notice) { mock('Notice', :to_xml => '') }
|
||||||
subject.method(:notify).should == subject.method(:notify_with_statds)
|
let(:configuration) { mock('Configuration', :public? => true) }
|
||||||
|
|
||||||
|
let(:sender) do
|
||||||
|
sender = mock('Sender')
|
||||||
|
sender.stub(:send_to_airbrake)
|
||||||
|
sender
|
||||||
end
|
end
|
||||||
|
|
||||||
it '#notify_or_ignore is an alias to #notify_or_ignore_with_statsd' do
|
describe '#send_notice_without_statsd' do
|
||||||
subject.method(:notify_or_ignore).
|
before do
|
||||||
should == subject.method(:notify_or_ignore_with_statsd)
|
Airbrake.stub(:configuration).and_return(configuration)
|
||||||
end
|
Airbrake.stub(:sender).and_return(sender)
|
||||||
|
end
|
||||||
|
|
||||||
describe '#notify_without_statsd' do
|
|
||||||
it 'does not call Airbrake::Statsd.increment' do
|
it 'does not call Airbrake::Statsd.increment' do
|
||||||
Airbrake.stub(:send_notice).and_return(nil)
|
|
||||||
|
|
||||||
Airbrake.should_receive(:build_notice_for).with('oops', {})
|
|
||||||
Airbrake::Statsd.should_not_receive(:increment)
|
Airbrake::Statsd.should_not_receive(:increment)
|
||||||
|
Airbrake.send(:send_notice_without_statsd, notice)
|
||||||
Airbrake.notify_without_statsd('oops', {})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#notify' do
|
describe '#send_notice' do
|
||||||
it 'calls Airbrake::Statsd.increment' do
|
it 'calls Airbrake::Statsd.increment' do
|
||||||
Airbrake.stub(:send_notice).and_return(nil)
|
|
||||||
|
|
||||||
Airbrake.should_receive(:build_notice_for).with('oops', {})
|
|
||||||
Airbrake::Statsd.should_receive(:increment)
|
Airbrake::Statsd.should_receive(:increment)
|
||||||
|
Airbrake.should_receive(:send_notice_without_statsd)
|
||||||
|
|
||||||
Airbrake.notify('oops', {})
|
Airbrake.send(:send_notice, notice)
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#notify_or_ignore_without_statsd' do
|
|
||||||
it 'does not call Airbrake::Statsd.increment' do
|
|
||||||
Airbrake.stub(:send_notice).and_return(nil)
|
|
||||||
|
|
||||||
Airbrake.should_receive(:build_notice_for).with('oops', {}).
|
|
||||||
and_return(mock('Notice', :ignore? => false))
|
|
||||||
Airbrake::Statsd.should_not_receive(:increment)
|
|
||||||
|
|
||||||
Airbrake.notify_or_ignore_without_statsd('oops', {})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#notify_or_ignore' do
|
|
||||||
it 'calls Airbrake::Statsd.increment' do
|
|
||||||
Airbrake.stub(:send_notice).and_return(nil)
|
|
||||||
|
|
||||||
Airbrake.should_receive(:build_notice_for).with('oops', {}).
|
|
||||||
and_return(mock('Notice', :ignore? => false))
|
|
||||||
Airbrake::Statsd.should_receive(:increment)
|
|
||||||
|
|
||||||
Airbrake.notify_or_ignore('oops', {})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,17 @@ module Airbrake
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '`bucket` option' do
|
||||||
|
it 'defaults to "exceptions"' do
|
||||||
|
subject.bucket.should == 'exceptions'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'can be set' do
|
||||||
|
subject.bucket = 'errors'
|
||||||
|
subject.bucket.should == 'errors'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,11 +6,26 @@ module Airbrake
|
|||||||
subject { Statsd }
|
subject { Statsd }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
subject.instance_variable_set('@configured', nil)
|
['@configured', '@config', '@client'].each do |var_name|
|
||||||
subject.instance_variable_set('@config', nil)
|
subject.instance_variable_set(var_name, nil)
|
||||||
subject.instance_variable_set('@client', nil)
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#configure' do
|
||||||
|
it 'sets @configured to true' do
|
||||||
|
subject.instance_variable_get('@configured').should_not be_true
|
||||||
|
subject.configure
|
||||||
|
subject.instance_variable_get('@configured').should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when block is passed' do
|
||||||
|
it 'passes #config to block' do
|
||||||
|
block = Proc.new { |conf| conf.should be_a(Statsd::Configuration) }
|
||||||
|
subject.configure(&block)
|
||||||
|
end
|
||||||
|
end # block passed
|
||||||
|
end # configure
|
||||||
|
|
||||||
describe '#configured?' do
|
describe '#configured?' do
|
||||||
context 'when #configure has been called' do
|
context 'when #configure has been called' do
|
||||||
it 'returns true' do
|
it 'returns true' do
|
||||||
@@ -30,7 +45,7 @@ module Airbrake
|
|||||||
it 'creates new Configuration instance if not set' do
|
it 'creates new Configuration instance if not set' do
|
||||||
subject.config.should be_a(Statsd::Configuration)
|
subject.config.should be_a(Statsd::Configuration)
|
||||||
end
|
end
|
||||||
end
|
end # config
|
||||||
|
|
||||||
describe '#client' do
|
describe '#client' do
|
||||||
it 'creates a new ::Statsd client instance if not set' do
|
it 'creates a new ::Statsd client instance if not set' do
|
||||||
@@ -49,23 +64,36 @@ module Airbrake
|
|||||||
::Statsd.any_instance.should_receive(:namespace=).with('test').once
|
::Statsd.any_instance.should_receive(:namespace=).with('test').once
|
||||||
subject.client
|
subject.client
|
||||||
end
|
end
|
||||||
end
|
end # namespace is set
|
||||||
end
|
end # client
|
||||||
|
|
||||||
describe '#increment' do
|
describe '#increment' do
|
||||||
context 'when #configure has been called' do
|
context 'when #configure has been called' do
|
||||||
before { subject.configure }
|
before { subject.configure }
|
||||||
|
|
||||||
it 'calls #increment on #client instance' do
|
it 'calls #increment on #client' do
|
||||||
subject.client.should_receive(:increment).once
|
|
||||||
subject.increment
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'default bucket name used is "exceptions"' do
|
|
||||||
subject.client.should_receive(:increment).with('exceptions').once
|
subject.client.should_receive(:increment).with('exceptions').once
|
||||||
subject.increment
|
subject.increment
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when bucket option has been customized' do
|
||||||
|
before do
|
||||||
|
subject.configure { |config| config.bucket = 'errors' }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'calls #increment on #client with custom bucket' do
|
||||||
|
subject.client.should_receive(:increment).with('errors').once
|
||||||
|
subject.increment
|
||||||
|
end
|
||||||
|
end # bucket option customized
|
||||||
end # configure called
|
end # configure called
|
||||||
|
|
||||||
|
context 'when #configure has not been called' do
|
||||||
|
it 'does not call #increment on #client' do
|
||||||
|
subject.client.should_not_receive(:increment)
|
||||||
|
subject.increment
|
||||||
|
end
|
||||||
|
end # configure not called
|
||||||
end # increment
|
end # increment
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user