rack_hoptoad 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +20 -0
- data/Rakefile +2 -2
- data/lib/rack/hoptoad_notifier.rb +42 -53
- data/lib/rack/notice.xml.erb +36 -0
- data/lib/rack_hoptoad.rb +1 -1
- metadata +8 -6
data/README.md
CHANGED
@@ -11,6 +11,15 @@ Throw something like this in your config.ru to enable notifications.
|
|
11
11
|
|
12
12
|
use Rack::HoptoadNotifier, 'fd48c7d26f724503a0280f808f44b339fc65fab8'
|
13
13
|
|
14
|
+
You can also exclude certain sensitive environmental variables using the block syntax
|
15
|
+
|
16
|
+
require 'rack_hoptoad'
|
17
|
+
|
18
|
+
use Rack::HoptoadNotifier, 'fd48c7d26f724503a0280f808f44b339fc65fab8' do |notifier|
|
19
|
+
notifier.environment_filters << %w(MY_SECRET_KEY MY_SECRET_TOKEN)
|
20
|
+
end
|
21
|
+
|
22
|
+
|
14
23
|
If your RACK_ENV variable is set to production or staging it'll actually post
|
15
24
|
to hoptoad. It won't process in the other environments.
|
16
25
|
|
@@ -18,3 +27,14 @@ Installation
|
|
18
27
|
============
|
19
28
|
|
20
29
|
% sudo gem install rack_hoptoad
|
30
|
+
|
31
|
+
Sinatra Notes
|
32
|
+
=============
|
33
|
+
|
34
|
+
In order for exceptions to propagate up to Rack in Sinatra you need to enable raise_errors
|
35
|
+
|
36
|
+
class MyApp < Sinatra::Default
|
37
|
+
enable :raise_errors
|
38
|
+
end
|
39
|
+
|
40
|
+
Note that the errors block does not execute so you'll need to handle the 500 elsewhere.
|
data/Rakefile
CHANGED
@@ -5,10 +5,10 @@ require 'spec/rake/spectask'
|
|
5
5
|
require 'date'
|
6
6
|
|
7
7
|
GEM = "rack_hoptoad"
|
8
|
-
GEM_VERSION = "0.0.
|
8
|
+
GEM_VERSION = "0.0.4"
|
9
9
|
AUTHOR = "Corey Donohoe"
|
10
10
|
EMAIL = "atmos@atmos.org"
|
11
|
-
HOMEPAGE = "http://
|
11
|
+
HOMEPAGE = "http://rubyforge.org/projects/rackhoptoad/"
|
12
12
|
SUMMARY = "A gem that provides hoptoad notifications from rack"
|
13
13
|
|
14
14
|
spec = Gem::Specification.new do |s|
|
@@ -9,6 +9,7 @@ module Rack
|
|
9
9
|
def initialize(app, api_key = nil)
|
10
10
|
@app = app
|
11
11
|
@api_key = api_key
|
12
|
+
@environment_filters = %w(AWS_ACCESS_KEY AWS_SECRET_ACCESS_KEY AWS_ACCOUNT SSH_AUTH_SOCK)
|
12
13
|
yield self if block_given?
|
13
14
|
end
|
14
15
|
|
@@ -26,36 +27,37 @@ module Rack
|
|
26
27
|
[status, headers, body]
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
@environment_filters ||= %w(AWS_ACCESS_KEY AWS_SECRET_ACCESS_KEY AWS_ACCOUNT SSH_AUTH_SOCK)
|
30
|
+
def environment_filter_keys
|
31
|
+
@environment_filters.flatten
|
32
32
|
end
|
33
|
+
private
|
33
34
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
:error_class => exception.class.name,
|
38
|
-
:error_message => "#{exception.class.name}: #{exception.message}",
|
39
|
-
:backtrace => exception.backtrace,
|
40
|
-
:environment => env.to_hash
|
41
|
-
}
|
35
|
+
def notice_template
|
36
|
+
::File.read(::File.join(::File.dirname(__FILE__), 'notice.xml.erb'))
|
37
|
+
end
|
42
38
|
|
43
|
-
|
39
|
+
INPUT_FORMAT = %r{^([^:]+):(\d+)(?::in `([^']+)')?$}.freeze
|
44
40
|
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
class Backtrace < Struct.new(:file, :number, :method); end
|
42
|
+
def build_backtrace(exception)
|
43
|
+
exception.backtrace.map do |line|
|
44
|
+
_, file, number, method = line.match(INPUT_FORMAT).to_a
|
45
|
+
Backtrace.new(file, number, method)
|
46
|
+
end
|
47
|
+
end
|
48
48
|
|
49
|
-
|
50
|
-
|
49
|
+
def send_notification(exception, env)
|
50
|
+
@error = exception
|
51
|
+
@api_key = api_key
|
52
|
+
@request = Rack::Request.new(env)
|
53
|
+
@request_path = @request.script_name + @request.path_info
|
54
|
+
@environment = clean_hoptoad_environment(ENV.to_hash.merge(env))
|
55
|
+
@backtrace = build_backtrace(exception)
|
51
56
|
|
52
|
-
|
53
|
-
:key => env['rack.session'] || 42,
|
54
|
-
:data => env['rack.session'] || { }
|
55
|
-
}
|
57
|
+
document = ERB.new(notice_template).result(binding)
|
56
58
|
|
57
59
|
if %w(staging production).include?(ENV['RACK_ENV'])
|
58
|
-
send_to_hoptoad
|
60
|
+
send_to_hoptoad document
|
59
61
|
end
|
60
62
|
env['hoptoad.notified'] = true
|
61
63
|
end
|
@@ -68,18 +70,19 @@ module Rack
|
|
68
70
|
end
|
69
71
|
|
70
72
|
def send_to_hoptoad(data) #:nodoc:
|
71
|
-
url = URI.parse("http://hoptoadapp.com:80/notices
|
73
|
+
url = URI.parse("http://hoptoadapp.com:80/notifier_api/v2/notices")
|
72
74
|
|
73
75
|
Net::HTTP.start(url.host, url.port) do |http|
|
74
76
|
headers = {
|
75
|
-
'Content-type' => '
|
76
|
-
'Accept'
|
77
|
+
'Content-type' => 'text/xml',
|
78
|
+
'Accept' => 'text/xml, application/xml'
|
77
79
|
}
|
80
|
+
|
78
81
|
http.read_timeout = 5 # seconds
|
79
82
|
http.open_timeout = 2 # seconds
|
80
83
|
# http.use_ssl = HoptoadNotifier.secure
|
81
84
|
response = begin
|
82
|
-
http.post(url.path,
|
85
|
+
http.post(url.path, data, headers)
|
83
86
|
rescue TimeoutError => e
|
84
87
|
logger "Timeout while contacting the Hoptoad server."
|
85
88
|
nil
|
@@ -97,17 +100,6 @@ module Rack
|
|
97
100
|
puts str if ENV['RACK_DEBUG']
|
98
101
|
end
|
99
102
|
|
100
|
-
def default_notice_options #:nodoc:
|
101
|
-
{
|
102
|
-
:api_key => api_key,
|
103
|
-
:error_message => 'Notification',
|
104
|
-
:backtrace => nil,
|
105
|
-
:request => {},
|
106
|
-
:session => {},
|
107
|
-
:environment => {}
|
108
|
-
}
|
109
|
-
end
|
110
|
-
|
111
103
|
def clean_non_serializable_data(notice) #:nodoc:
|
112
104
|
notice.select{|k,v| serializable?(v) }.inject({}) do |h, pair|
|
113
105
|
h[pair.first] = pair.last.is_a?(Hash) ? clean_non_serializable_data(pair.last) : pair.last
|
@@ -115,27 +107,24 @@ module Rack
|
|
115
107
|
end
|
116
108
|
end
|
117
109
|
|
118
|
-
def
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
value.is_a?(Hash) ||
|
123
|
-
value.is_a?(Bignum)
|
110
|
+
def clean_hoptoad_environment(environment) #:nodoc:
|
111
|
+
clean_non_serializable_data(environment).each do |key, value|
|
112
|
+
environment[key] = "[FILTERED]" if filter?(key)
|
113
|
+
end
|
124
114
|
end
|
125
115
|
|
126
|
-
def
|
127
|
-
|
128
|
-
|
129
|
-
h
|
116
|
+
def filter?(key)
|
117
|
+
environment_filter_keys.any? do |filter|
|
118
|
+
key.to_s.match(/#{filter}/)
|
130
119
|
end
|
131
120
|
end
|
132
121
|
|
133
|
-
def
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
122
|
+
def serializable?(value) #:nodoc:
|
123
|
+
value.is_a?(Fixnum) ||
|
124
|
+
value.is_a?(Array) ||
|
125
|
+
value.is_a?(String) ||
|
126
|
+
value.is_a?(Hash) ||
|
127
|
+
value.is_a?(Bignum)
|
139
128
|
end
|
140
129
|
end
|
141
130
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<notice version="2.0.0">
|
3
|
+
<api-key><%= @api_key %></api-key>
|
4
|
+
<notifier>
|
5
|
+
<name>Rack Hoptoad Notifier</name>
|
6
|
+
<version>0.0.4</version>
|
7
|
+
<url>http://github.com//atmos/rack_hoptoad</url>
|
8
|
+
</notifier>
|
9
|
+
<error>
|
10
|
+
<class><%= @error.class.name %></class>
|
11
|
+
<message><%= @error.message %></message>
|
12
|
+
<backtrace>
|
13
|
+
<% @backtrace.each do |line| %>
|
14
|
+
<line method="<%= line.method %>" file="<%= line.file %>" number="<%= line.number %>"/>
|
15
|
+
<% end %>
|
16
|
+
</backtrace>
|
17
|
+
</error>
|
18
|
+
<request>
|
19
|
+
<url><%= @request_path %></url>
|
20
|
+
<component><%= @request_path %></component>
|
21
|
+
<params>
|
22
|
+
<% @request.params.each do |key,value| %>
|
23
|
+
<var key="<%= key %>"><%= value %></var>
|
24
|
+
<% end %>
|
25
|
+
</params>
|
26
|
+
<cgi-data>
|
27
|
+
<% @environment.each do |key,value| %>
|
28
|
+
<var key="<%= key %>"><%= value %></var>
|
29
|
+
<% end %>
|
30
|
+
</cgi-data>
|
31
|
+
</request>
|
32
|
+
<server-environment>
|
33
|
+
<project-root><%= Dir.pwd %></project-root>
|
34
|
+
<environment-name><%= ENV['RACK_ENV'] || 'development' %></environment-name>
|
35
|
+
</server-environment>
|
36
|
+
</notice>
|
data/lib/rack_hoptoad.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack_hoptoad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corey Donohoe
|
@@ -9,7 +9,7 @@ autorequire: rack_hoptoad
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-21 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -36,11 +36,13 @@ files:
|
|
36
36
|
- README.md
|
37
37
|
- Rakefile
|
38
38
|
- TODO
|
39
|
-
- lib/rack
|
40
39
|
- lib/rack/hoptoad_notifier.rb
|
40
|
+
- lib/rack/notice.xml.erb
|
41
41
|
- lib/rack_hoptoad.rb
|
42
42
|
has_rdoc: true
|
43
|
-
homepage: http://
|
43
|
+
homepage: http://rubyforge.org/projects/rackhoptoad/
|
44
|
+
licenses: []
|
45
|
+
|
44
46
|
post_install_message:
|
45
47
|
rdoc_options: []
|
46
48
|
|
@@ -61,9 +63,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
63
|
requirements: []
|
62
64
|
|
63
65
|
rubyforge_project:
|
64
|
-
rubygems_version: 1.3.
|
66
|
+
rubygems_version: 1.3.5
|
65
67
|
signing_key:
|
66
|
-
specification_version:
|
68
|
+
specification_version: 3
|
67
69
|
summary: A gem that provides hoptoad notifications from rack
|
68
70
|
test_files: []
|
69
71
|
|