bugsnag 1.0.3 → 1.0.4
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/VERSION +1 -1
- data/bugsnag.gemspec +3 -2
- data/lib/bugsnag.rb +26 -2
- data/lib/bugsnag/configuration.rb +2 -1
- data/lib/bugsnag/notification.rb +12 -9
- data/lib/bugsnag/rack.rb +2 -2
- data/lib/bugsnag/rails/action_controller_rescue.rb +4 -6
- data/lib/bugsnag/rails/controller_methods.rb +5 -15
- data/lib/bugsnag/resque.rb +19 -0
- metadata +5 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.4
|
data/bugsnag.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "bugsnag"
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["James Smith"]
|
12
|
-
s.date = "2012-01-
|
12
|
+
s.date = "2012-01-16"
|
13
13
|
s.description = "Ruby notifier for bugsnag.com"
|
14
14
|
s.email = "james@bugsnag.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
|
|
34
34
|
"lib/bugsnag/rails/action_controller_rescue.rb",
|
35
35
|
"lib/bugsnag/rails/controller_methods.rb",
|
36
36
|
"lib/bugsnag/railtie.rb",
|
37
|
+
"lib/bugsnag/resque.rb",
|
37
38
|
"lib/bugsnag/version.rb",
|
38
39
|
"rails/init.rb",
|
39
40
|
"test/helper.rb",
|
data/lib/bugsnag.rb
CHANGED
@@ -12,20 +12,44 @@ module Bugsnag
|
|
12
12
|
LOG_PREFIX = "** [Bugsnag] "
|
13
13
|
|
14
14
|
class << self
|
15
|
+
# Configure the gem to send notifications, at the very least an api_key is required
|
15
16
|
def configure
|
16
|
-
yield(configuration)
|
17
|
-
|
17
|
+
yield(configuration)
|
18
|
+
|
19
|
+
# Use resque for asynchronous notification if required
|
20
|
+
require "bugsnag/resque" if configuration.use_resque && defined?(Resque)
|
21
|
+
|
22
|
+
# Log that we are ready to rock
|
23
|
+
if configuration.api_key && !@logged_ready
|
24
|
+
log "Bugsnag exception handler #{VERSION} ready, api_key=#{configuration.api_key}"
|
25
|
+
@logged_ready = true
|
26
|
+
end
|
18
27
|
end
|
19
28
|
|
29
|
+
# Explicitly notify of an exception
|
20
30
|
def notify(exception, session_data={})
|
31
|
+
Notification.new(exception, configuration.merge(session_data)).deliver
|
32
|
+
end
|
33
|
+
|
34
|
+
# Notify of an exception unless it should be ignored
|
35
|
+
def notify_or_ignore(exception, session_data={})
|
21
36
|
notification = Notification.new(exception, configuration.merge(session_data))
|
22
37
|
notification.deliver unless notification.ignore?
|
23
38
|
end
|
24
39
|
|
40
|
+
# Auto notify of an exception, called from rails and rack exception
|
41
|
+
# rescuers, unless auto notification is disabled, or we should ignore this
|
42
|
+
# error class
|
43
|
+
def auto_notify(exception, session_data={})
|
44
|
+
notify_or_ignore(exception, session_data) unless configuration.disable_auto_notification
|
45
|
+
end
|
46
|
+
|
47
|
+
# Log wrapper
|
25
48
|
def log(message)
|
26
49
|
configuration.logger.info(LOG_PREFIX + message) if configuration.logger
|
27
50
|
end
|
28
51
|
|
52
|
+
# Configuration getter
|
29
53
|
def configuration
|
30
54
|
@configuration ||= Bugsnag::Configuration.new
|
31
55
|
end
|
@@ -3,7 +3,8 @@ module Bugsnag
|
|
3
3
|
OPTIONS = [
|
4
4
|
:api_key, :release_stage, :project_root, :app_version,
|
5
5
|
:framework, :endpoint, :logger, :disable_auto_notification,
|
6
|
-
:params_filters, :stacktrace_filters, :ignore_classes
|
6
|
+
:params_filters, :stacktrace_filters, :ignore_classes,
|
7
|
+
:use_resque
|
7
8
|
]
|
8
9
|
OPTIONS.each {|o| attr_accessor o }
|
9
10
|
|
data/lib/bugsnag/notification.rb
CHANGED
@@ -23,6 +23,15 @@ module Bugsnag
|
|
23
23
|
:ignore_classes, :endpoint, :app_version, :release_stage,
|
24
24
|
:project_root
|
25
25
|
|
26
|
+
|
27
|
+
def self.deliver_exception_payload(endpoint, payload_string)
|
28
|
+
begin
|
29
|
+
response = post(endpoint, {:body => payload_string})
|
30
|
+
rescue Exception => e
|
31
|
+
Bugsnag.log("Notification to #{self.endpoint} failed, #{e.inspect}")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
26
35
|
def initialize(exception, opts={})
|
27
36
|
self.exception = exception
|
28
37
|
opts.reject! {|k,v| v.nil?}.each do |k,v|
|
@@ -46,13 +55,7 @@ module Bugsnag
|
|
46
55
|
}.reject {|k,v| v.nil? }]
|
47
56
|
}
|
48
57
|
|
49
|
-
|
50
|
-
response = self.class.post(self.endpoint, {:body => MultiJson.encode(payload)})
|
51
|
-
rescue Exception => e
|
52
|
-
Bugsnag.log("Notification to #{self.endpoint} failed, #{e.inspect}")
|
53
|
-
end
|
54
|
-
|
55
|
-
return response
|
58
|
+
self.class.deliver_exception_payload(self.endpoint, MultiJson.encode(payload))
|
56
59
|
end
|
57
60
|
|
58
61
|
def ignore?
|
@@ -74,8 +77,8 @@ module Bugsnag
|
|
74
77
|
end
|
75
78
|
|
76
79
|
def stacktrace_hash
|
77
|
-
|
78
|
-
|
80
|
+
stacktrace = self.exception.backtrace || caller
|
81
|
+
stacktrace.map do |trace|
|
79
82
|
method = nil
|
80
83
|
file, line_str, method_str = trace.split(":")
|
81
84
|
|
data/lib/bugsnag/rack.rb
CHANGED
@@ -8,12 +8,12 @@ module Bugsnag
|
|
8
8
|
begin
|
9
9
|
response = @app.call(env)
|
10
10
|
rescue Exception => raised
|
11
|
-
|
11
|
+
Bugsnag.auto_notify(raised, bugsnag_request_data(env))
|
12
12
|
raise
|
13
13
|
end
|
14
14
|
|
15
15
|
if env['rack.exception']
|
16
|
-
|
16
|
+
Bugsnag.auto_notify(env['rack.exception'], bugsnag_request_data(env))
|
17
17
|
end
|
18
18
|
|
19
19
|
response
|
@@ -11,18 +11,16 @@ module Bugsnag
|
|
11
11
|
|
12
12
|
private
|
13
13
|
def rescue_action_in_public_with_bugsnag(exception)
|
14
|
-
|
14
|
+
# bugsnag_request_data is defined in controller_methods.rb
|
15
|
+
Bugsnag.auto_notify(exception, bugsnag_request_data)
|
15
16
|
rescue_action_in_public_without_bugsnag(exception)
|
16
17
|
end
|
17
18
|
|
18
19
|
def rescue_action_locally_with_bugsnag(exception)
|
19
|
-
|
20
|
+
# bugsnag_request_data is defined in controller_methods.rb
|
21
|
+
Bugsnag.auto_notify(exception, bugsnag_request_data)
|
20
22
|
rescue_action_locally_without_bugsnag(exception)
|
21
23
|
end
|
22
|
-
|
23
|
-
def auto_notify(exception)
|
24
|
-
notify_bugsnag(exception)
|
25
|
-
end
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
@@ -3,11 +3,9 @@ module Bugsnag
|
|
3
3
|
module ControllerMethods
|
4
4
|
private
|
5
5
|
def notify_bugsnag(exception, custom_data=nil)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
Bugsnag.notify(exception, request_data)
|
10
|
-
end
|
6
|
+
request_data = bugsnag_request_data
|
7
|
+
request_data[:meta_data][:custom] = custom_data if custom_data
|
8
|
+
Bugsnag.notify(exception, request_data)
|
11
9
|
end
|
12
10
|
|
13
11
|
def bugsnag_request_data
|
@@ -19,22 +17,14 @@ module Bugsnag
|
|
19
17
|
:url => bugsnag_request_url,
|
20
18
|
:controller => params[:controller],
|
21
19
|
:action => params[:action],
|
22
|
-
:params => bugsnag_filter_if_filtering(params.to_hash),
|
20
|
+
:params => bugsnag_filter_if_filtering(Bugsnag::Helpers.cleanup_hash(params.to_hash)),
|
23
21
|
},
|
24
|
-
:session => bugsnag_filter_if_filtering(bugsnag_session_data),
|
22
|
+
:session => bugsnag_filter_if_filtering(Bugsnag::Helpers.cleanup_hash(bugsnag_session_data)),
|
25
23
|
:environment => bugsnag_filter_if_filtering(Bugsnag::Helpers.cleanup_hash(request.env))
|
26
24
|
}
|
27
25
|
}
|
28
26
|
end
|
29
27
|
|
30
|
-
def bugsnag_local_request?
|
31
|
-
if defined?(::Rails.application.config)
|
32
|
-
::Rails.application.config.consider_all_requests_local || request.local?
|
33
|
-
else
|
34
|
-
consider_all_requests_local || local_request?
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
28
|
def bugsnag_session_id
|
39
29
|
session = bugsnag_session_data
|
40
30
|
session[:session_id] || session["session_id"]
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Bugsnag
|
2
|
+
class Resque
|
3
|
+
@queue = "bugsnag"
|
4
|
+
def self.perform(*args)
|
5
|
+
Bugsnag::Notification.deliver_exception_payload_without_resque(*args)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
Bugsnag::Notification.class_eval do
|
11
|
+
class << self
|
12
|
+
def deliver_exception_payload_with_resque(*args)
|
13
|
+
Resque.enqueue(Bugsnag::Resque, *args)
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method :deliver_exception_payload_without_resque, :deliver_exception_payload
|
17
|
+
alias_method :deliver_exception_payload, :deliver_exception_payload_with_resque
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bugsnag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 4
|
10
|
+
version: 1.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- James Smith
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-01-
|
18
|
+
date: 2012-01-16 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
prerelease: false
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- lib/bugsnag/rails/action_controller_rescue.rb
|
133
133
|
- lib/bugsnag/rails/controller_methods.rb
|
134
134
|
- lib/bugsnag/railtie.rb
|
135
|
+
- lib/bugsnag/resque.rb
|
135
136
|
- lib/bugsnag/version.rb
|
136
137
|
- rails/init.rb
|
137
138
|
- test/helper.rb
|