bugsnag 1.1.5 → 1.2.0.beta

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.
@@ -1,70 +1,55 @@
1
+ require "bugsnag/middleware/rack_request"
2
+ require "bugsnag/middleware/warden_user"
3
+ require "bugsnag/middleware/callbacks"
4
+
1
5
  module Bugsnag
2
6
  class Rack
3
7
  def initialize(app)
4
8
  @app = app
5
9
 
6
- # Automatically set the release_stage
7
- Bugsnag.configuration.release_stage = ENV['RACK_ENV'] if ENV['RACK_ENV']
8
-
9
- # Automatically set the project_root if possible
10
- if Bugsnag.configuration.project_root.nil? || Bugsnag.configuration.project_root.empty?
11
- if defined?(settings)
12
- Bugsnag.configuration.project_root = settings.root
13
- else
14
- caller.each do |c|
15
- if c =~ /[\/\\]config.ru$/
16
- Bugsnag.configuration.project_root = File.dirname(c.split(":").first)
17
- break
18
- end
10
+ # Configure bugsnag rack defaults
11
+ Bugsnag.configure do |config|
12
+ # Try to set the release_stage automatically if it hasn't already been set
13
+ config.release_stage ||= ENV["RACK_ENV"] if ENV["RACK_ENV"]
14
+
15
+ # Try to set the project_root if it hasn't already been set, or show a warning if we can't
16
+ unless config.project_root && !config.project_root.empty?
17
+ if defined?(settings)
18
+ config.project_root = settings.root
19
+ else
20
+ Bugsnag.warn("You should set your app's project_root (see https://bugsnag.com/docs/notifiers/ruby#project_root).")
19
21
  end
20
22
  end
23
+
24
+ # Hook up rack-based notification middlewares
25
+ config.middleware.use Bugsnag::Middleware::RackRequest
26
+ config.middleware.use Bugsnag::Middleware::WardenUser if defined?(Warden)
21
27
  end
22
28
  end
23
29
 
24
30
  def call(env)
31
+ # Set the request data for bugsnag middleware to use
32
+ Bugsnag.set_request_data(:rack_env, env)
33
+
25
34
  begin
26
35
  response = @app.call(env)
27
36
  rescue Exception => raised
28
- Bugsnag.auto_notify(raised, self.class.bugsnag_request_data(env))
37
+ # Notify bugsnag of rack exceptions
38
+ Bugsnag.auto_notify(raised)
39
+
40
+ # Re-raise the exception
29
41
  raise
30
42
  end
31
43
 
32
- if env['rack.exception']
33
- Bugsnag.auto_notify(env['rack.exception'], self.class.bugsnag_request_data(env))
44
+ # Notify bugsnag of rack exceptions
45
+ if env["rack.exception"]
46
+ Bugsnag.auto_notify(env["rack.exception"])
34
47
  end
35
-
48
+
36
49
  response
37
- end
38
-
39
- class << self
40
- def bugsnag_request_data(env)
41
- request = ::Rack::Request.new(env)
42
-
43
- session = env["rack.session"]
44
- params = env["action_dispatch.request.parameters"] || request.params
45
- user_id = session[:session_id] || session["session_id"] rescue nil
46
-
47
- {
48
- :user_id => user_id,
49
- :context => Bugsnag::Helpers.param_context(params) || Bugsnag::Helpers.request_context(request),
50
- :meta_data => {
51
- :request => {
52
- :url => request.url,
53
- :controller => params[:controller],
54
- :action => params[:action],
55
- :params => bugsnag_filter_if_filtering(env, Bugsnag::Helpers.cleanup_hash(params.to_hash)),
56
- },
57
- :session => bugsnag_filter_if_filtering(env, Bugsnag::Helpers.cleanup_hash(session)),
58
- :environment => bugsnag_filter_if_filtering(env, Bugsnag::Helpers.cleanup_hash(env))
59
- }
60
- }
61
- end
62
-
63
- private
64
- def bugsnag_filter_if_filtering(env, hash)
65
- @params_filters ||= env["action_dispatch.parameter_filter"]
66
- Bugsnag::Helpers.apply_filters(hash, @params_filters)
67
- end
50
+ ensure
51
+ # Clear per-request data after processing the each request
52
+ Bugsnag.clear_request_data
68
53
  end
69
54
  end
70
- end
55
+ end
@@ -1,8 +1,11 @@
1
- # Rails 2.x support
1
+ # Rails 2.x hooks
2
+ # For Rails 3+ hooks, see railtie.rb
2
3
 
3
4
  require "bugsnag"
4
5
  require "bugsnag/rails/controller_methods"
5
6
  require "bugsnag/rails/action_controller_rescue"
7
+ require "bugsnag/middleware/rails2_request"
8
+ require "bugsnag/middleware/callbacks"
6
9
 
7
10
  module Bugsnag
8
11
  module Rails
@@ -21,11 +24,17 @@ module Bugsnag
21
24
  end
22
25
 
23
26
  Bugsnag.configure do |config|
24
- config.logger = rails_logger
27
+ config.logger ||= rails_logger
25
28
  config.release_stage = RAILS_ENV if defined?(RAILS_ENV)
26
29
  config.project_root = RAILS_ROOT if defined?(RAILS_ROOT)
27
- config.framework = "Rails: #{::Rails::VERSION::STRING}" if defined?(::Rails::VERSION)
30
+
31
+ config.middleware.use Bugsnag::Middleware::Rails2Request
28
32
  end
33
+
34
+ # Auto-load configuration settings from config/bugsnag.yml if it exists
35
+ config_file = File.join(RAILS_ROOT, "config", "bugsnag.yml")
36
+ config = YAML.load_file(config_file) if File.exists?(config_file)
37
+ Bugsnag.configure(config[RAILS_ENV] ? config[RAILS_ENV] : config) if config
29
38
  end
30
39
  end
31
40
  end
@@ -1,26 +1,38 @@
1
- module Bugsnag
2
- module Rails
3
- module ActionControllerRescue
4
- def self.included(base)
5
- base.send(:alias_method, :rescue_action_in_public_without_bugsnag, :rescue_action_in_public)
6
- base.send(:alias_method, :rescue_action_in_public, :rescue_action_in_public_with_bugsnag)
1
+ # Rails 2.x only
2
+ module Bugsnag::Rails
3
+ module ActionControllerRescue
4
+ def self.included(base)
5
+ # Hook into rails exception rescue stack
6
+ base.send(:alias_method, :rescue_action_in_public_without_bugsnag, :rescue_action_in_public)
7
+ base.send(:alias_method, :rescue_action_in_public, :rescue_action_in_public_with_bugsnag)
7
8
 
8
- base.send(:alias_method, :rescue_action_locally_without_bugsnag, :rescue_action_locally)
9
- base.send(:alias_method, :rescue_action_locally, :rescue_action_locally_with_bugsnag)
10
- end
9
+ base.send(:alias_method, :rescue_action_locally_without_bugsnag, :rescue_action_locally)
10
+ base.send(:alias_method, :rescue_action_locally, :rescue_action_locally_with_bugsnag)
11
11
 
12
- private
13
- def rescue_action_in_public_with_bugsnag(exception)
14
- # bugsnag_request_data is defined in controller_methods.rb
15
- Bugsnag.auto_notify(exception, bugsnag_request_data)
16
- rescue_action_in_public_without_bugsnag(exception)
17
- end
18
-
19
- def rescue_action_locally_with_bugsnag(exception)
20
- # bugsnag_request_data is defined in controller_methods.rb
21
- Bugsnag.auto_notify(exception, bugsnag_request_data)
22
- rescue_action_locally_without_bugsnag(exception)
23
- end
12
+ # Run filters on requests to capture request data
13
+ base.send(:before_filter, :set_bugsnag_request_data)
14
+ base.send(:after_filter, :clear_bugsnag_request_data)
15
+ end
16
+
17
+ private
18
+ def set_bugsnag_request_data
19
+ Bugsnag.set_request_data(:rails2_request, request)
20
+ end
21
+
22
+ def clear_bugsnag_request_data
23
+ Bugsnag.clear_request_data
24
+ end
25
+
26
+ def rescue_action_in_public_with_bugsnag(exception)
27
+ Bugsnag.auto_notify(exception)
28
+
29
+ rescue_action_in_public_without_bugsnag(exception)
30
+ end
31
+
32
+ def rescue_action_locally_with_bugsnag(exception)
33
+ Bugsnag.auto_notify(exception)
34
+
35
+ rescue_action_locally_without_bugsnag(exception)
24
36
  end
25
37
  end
26
38
  end
@@ -1,64 +1,48 @@
1
- module Bugsnag
2
- module Rails
3
- module ControllerMethods
4
- private
5
- def notify_bugsnag(exception, custom_data=nil)
6
- request_data = bugsnag_request_data
7
- request_data[:meta_data][:custom] = custom_data if custom_data
8
- Bugsnag.notify(exception, request_data)
1
+ module Bugsnag::Rails
2
+ module ControllerMethods
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ private
9
+ def before_bugsnag_notify(*methods, &block)
10
+ _add_bugsnag_notify_callback(:rails_before_callbacks, *methods, &block)
9
11
  end
10
12
 
11
- def bugsnag_request_data
12
- {
13
- :user_id => bugsnag_session_id,
14
- :context => Bugsnag::Helpers.param_context(params),
15
- :meta_data => {
16
- :request => {
17
- :url => bugsnag_request_url,
18
- :controller => params[:controller],
19
- :action => params[:action],
20
- :params => bugsnag_filter_if_filtering(Bugsnag::Helpers.cleanup_hash(params.to_hash)),
21
- },
22
- :session => bugsnag_filter_if_filtering(Bugsnag::Helpers.cleanup_hash(bugsnag_session_data)),
23
- :environment => bugsnag_filter_if_filtering(Bugsnag::Helpers.cleanup_hash(request.env))
24
- }
25
- }
13
+ def after_bugsnag_notify(*methods, &block)
14
+ _add_bugsnag_notify_callback(:rails_after_callbacks, *methods, &block)
26
15
  end
27
16
 
28
- def bugsnag_session_id
29
- session = bugsnag_session_data
30
- session[:session_id] || session["session_id"]
31
- end
32
-
33
- def bugsnag_request_url
34
- url = "#{request.protocol}#{request.host}"
17
+ def _add_bugsnag_notify_callback(callback_key, *methods, &block)
18
+ options = methods.last.is_a?(Hash) ? methods.pop : {}
35
19
 
36
- unless [80, 443].include?(request.port)
37
- url << ":#{request.port}"
38
- end
20
+ before_filter(options) do |controller|
21
+ request_data = Bugsnag.configuration.request_data
22
+ request_data[callback_key] ||= []
39
23
 
40
- url << request.fullpath
41
- url
42
- end
24
+ # Set up "method symbol" callbacks
25
+ methods.each do |method_symbol|
26
+ request_data[callback_key] << lambda { |notification|
27
+ self.send(method_symbol, notification)
28
+ }
29
+ end
43
30
 
44
- def bugsnag_session_data
45
- if session.respond_to?(:to_hash)
46
- session.to_hash
47
- else
48
- session.data
31
+ # Set up "block" callbacks
32
+ request_data[callback_key] << lambda { |notification|
33
+ controller.instance_exec(notification, &block)
34
+ } if block_given?
49
35
  end
50
36
  end
51
-
52
- def bugsnag_filter_if_filtering(hash)
53
- return hash if ! hash.is_a?(Hash)
37
+ end
54
38
 
55
- if respond_to?(:filter_parameters)
56
- filter_parameters(hash) rescue hash
57
- else
58
- hash
59
- end
60
- end
39
+ private
40
+ def notify_bugsnag(exception, custom_data=nil)
41
+ Bugsnag.warn "DEPRECATED METHOD: notify_bugsnag is deprecated and will be removed in the future. Please use Bugsnag.notify instead" if Bugsnag.configuration.release_stage != "production"
61
42
 
43
+ overrides = {}
44
+ overrides[:custom] = custom_data if custom_data
45
+ Bugsnag.notify(exception, overrides)
62
46
  end
63
47
  end
64
48
  end
@@ -1,12 +1,33 @@
1
- # Rails 3.x support
1
+ # Rails 3.x hooks
2
2
 
3
- require "bugsnag"
4
3
  require "rails"
4
+ require "bugsnag"
5
+ require "bugsnag/middleware/rails3_request"
5
6
 
6
7
  module Bugsnag
7
8
  class Railtie < Rails::Railtie
8
9
  rake_tasks do
9
- load "tasks/bugsnag.rake"
10
+ load "bugsnag/tasks/bugsnag.rake"
11
+ end
12
+
13
+ config.before_initialize do
14
+ # Configure bugsnag rails defaults
15
+ Bugsnag.configure do |config|
16
+ config.logger = Rails.logger
17
+ config.release_stage = Rails.env.to_s
18
+ config.project_root = Rails.root.to_s
19
+ config.params_filters += Rails.configuration.filter_parameters
20
+ end
21
+
22
+ # Auto-load configuration settings from config/bugsnag.yml if it exists
23
+ config_file = Rails.root.join("config", "bugsnag.yml")
24
+ config = YAML.load_file(config_file) if File.exists?(config_file)
25
+ Bugsnag.configure(config[Rails.env] ? config[Rails.env] : config) if config
26
+
27
+ if defined?(::ActionController::Base)
28
+ require "bugsnag/rails/controller_methods"
29
+ ::ActionController::Base.send(:include, Bugsnag::Rails::ControllerMethods)
30
+ end
10
31
  end
11
32
 
12
33
  initializer "bugsnag.use_rack_middleware" do |app|
@@ -19,17 +40,8 @@ module Bugsnag
19
40
 
20
41
  config.after_initialize do
21
42
  Bugsnag.configure do |config|
22
- config.release_stage = ::Rails.env
23
- config.project_root = ::Rails.root
24
- config.framework = "Rails: #{::Rails::VERSION::STRING}"
25
-
26
- config.logger ||= ::Rails.logger
27
- end
28
-
29
- if defined?(::ActionController::Base)
30
- require "bugsnag/rails/controller_methods"
31
- ::ActionController::Base.send(:include, Bugsnag::Rails::ControllerMethods)
43
+ config.middleware.use Bugsnag::Middleware::Rails3Request
32
44
  end
33
45
  end
34
46
  end
35
- end
47
+ end
@@ -1,3 +1,3 @@
1
- Dir["#{File.dirname(__FILE__)}/../tasks/*.rake"].each do |task|
1
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].each do |task|
2
2
  load task
3
3
  end
@@ -42,6 +42,11 @@ namespace :bugsnag do
42
42
  Bugsnag.notify(e, {:context => "rake#test_exception"})
43
43
  end
44
44
  end
45
+
46
+ desc "Show the bugsnag middleware stack"
47
+ task :middleware => :load do
48
+ Bugsnag.configuration.middleware.each {|m| puts m.to_s}
49
+ end
45
50
  end
46
51
 
47
52
  task :load do
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bugsnag
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease:
4
+ hash: -639319559
5
+ prerelease: 6
6
6
  segments:
7
7
  - 1
8
- - 1
9
- - 5
10
- version: 1.1.5
8
+ - 2
9
+ - 0
10
+ - beta
11
+ version: 1.2.0.beta
11
12
  platform: ruby
12
13
  authors:
13
14
  - James Smith
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2012-09-21 00:00:00 Z
19
+ date: 2012-09-29 00:00:00 Z
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  requirement: &id001 !ruby/object:Gem::Requirement
@@ -36,14 +37,20 @@ dependencies:
36
37
  requirement: &id002 !ruby/object:Gem::Requirement
37
38
  none: false
38
39
  requirements:
39
- - - ~>
40
+ - - <
40
41
  - !ruby/object:Gem::Version
41
- hash: 57
42
+ hash: 15
42
43
  segments:
44
+ - 1
43
45
  - 0
44
- - 8
45
- - 3
46
- version: 0.8.3
46
+ version: "1.0"
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 1
50
+ segments:
51
+ - 0
52
+ - 5
53
+ version: "0.5"
47
54
  version_requirements: *id002
48
55
  name: httparty
49
56
  prerelease: false
@@ -113,8 +120,13 @@ files:
113
120
  - lib/bugsnag.rb
114
121
  - lib/bugsnag/capistrano.rb
115
122
  - lib/bugsnag/configuration.rb
116
- - lib/bugsnag/delay/resque.rb
117
123
  - lib/bugsnag/helpers.rb
124
+ - lib/bugsnag/middleware/callbacks.rb
125
+ - lib/bugsnag/middleware/rack_request.rb
126
+ - lib/bugsnag/middleware/rails2_request.rb
127
+ - lib/bugsnag/middleware/rails3_request.rb
128
+ - lib/bugsnag/middleware/warden_user.rb
129
+ - lib/bugsnag/middleware_stack.rb
118
130
  - lib/bugsnag/notification.rb
119
131
  - lib/bugsnag/rack.rb
120
132
  - lib/bugsnag/rails.rb
@@ -122,9 +134,9 @@ files:
122
134
  - lib/bugsnag/rails/controller_methods.rb
123
135
  - lib/bugsnag/railtie.rb
124
136
  - lib/bugsnag/tasks.rb
137
+ - lib/bugsnag/tasks/bugsnag.rake
125
138
  - lib/bugsnag/version.rb
126
139
  - lib/resque/failure/bugsnag.rb
127
- - lib/tasks/bugsnag.rake
128
140
  - rails/init.rb
129
141
  - test/helper.rb
130
142
  - test/test_bugsnag.rb
@@ -148,12 +160,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
160
  required_rubygems_version: !ruby/object:Gem::Requirement
149
161
  none: false
150
162
  requirements:
151
- - - ">="
163
+ - - ">"
152
164
  - !ruby/object:Gem::Version
153
- hash: 3
165
+ hash: 25
154
166
  segments:
155
- - 0
156
- version: "0"
167
+ - 1
168
+ - 3
169
+ - 1
170
+ version: 1.3.1
157
171
  requirements: []
158
172
 
159
173
  rubyforge_project: