Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ebd5166
Update README for new version
bklang Dec 23, 2011
52e7e25
Formatting
bklang Dec 23, 2011
5b6b9ad
Fix broken link
bklang Dec 23, 2011
1ea5a15
Update for Adhearsion 2.0
bklang Dec 23, 2011
cf9d705
Fix development dependency
bklang Dec 23, 2011
ed3025f
Hack to fix Bundler auto-require
bklang Dec 23, 2011
d94d9a9
Make class definition consistent
bklang Dec 23, 2011
d8723b4
Avoid Adhearsion dependency just to detect the version
bklang Dec 23, 2011
a112091
Usage information
bklang Dec 23, 2011
5ea0367
Typo in Adhearsion.config
bklang Jan 14, 2012
fbad157
Fix parameter to Toadhopper
bklang Jan 14, 2012
8d3d380
Depend on Ahn 2.0 alpha1
bklang Jan 18, 2012
b3fee7b
[RELEASE] Changed license to MIT and copyright to Adhearsion Foundati…
lpradovera Apr 11, 2012
611a37f
Merge branch 'release/2.0.0' into develop
lpradovera Apr 11, 2012
7fc2153
Now accounts for logger being passed in
Feb 18, 2013
7bb0041
Increment minor version
Feb 19, 2013
77dd04c
[CS] Clean up gemspec
benlangfeld Mar 19, 2013
b5cbd8d
Revert "Increment minor version"
benlangfeld Mar 19, 2013
4ffebe1
[CS] Remove non-existant specs
benlangfeld Mar 19, 2013
de0d41a
[DOC] Changelog entry
benlangfeld Mar 19, 2013
d5648e0
[UPDATE] Bump to 2.0.1
benlangfeld Mar 20, 2013
8a502b7
Merge branch 'release/2.0.1' into develop
benlangfeld Mar 20, 2013
7ef3430
[CS] Use full rubygems URL in Gemfile
benlangfeld Mar 20, 2013
d7788e3
[CS] Ignore stuff we don't care about
benlangfeld Mar 20, 2013
f387c5b
Moved notifiers to a separate class. Added specs.
lpradovera Nov 1, 2013
b288e7c
First pass at Newrelic support
lpradovera Nov 1, 2013
dfef696
Some basic specs. Newrelic support complete.
lpradovera Nov 1, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
vendor/ruby
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--format documentation
--colour
--tty
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# develop

# v2.0.1
* Bugfix: Adhearsion may pass a logger object with exception events

# v2.0.0
* First release
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source :rubygems
source 'https://rubygems.org'

gemspec
24 changes: 24 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard :rspec do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }

# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }

# Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }

# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end

20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (C) 2012 Adhearsion Foundation Inc.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
This component for Adhearsion allows you to catch exceptions raised within Adhearsion applications and report them to [Hoptoad](http://hoptoadapp.com)
adhearsion-reporter
==================

Report Adhearsion application exceptions and deployments to:

* [Airbrake](http://airbrake.io)
* [Errbit](https://github.com/errbit/errbit)

This Adhearsion plugin requires Adhearsion 2.0 or later. For Adhearsion 1.0 try the previous version of this gem [ahn_hoptoad](https://github.com/mojolingo/ahn_hoptoad)

Usage
-----

To use this gem, add the following line to your Gemfile:

```ruby
gem 'adhearsion-reporter'
```

To view the available configuration options, run the rake task:

```
rake adhearsion:config:show[reporter]
```

The configuration options are added to config/adhearsion.rb with the rest of Adhearsion's configuration. Example:

```ruby
Adhearsion.config do |config|
config.reporter.api_key = "YOUR API KEY HERE"
end
```

Copyright
---------

Copyright (C) 2012 Adhearsion Foundation Inc.
Released under the MIT License - Check [License file](https://github.com/adhearsion/adhearsion-reporter/blob/master/LICENSE)
30 changes: 30 additions & 0 deletions adhearsion-reporter.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "adhearsion/reporter/version"

Gem::Specification.new do |s|
s.name = "adhearsion-reporter"
s.version = Adhearsion::REPORTER_VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Ben Klang"]
s.email = %w{bklang@mojolingo.com}
s.homepage = "http://github.com/adhearsion/adhearsion-reporter"
s.summary = %q{Report Adhearsion application deployments and exceptions}
s.description = <<EOF
Report Adhearsion application exceptions and deployments to:

Airbrake
Errbit
This Adhearsion plugin requires Adhearsion 2.0 or later. For Adhearsion 1.0 try the previous version of this gem ahn_hoptoad
EOF
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_runtime_dependency "adhearsion", ["~> 2.0"]
s.add_runtime_dependency "toadhopper", [">= 1.3.0"]
s.add_runtime_dependency "newrelic_rpm", [">= 3.6.8"]

s.add_development_dependency 'guard-rspec'
end
23 changes: 0 additions & 23 deletions ahn_hoptoad.gemspec

This file was deleted.

5 changes: 0 additions & 5 deletions config/ahn_hoptoad.yml

This file was deleted.

2 changes: 2 additions & 0 deletions lib/adhearsion-reporter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# encoding: utf-8
require 'adhearsion/reporter'
33 changes: 33 additions & 0 deletions lib/adhearsion/reporter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# encoding: utf-8

require 'toadhopper'

Adhearsion::Reporter = Class.new Adhearsion::Plugin

require 'adhearsion/reporter/hoptoad_notifier'
require 'adhearsion/reporter/newrelic_notifier'

module Adhearsion
class Reporter
config :reporter do
api_key nil, desc: "The Airbrake/Errbit API key"
url "http://airbrake.io", desc: "Base URL for notification service"
notifier Adhearsion::Reporter::HoptoadNotifier, desc: "The class that will act as the notifier"
enable true, desc: "Disables notifications. Useful for testing"
newrelic {
license_key 'MYKEY', desc: "Your license key for New Relic"
app_name "My Application", desc: "The name of your application as you'd like it show up in New Relic"
monitor_mode false, desc: "Whether the agent collects performance data about your application"
developer_mode false, desc: "More information but very high overhead in memory"
log_level 'info', desc: "The newrelic's agent log level"
}
end

init :reporter do
Reporter.config.notifier.instance.init
Events.register_callback(:exception) do |e, logger|
Reporter.config.notifier.instance.notify e
end
end
end
end
26 changes: 26 additions & 0 deletions lib/adhearsion/reporter/hoptoad_notifier.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# encoding: utf-8

require 'toadhopper'

module Adhearsion
class Reporter
class HoptoadNotifier
include Singleton

def init
@notifier = Toadhopper.new Reporter.config.api_key, :notify_host => Reporter.config.url
end

def notify(ex)
response = @notifier.post!(ex) if Reporter.config.enable
if !response.errors.empty? || !(200..299).include?(response.status.to_i)
logger.error "Error posting exception to #{Reporter.config.url}! Response code #{response.status}"
response.errors.each do |error|
logger.error "#{error}"
end
logger.warn "Original exception message: #{ex.message}"
end
end
end
end
end
23 changes: 23 additions & 0 deletions lib/adhearsion/reporter/newrelic_notifier.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# encoding: utf-8

require 'new_relic/control'

module Adhearsion
class Reporter
class NewrelicNotifier
include Singleton

def init
NewRelic::Agent.manual_start(Adhearsion::Reporter.config.newrelic.to_hash)
end

def notify(ex)
NewRelic::Agent.notice_error(ex)
rescue Exception => e
logger.error "Error posting exception to Newrelic"
logger.warn "Original exception message: #{e.message}"
raise
end
end
end
end
3 changes: 3 additions & 0 deletions lib/adhearsion/reporter/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Adhearsion
REPORTER_VERSION = '2.0.1'
end
16 changes: 0 additions & 16 deletions lib/ahn_hoptoad.rb

This file was deleted.

3 changes: 0 additions & 3 deletions lib/ahn_hoptoad/version.rb

This file was deleted.

8 changes: 0 additions & 8 deletions spec/ahnhoptoad_spec.rb

This file was deleted.

76 changes: 76 additions & 0 deletions spec/reporter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
require 'spec_helper'

describe Adhearsion::Reporter do
EventClass = Class.new
ExceptionClass = Class.new StandardError

context "with a DummyNotifier" do
class DummyNotifier
include Singleton
attr_reader :initialized, :notified
def init
@initialized = true
end

def notify(ex)
@notified = ex
end
end

before(:each) do
Adhearsion::Reporter.config.notifier = DummyNotifier
Adhearsion::Plugin.init_plugins
Adhearsion::Events.trigger_immediately :exception, ExceptionClass.new
end

it "calls init on the notifier instance" do
Adhearsion::Reporter.config.notifier.instance.initialized.should == true
end

it "logs an exception event" do
sleep 0.25
Adhearsion::Reporter.config.notifier.instance.notified.class.should == ExceptionClass
end
end

context "with a HoptoadNotifier" do
before(:each) do
Adhearsion::Reporter.config.notifier = Adhearsion::Reporter::HoptoadNotifier
end

it "should initialize correctly" do
Toadhopper.should_receive(:new).with(Adhearsion::Reporter.config.api_key, notify_host: Adhearsion::Reporter.config.url)
Adhearsion::Plugin.init_plugins
end

it "should notify Airbrake" do
mock_notifier = double('notifier')
Toadhopper.should_receive(:new).and_return(mock_notifier)
event_error = ExceptionClass.new
mock_notifier.should_receive(:post!).at_least(:once).with(event_error).and_return(double('response').as_null_object)
Adhearsion::Plugin.init_plugins
Adhearsion::Events.trigger_immediately :exception, event_error
end
end

context "with a NewrelicNotifier" do
before(:each) do
Adhearsion::Reporter.config.notifier = Adhearsion::Reporter::NewrelicNotifier
end

it "should initialize correctly" do
NewRelic::Agent.should_receive(:manual_start).with(Adhearsion::Reporter.config.newrelic.to_hash)
Adhearsion::Plugin.init_plugins
end

it "should notify Newrelic" do
NewRelic::Agent.should_receive(:manual_start)

event_error = ExceptionClass.new
NewRelic::Agent.should_receive(:notice_error).at_least(:once).with(event_error)

Adhearsion::Plugin.init_plugins
Adhearsion::Events.trigger_immediately :exception, event_error
end
end
end
12 changes: 12 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'adhearsion'
require 'adhearsion/reporter'

ENV['AHN_ENV'] = 'test'

RSpec.configure do |config|
config.color_enabled = true
config.tty = true

config.filter_run :focus => true
config.run_all_when_everything_filtered = true
end