whoops_rails_notifier 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +2 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +25 -0
- data/lib/whoops_rails_notifier.rb +24 -0
- data/lib/whoops_rails_notifier/action_controller_catcher.rb +19 -0
- data/lib/whoops_rails_notifier/controller_methods.rb +50 -0
- data/lib/whoops_rails_notifier/evidence.rb +29 -0
- data/lib/whoops_rails_notifier/exception_strategy.rb +38 -0
- data/lib/whoops_rails_notifier/rack.rb +45 -0
- data/lib/whoops_rails_notifier/railtie.rb +11 -0
- metadata +194 -0
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
|
12
|
+
require 'rspec/core'
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
16
|
+
|
17
|
+
task :default => :spec
|
18
|
+
|
19
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
20
|
+
rdoc.rdoc_dir = 'rdoc'
|
21
|
+
rdoc.title = 'WhoopsRailsNotifier'
|
22
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
23
|
+
rdoc.rdoc_files.include('README.rdoc')
|
24
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "digest"
|
2
|
+
require "whoops_notifier"
|
3
|
+
require "whoops_rails_notifier/action_controller_catcher"
|
4
|
+
require "whoops_rails_notifier/controller_methods"
|
5
|
+
require "whoops_rails_notifier/exception_strategy"
|
6
|
+
require "whoops_rails_notifier/rack"
|
7
|
+
require "whoops_rails_notifier/railtie"
|
8
|
+
|
9
|
+
module WhoopsRailsNotifier
|
10
|
+
def self.initialize
|
11
|
+
configure
|
12
|
+
create_exception_strategy
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configure
|
16
|
+
config = YAML.load_file(File.join(Rails.root, "config", "whoops.yml"))[Rails.env]
|
17
|
+
WhoopsNotifier.config.set(config)
|
18
|
+
WhoopsNotifier.config.logger = Rails.logger
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.create_exception_strategy
|
22
|
+
strategy = WhoopsRailsNotifier::ExceptionStrategy.new(:rails_exception)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module WhoopsRailsNotifier
|
2
|
+
module ActionControllerCatcher
|
3
|
+
# Sets up an alias chain to catch exceptions when Rails does
|
4
|
+
def self.included(base) #:nodoc:
|
5
|
+
# base.send(:alias_method, :rescue_action_in_public_without_whoops, :rescue_action_in_public)
|
6
|
+
# base.send(:alias_method, :rescue_action_in_public, :rescue_action_in_public_with_whoops)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
# Overrides the rescue_action method in ActionController::Base, but does not inhibit
|
12
|
+
# any custom processing that is defined with Rails 2's exception helpers.
|
13
|
+
def rescue_action_in_public_with_whoops(exception)
|
14
|
+
evidence = {:exception => exception}.merge(whoops_request_data)
|
15
|
+
WhoopsRailsNotifier.notify(evidence)
|
16
|
+
rescue_action_in_public_without_whoops(exception)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module WhoopsRailsNotifier
|
2
|
+
module ControllerMethods
|
3
|
+
private
|
4
|
+
|
5
|
+
# This method should be used for sending manual notifications while you are still
|
6
|
+
# inside the controller. Otherwise it works like WhoopsNotifierRails.notify.
|
7
|
+
def notify_whoops(exception)
|
8
|
+
evidence = {:exception => exception}.merge(whoops_request_data)
|
9
|
+
WhoopsRailsNotifier.notify(:rails, evidence)
|
10
|
+
end
|
11
|
+
|
12
|
+
def whoops_request_data
|
13
|
+
{ :parameters => whoops_filter_if_filtering(params.to_hash),
|
14
|
+
:session_data => whoops_filter_if_filtering(whoops_session_data),
|
15
|
+
:controller => params[:controller],
|
16
|
+
:action => params[:action],
|
17
|
+
:url => whoops_request_url,
|
18
|
+
:cgi_data => whoops_filter_if_filtering(request.env) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def whoops_filter_if_filtering(hash)
|
22
|
+
return hash if ! hash.is_a?(Hash)
|
23
|
+
|
24
|
+
if respond_to?(:filter_parameters)
|
25
|
+
filter_parameters(hash) rescue hash
|
26
|
+
else
|
27
|
+
hash
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def whoops_session_data
|
32
|
+
if session.respond_to?(:to_hash)
|
33
|
+
session.to_hash
|
34
|
+
else
|
35
|
+
session.data
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def whoops_request_url
|
40
|
+
url = "#{request.protocol}#{request.host}"
|
41
|
+
|
42
|
+
unless [80, 443].include?(request.port)
|
43
|
+
url << ":#{request.port}"
|
44
|
+
end
|
45
|
+
|
46
|
+
url << request.request_uri
|
47
|
+
url
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module WhoopsRailsNotifier
|
2
|
+
class Evidence
|
3
|
+
attr_accessor :exception
|
4
|
+
attr_accessor :url
|
5
|
+
|
6
|
+
def initialize(exception, rack)
|
7
|
+
self.exception = exception
|
8
|
+
self.rack = rack
|
9
|
+
self.url = args[:url] || rack_env(:url)
|
10
|
+
|
11
|
+
self.parameters = args[:parameters] ||
|
12
|
+
action_dispatch_params ||
|
13
|
+
rack_env(:params) ||
|
14
|
+
{}
|
15
|
+
self.component = args[:component] || args[:controller] || parameters['controller']
|
16
|
+
self.action = args[:action] || parameters['action']
|
17
|
+
|
18
|
+
self.environment_name = args[:environment_name]
|
19
|
+
self.cgi_data = args[:cgi_data] || args[:rack_env]
|
20
|
+
self.backtrace = Backtrace.parse(exception_attribute(:backtrace, caller), :filters => self.backtrace_filters)
|
21
|
+
self.error_class = exception_attribute(:error_class) {|exception| exception.class.name }
|
22
|
+
self.error_message = exception_attribute(:error_message, 'Notification') do |exception|
|
23
|
+
end
|
24
|
+
|
25
|
+
def action_dispatch_params
|
26
|
+
rack[:rack_env]['action_dispatch.request.parameters'] if rack
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module WhoopsRailsNotifier
|
2
|
+
class ExceptionStrategy < WhoopsNotifier::Strategy
|
3
|
+
attr_accessor :service, :environment
|
4
|
+
def initialize(strategy_name)
|
5
|
+
super
|
6
|
+
|
7
|
+
self.service = ::Rails.application.class.name.split("::").first.downcase
|
8
|
+
self.environment = ::Rails.env
|
9
|
+
|
10
|
+
add_report_modifiers
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_report_modifiers
|
14
|
+
self.add_report_modifier(:basic_details) do |report, evidence|
|
15
|
+
report.service = self.service
|
16
|
+
report.environment = self.environment
|
17
|
+
report.event_type = "exception"
|
18
|
+
report.message = evidence[:exception].message
|
19
|
+
report.event_time = Time.now
|
20
|
+
end
|
21
|
+
|
22
|
+
self.add_report_modifier(:details) do |report, evidence|
|
23
|
+
exception = evidence[:exception]
|
24
|
+
rack_env = evidence[:rack_env]
|
25
|
+
|
26
|
+
details = {}
|
27
|
+
details[:backtrace] = exception.backtrace.collect{|l| l.sub(/^#{ENV['GEM_HOME']}/, '%GEM_HOME').sub(/^#{Rails.root}/, '%Rails.root')}
|
28
|
+
report.details = details
|
29
|
+
end
|
30
|
+
|
31
|
+
self.add_report_modifier(:create_event_group_identifier) do |report, evidence|
|
32
|
+
identifier = "#{evidence[:controller]}##{evidence[:action]}"
|
33
|
+
identifier << evidence[:exception].backtrace.collect{|l| l.sub(Rails.root, "")}.join("\n")
|
34
|
+
report.event_group_identifier = Digest::MD5.hexdigest(identifier)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module WhoopsRailsNotifier
|
2
|
+
# Middleware for Rack applications. Any errors raised by the upstream
|
3
|
+
# application will be delivered to Hoptoad and re-raised.
|
4
|
+
#
|
5
|
+
# Synopsis:
|
6
|
+
#
|
7
|
+
# require 'rack'
|
8
|
+
# require 'hoptoad_notifier'
|
9
|
+
#
|
10
|
+
# HoptoadNotifier.configure do |config|
|
11
|
+
# config.api_key = 'my_api_key'
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# app = Rack::Builder.app do
|
15
|
+
# use HoptoadNotifier::Rack
|
16
|
+
# run lambda { |env| raise "Rack down" }
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# Use a standard HoptoadNotifier.configure call to configure your api key.
|
20
|
+
class Rack
|
21
|
+
def initialize(app)
|
22
|
+
@app = app
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(env)
|
26
|
+
begin
|
27
|
+
response = @app.call(env)
|
28
|
+
rescue Exception => raised
|
29
|
+
evidence = {
|
30
|
+
:exception => raised,
|
31
|
+
:rack_env => env
|
32
|
+
}
|
33
|
+
WhoopsNotifier.notify(:rails_exception, evidence)
|
34
|
+
raise
|
35
|
+
end
|
36
|
+
|
37
|
+
# if env['rack.exception']
|
38
|
+
# WhoopsRailsNotifier.notify_or_ignore(env['rack.exception'], :rack_env => env)
|
39
|
+
# env['hoptoad.error_id'] = error_id
|
40
|
+
# end
|
41
|
+
|
42
|
+
response
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module WhoopsRailsNotifier
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
# config.app_middleware.insert_after "ActionDispatch::Callbacks"
|
4
|
+
config.app_middleware.use WhoopsRailsNotifier::Rack
|
5
|
+
|
6
|
+
config.after_initialize do
|
7
|
+
WhoopsRailsNotifier.initialize
|
8
|
+
::ActionController::Base.send(:include, WhoopsRailsNotifier::ControllerMethods)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: whoops_rails_notifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Daniel Higginbotham
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-11 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: whoops_notifier
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 25
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 0
|
33
|
+
- 3
|
34
|
+
version: 0.0.3
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rails
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 5
|
46
|
+
segments:
|
47
|
+
- 3
|
48
|
+
version: "3"
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: rake
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - "="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 49
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
- 8
|
63
|
+
- 7
|
64
|
+
version: 0.8.7
|
65
|
+
type: :development
|
66
|
+
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rspec-rails
|
69
|
+
prerelease: false
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: ruby-debug
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 3
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
type: :development
|
94
|
+
version_requirements: *id005
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: fakeweb
|
97
|
+
prerelease: false
|
98
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 3
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
type: :development
|
108
|
+
version_requirements: *id006
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: sqlite3
|
111
|
+
prerelease: false
|
112
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
hash: 3
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
version: "0"
|
121
|
+
type: :development
|
122
|
+
version_requirements: *id007
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: capybara
|
125
|
+
prerelease: false
|
126
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
hash: 15
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
- 4
|
135
|
+
- 0
|
136
|
+
version: 0.4.0
|
137
|
+
type: :development
|
138
|
+
version_requirements: *id008
|
139
|
+
description: A Whoops Notifier for Rails 3 apps.
|
140
|
+
email:
|
141
|
+
executables: []
|
142
|
+
|
143
|
+
extensions: []
|
144
|
+
|
145
|
+
extra_rdoc_files: []
|
146
|
+
|
147
|
+
files:
|
148
|
+
- lib/whoops_rails_notifier/action_controller_catcher.rb
|
149
|
+
- lib/whoops_rails_notifier/controller_methods.rb
|
150
|
+
- lib/whoops_rails_notifier/evidence.rb
|
151
|
+
- lib/whoops_rails_notifier/exception_strategy.rb
|
152
|
+
- lib/whoops_rails_notifier/rack.rb
|
153
|
+
- lib/whoops_rails_notifier/railtie.rb
|
154
|
+
- lib/whoops_rails_notifier.rb
|
155
|
+
- MIT-LICENSE
|
156
|
+
- Rakefile
|
157
|
+
- Gemfile
|
158
|
+
- README.rdoc
|
159
|
+
has_rdoc: true
|
160
|
+
homepage:
|
161
|
+
licenses: []
|
162
|
+
|
163
|
+
post_install_message:
|
164
|
+
rdoc_options: []
|
165
|
+
|
166
|
+
require_paths:
|
167
|
+
- lib
|
168
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
hash: 3
|
174
|
+
segments:
|
175
|
+
- 0
|
176
|
+
version: "0"
|
177
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
|
+
none: false
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
hash: 3
|
183
|
+
segments:
|
184
|
+
- 0
|
185
|
+
version: "0"
|
186
|
+
requirements: []
|
187
|
+
|
188
|
+
rubyforge_project:
|
189
|
+
rubygems_version: 1.3.7
|
190
|
+
signing_key:
|
191
|
+
specification_version: 3
|
192
|
+
summary: A Whoops Notifier for Rails 3 apps.
|
193
|
+
test_files: []
|
194
|
+
|