rack_bugzscout 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack_bugzscout.rb +56 -8
- metadata +1 -1
data/lib/rack_bugzscout.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bugzscout'
|
3
|
+
require 'erb'
|
3
4
|
|
4
5
|
module Rack
|
5
6
|
# Catches all exceptions raised, and submits them to FogBugz via BugzScout.
|
@@ -13,6 +14,8 @@ module Rack
|
|
13
14
|
@fogbugz_user = fogbugz_user
|
14
15
|
@fogbugz_project = fogbugz_project
|
15
16
|
@fogbugz_area = fogbugz_area
|
17
|
+
|
18
|
+
@template = ERB.new(TEMPLATE)
|
16
19
|
end
|
17
20
|
|
18
21
|
def call(env)
|
@@ -28,23 +31,68 @@ module Rack
|
|
28
31
|
end
|
29
32
|
|
30
33
|
private
|
34
|
+
|
35
|
+
def generate_report(exception, env)
|
36
|
+
FogBugz::BugzScout.submit(@fogbugz_url) do |scout|
|
37
|
+
scout.user = @fogbugz_user
|
38
|
+
scout.project = @fogbugz_project
|
39
|
+
scout.area = @fogbugz_area
|
40
|
+
scout.title = exception.to_s
|
41
|
+
scout.body = @template.result(binding)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
31
45
|
def send_notification(exception, env)
|
32
46
|
# wrapping this so we can avoid sending these up the chain
|
33
47
|
# not entirely sure that this is the right thing to do...
|
34
48
|
begin
|
35
49
|
if %w(staging production).include?(ENV['RACK_ENV'])
|
36
|
-
|
37
|
-
scout.user = @fogbugz_user
|
38
|
-
scout.project = @fogbugz_project
|
39
|
-
scout.area = @fogbugz_area
|
40
|
-
scout.title = exception.class.name
|
41
|
-
scout.body = exception.message
|
42
|
-
end
|
50
|
+
generate_report(exception, env)
|
43
51
|
env['bugzscout.submitted'] = true
|
44
52
|
end
|
45
53
|
rescue => error
|
46
|
-
# maybe we ought to log something here?
|
54
|
+
# maybe we ought to log something here if things don't work out?
|
47
55
|
end
|
48
56
|
end
|
57
|
+
|
58
|
+
def extract_body(env)
|
59
|
+
if io = env['rack.input']
|
60
|
+
io.rewind if io.respond_to?(:rewind)
|
61
|
+
io.read
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
TEMPLATE = (<<-'REPORT').gsub(/^ {4}/, '')
|
66
|
+
A <%= exception.class.to_s %> occured: <%= exception.to_s %>
|
67
|
+
<% if body = extract_body(env) %>
|
68
|
+
|
69
|
+
====================
|
70
|
+
Request Body:
|
71
|
+
====================
|
72
|
+
|
73
|
+
<%= body.gsub(/^/, ' ') %>
|
74
|
+
<% end %>
|
75
|
+
|
76
|
+
====================
|
77
|
+
Rack Environment:
|
78
|
+
====================
|
79
|
+
|
80
|
+
PID: <%= $$ %>
|
81
|
+
PWD: <%= Dir.getwd %>
|
82
|
+
|
83
|
+
<%= env.to_a.
|
84
|
+
sort{|a,b| a.first <=> b.first}.
|
85
|
+
map{ |k,v| "%-25s%p" % [k+':', v] }.
|
86
|
+
join("\n ") %>
|
87
|
+
|
88
|
+
<% if exception.respond_to?(:backtrace) %>
|
89
|
+
====================
|
90
|
+
Backtrace:
|
91
|
+
====================
|
92
|
+
|
93
|
+
<%= exception.backtrace.join("\n ") %>
|
94
|
+
<% end %>
|
95
|
+
REPORT
|
96
|
+
|
49
97
|
end
|
50
98
|
end
|