adhearsion-reporter 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17f5c0367eeb44fbd42e9bbcdf159cca503a9098
4
- data.tar.gz: 5b00b2a43441bad7ce6b740936762dd91dd63249
3
+ metadata.gz: 55eccb6f3f9822e1bb2fcfb3bf543dba08da7d9f
4
+ data.tar.gz: 8f9a673465445f6bd37e65a694f54f298496d08c
5
5
  SHA512:
6
- metadata.gz: 03f27058cbf2a58674d511ce938bf4d11b5f178650d8bce00d9e8ca1cc74de3695305d2f0ceaa615b91395d9496909768a7c6ae927f53bc0d827a139d642d5cd
7
- data.tar.gz: 02fdfcd86a300414090036727f3c412bad3c47b150a24760fdbc571f17c59d640de14bf9ee889253f593e8c44d21c83468eda447faf2394f9c45910e08acfb92
6
+ metadata.gz: af79d4b1a6c6664347b609e24fef1cf88d10b36bec698cdc637a1ad248bab2485bd45a2ef3a01cfb5263c6da1ebde5466e423223842bf20c8fb9f688b3b13f3e
7
+ data.tar.gz: f69ff9fdfe2ba9265e42d95729ca8a9105b51380b9752bd876a93dc68196e99dd7855681da2aa9d3cb7c8c3b5628da0d8e8229ec8d78e3a876a0db7a1726a530
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --colour
3
+ --tty
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.0
7
+ - jruby-19mode
8
+ - rbx-19mode
9
+ - ruby-head
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: 1.9.2
13
+ - rvm: ruby-head
14
+ - rvm: rbx-19mode
15
+ notifications:
16
+ irc: "irc.freenode.org#adhearsion"
@@ -1,5 +1,11 @@
1
1
  # develop
2
2
 
3
+ # v2.1.0
4
+ * Bugfix: record the correct environment with each notification
5
+ * Feature: include a little more metadata with each notification
6
+ * Feature: ignore notification from configurable list of environments (default: development and test)
7
+ * Feature: include hostname and Adhearsion version in environment portion of report
8
+
3
9
  # v2.0.1
4
10
  * Bugfix: Adhearsion may pass a logger object with exception events
5
11
 
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ 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"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new :spec
6
+
7
+ task default: :spec
@@ -4,7 +4,7 @@ require "adhearsion/reporter/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "adhearsion-reporter"
7
- s.version = Adhearsion::REPORTER_VERSION
7
+ s.version = Adhearsion::Reporter::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Ben Klang"]
10
10
  s.email = %w{bklang@mojolingo.com}
@@ -24,4 +24,7 @@ EOF
24
24
 
25
25
  s.add_runtime_dependency "adhearsion", ["~> 2.0"]
26
26
  s.add_runtime_dependency "toadhopper", [">= 1.3.0"]
27
+ s.add_runtime_dependency "newrelic_rpm", ["~> 3.6"]
28
+
29
+ s.add_development_dependency 'guard-rspec'
27
30
  end
@@ -1,24 +1,41 @@
1
1
  # encoding: utf-8
2
+
2
3
  require 'toadhopper'
3
4
 
5
+ require 'adhearsion'
6
+ require 'adhearsion/reporter/airbrake_notifier'
7
+ require 'adhearsion/reporter/newrelic_notifier'
8
+
4
9
  module Adhearsion
5
- class Reporter < Plugin
6
- config :reporter do
7
- api_key nil, :desc => "The Airbrake/Errbit API key"
8
- url "http://airbrake.io", :desc => "Base URL for notification service"
10
+ class Reporter
11
+ class << self
12
+ def config
13
+ Plugin.config
14
+ end
9
15
  end
10
16
 
11
- init :reporter do
12
- config = Adhearsion.config[:reporter]
13
- notifier = Toadhopper.new config.api_key, :notify_host => config.url
14
- Events.register_callback(:exception) do |e, logger|
15
- response = notifier.post!(e)
16
- if !response.errors.empty? || !(200..299).include?(response.status.to_i)
17
- logger.error "Error posting exception to #{config.url}! Response code #{response.status}"
18
- response.errors.each do |error|
19
- logger.error "#{error}"
20
- end
21
- logger.warn "Original exception message: #{e.message}"
17
+ class Plugin < Adhearsion::Plugin
18
+ config :reporter do
19
+ api_key nil, desc: "The Airbrake/Errbit API key"
20
+ url "http://airbrake.io", desc: "Base URL for notification service"
21
+ notifier Adhearsion::Reporter::AirbrakeNotifier,
22
+ desc: "The class that will act as the notifier. Built-in classes are Adhearsion::Reporter::AirbrakeNotifier and Adhearsion::Reporter::NewrelicNotifier",
23
+ transform: Proc.new { |v| const_get(v.to_s) }
24
+ enable true, desc: "Disables notifications. Useful for testing"
25
+ excluded_environments [:development, :test], desc: "Skip reporting errors for the listed environments (comma delimited when set by environment variable", transform: Proc.new { |v| names = v.split(','); names = names.each.map &:to_sym }
26
+ newrelic {
27
+ license_key 'MYKEY', desc: "Your license key for New Relic"
28
+ app_name "My Application", desc: "The name of your application as you'd like it show up in New Relic"
29
+ monitor_mode false, desc: "Whether the agent collects performance data about your application"
30
+ developer_mode false, desc: "More information but very high overhead in memory"
31
+ log_level 'info', desc: "The newrelic's agent log level"
32
+ }
33
+ end
34
+
35
+ init :reporter do
36
+ Reporter.config.notifier.init
37
+ Events.register_callback(:exception) do |e, logger|
38
+ Reporter.config.notifier.instance.notify e
22
39
  end
23
40
  end
24
41
  end
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'toadhopper'
4
+ require 'socket'
5
+ require 'adhearsion/reporter/version'
6
+
7
+ module Adhearsion
8
+ class Reporter
9
+ class AirbrakeNotifier
10
+ include Singleton
11
+
12
+ def init
13
+ @notifier = Toadhopper.new Reporter.config.api_key, :notify_host => Reporter.config.url
14
+ @options = {
15
+ framework_env: Adhearsion.config.platform.environment,
16
+ notifier_name: 'adhearsion-reporter',
17
+ notifier_version: Adhearsion::Reporter::VERSION,
18
+ project_root: Adhearsion.config.platform[:root],
19
+ environment: {
20
+ 'HOSTNAME' => Socket.gethostname,
21
+ 'AHN_VERSION' => Adhearsion::VERSION
22
+ }
23
+ }
24
+ end
25
+
26
+ def notify(ex)
27
+ return unless should_post?
28
+ response = @notifier.post!(ex, @options)
29
+ if !response.errors.empty? || !(200..299).include?(response.status.to_i)
30
+ logger.error "Error posting exception to #{Reporter.config.url}! Response code #{response.status}"
31
+ response.errors.each do |error|
32
+ logger.error "#{error}"
33
+ end
34
+ logger.warn "Original exception message: #{ex.message}"
35
+ end
36
+ end
37
+
38
+ def self.method_missing(m, *args, &block)
39
+ instance.send m, *args, &block
40
+ end
41
+
42
+ private
43
+ def should_post?
44
+ Reporter.config.enable &&
45
+ !Reporter.config.excluded_environments.include?(@options[:framework_env])
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require 'new_relic/control'
4
+
5
+ module Adhearsion
6
+ class Reporter
7
+ class NewrelicNotifier
8
+ include Singleton
9
+
10
+ def init
11
+ NewRelic::Agent.manual_start(Adhearsion::Reporter.config.newrelic.to_hash)
12
+ end
13
+
14
+ def notify(ex)
15
+ NewRelic::Agent.notice_error(ex)
16
+ rescue Exception => e
17
+ logger.error "Error posting exception to Newrelic"
18
+ logger.warn "Original exception message: #{e.message}"
19
+ raise
20
+ end
21
+
22
+ def self.method_missing(m, *args, &block)
23
+ instance.send m, *args, &block
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,5 @@
1
1
  module Adhearsion
2
- REPORTER_VERSION = '2.0.1'
2
+ class Reporter
3
+ VERSION = '2.1.0'
4
+ end
3
5
  end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe Adhearsion::Reporter do
4
+ EventClass = Class.new
5
+ ExceptionClass = Class.new StandardError
6
+
7
+ context "with a DummyNotifier" do
8
+ class DummyNotifier
9
+ include Singleton
10
+ attr_reader :initialized, :notified
11
+ def init
12
+ @initialized = true
13
+ end
14
+
15
+ def notify(ex)
16
+ @notified = ex
17
+ end
18
+
19
+ def self.method_missing(m, *args, &block)
20
+ instance.send m, *args, &block
21
+ end
22
+ end
23
+
24
+ before(:each) do
25
+ Adhearsion::Reporter.config.notifier = DummyNotifier
26
+ Adhearsion::Plugin.init_plugins
27
+ Adhearsion::Events.trigger_immediately :exception, ExceptionClass.new
28
+ end
29
+
30
+ it "calls init on the notifier instance" do
31
+ Adhearsion::Reporter.config.notifier.instance.initialized.should == true
32
+ end
33
+
34
+ it "logs an exception event" do
35
+ sleep 0.25
36
+ Adhearsion::Reporter.config.notifier.instance.notified.class.should == ExceptionClass
37
+ end
38
+ end
39
+
40
+ context "with a AirbrakeNotifier" do
41
+ before(:each) do
42
+ Adhearsion::Reporter.config.notifier = Adhearsion::Reporter::AirbrakeNotifier
43
+ end
44
+
45
+ it "should initialize correctly" do
46
+ Toadhopper.should_receive(:new).with(Adhearsion::Reporter.config.api_key, notify_host: Adhearsion::Reporter.config.url)
47
+ Adhearsion::Plugin.init_plugins
48
+ end
49
+
50
+ context "exceptions" do
51
+ let(:mock_notifier) { double 'notifier' }
52
+ let(:event_error) { ExceptionClass.new }
53
+ let(:response) { double('response').as_null_object }
54
+
55
+ before { Toadhopper.should_receive(:new).at_least(:once).and_return(mock_notifier) }
56
+
57
+ after do
58
+ Adhearsion::Plugin.init_plugins
59
+ Adhearsion::Events.trigger_immediately :exception, event_error
60
+ end
61
+
62
+ it "should notify Airbrake" do
63
+ mock_notifier.should_receive(:post!).at_least(:once).with(event_error, hash_including(framework_env: :production)).and_return(response)
64
+ end
65
+
66
+ context "with an environment set" do
67
+ before { Adhearsion.config.platform.environment = :foo }
68
+
69
+ it "notifies airbrake with that environment" do
70
+ mock_notifier.should_receive(:post!).at_least(:once).with(event_error, hash_including(framework_env: :foo)).and_return(response)
71
+ end
72
+ end
73
+
74
+ context "in excluded environments" do
75
+ before do
76
+ Adhearsion.config.platform.environment = :development
77
+ Adhearsion::Plugin.init_plugins
78
+ end
79
+ it "should not report errors for excluded environments" do
80
+ mock_notifier.should_not_receive(:post!)
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ context "with a NewrelicNotifier" do
87
+ before(:each) do
88
+ Adhearsion::Reporter.config.notifier = Adhearsion::Reporter::NewrelicNotifier
89
+ end
90
+
91
+ it "should initialize correctly" do
92
+ NewRelic::Agent.should_receive(:manual_start).with(Adhearsion::Reporter.config.newrelic.to_hash)
93
+ Adhearsion::Plugin.init_plugins
94
+ end
95
+
96
+ it "should notify Newrelic" do
97
+ NewRelic::Agent.should_receive(:manual_start)
98
+
99
+ event_error = ExceptionClass.new
100
+ NewRelic::Agent.should_receive(:notice_error).at_least(:once).with(event_error)
101
+
102
+ Adhearsion::Plugin.init_plugins
103
+ Adhearsion::Events.trigger_immediately :exception, event_error
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,13 @@
1
+ require 'adhearsion'
2
+ require 'adhearsion/reporter'
3
+ require 'socket'
4
+
5
+ ENV['AHN_ENV'] = 'production'
6
+
7
+ RSpec.configure do |config|
8
+ config.color_enabled = true
9
+ config.tty = true
10
+
11
+ config.filter_run :focus => true
12
+ config.run_all_when_everything_filtered = true
13
+ end
metadata CHANGED
@@ -1,43 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adhearsion-reporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Klang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-20 00:00:00.000000000 Z
11
+ date: 2014-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: adhearsion
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: toadhopper
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: newrelic_rpm
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  description: |
42
70
  Report Adhearsion application exceptions and deployments to:
43
71
 
@@ -50,16 +78,23 @@ executables: []
50
78
  extensions: []
51
79
  extra_rdoc_files: []
52
80
  files:
53
- - .gitignore
81
+ - ".gitignore"
82
+ - ".rspec"
83
+ - ".travis.yml"
54
84
  - CHANGELOG.md
55
85
  - Gemfile
86
+ - Guardfile
56
87
  - LICENSE
57
88
  - README.md
58
89
  - Rakefile
59
90
  - adhearsion-reporter.gemspec
60
91
  - lib/adhearsion-reporter.rb
61
92
  - lib/adhearsion/reporter.rb
93
+ - lib/adhearsion/reporter/airbrake_notifier.rb
94
+ - lib/adhearsion/reporter/newrelic_notifier.rb
62
95
  - lib/adhearsion/reporter/version.rb
96
+ - spec/reporter_spec.rb
97
+ - spec/spec_helper.rb
63
98
  homepage: http://github.com/adhearsion/adhearsion-reporter
64
99
  licenses: []
65
100
  metadata: {}
@@ -69,18 +104,21 @@ require_paths:
69
104
  - lib
70
105
  required_ruby_version: !ruby/object:Gem::Requirement
71
106
  requirements:
72
- - - '>='
107
+ - - ">="
73
108
  - !ruby/object:Gem::Version
74
109
  version: '0'
75
110
  required_rubygems_version: !ruby/object:Gem::Requirement
76
111
  requirements:
77
- - - '>='
112
+ - - ">="
78
113
  - !ruby/object:Gem::Version
79
114
  version: '0'
80
115
  requirements: []
81
116
  rubyforge_project:
82
- rubygems_version: 2.0.0
117
+ rubygems_version: 2.2.1
83
118
  signing_key:
84
119
  specification_version: 4
85
120
  summary: Report Adhearsion application deployments and exceptions
86
- test_files: []
121
+ test_files:
122
+ - spec/reporter_spec.rb
123
+ - spec/spec_helper.rb
124
+ has_rdoc: