errplane 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/lib/errplane.rb CHANGED
@@ -35,11 +35,12 @@ module Errplane
35
35
 
36
36
  def transmit_unless_ignorable(e, env)
37
37
  begin
38
- black_box = assemble_black_box_for(e)
39
- ::Rails.logger.info("\nTransmitter: #{transmitter.inspect}")
40
- ::Rails.logger.info("\nBlack Box: #{black_box.to_json}")
41
- ::Rails.logger.info("\nIgnorable Exception? #{ignorable_exception?(e)}")
42
- ::Rails.logger.info("\nEnvironment: #{ENV.to_hash}")
38
+ black_box = assemble_black_box_for(e, env)
39
+ configuration.logger.info("\nTransmitter: #{transmitter.inspect}") if configuration.debug?
40
+ configuration.logger.info("\nBlack Box: #{black_box.to_json}") if configuration.debug?
41
+ configuration.logger.info("\nIgnorable Exception? #{ignorable_exception?(e)}") if configuration.debug?
42
+ configuration.logger.info("\nEnvironment: #{ENV.to_hash}") if configuration.debug?
43
+
43
44
  transmitter.relay(black_box) unless ignorable_exception?(e)
44
45
  rescue
45
46
  configuration.logger.info("[Errplane] Something went terribly wrong. Exception failed to take off.")
@@ -54,10 +55,10 @@ module Errplane
54
55
  assemble_black_box_for(e)
55
56
  end
56
57
 
57
- ::Rails.logger.info("\nTransmitter: #{transmitter.inspect}")
58
- ::Rails.logger.info("\nBlack Box: #{black_box.to_json}")
59
- ::Rails.logger.info("\nIgnorable Exception? #{ignorable_exception?(e)}")
60
- ::Rails.logger.info("\nEnvironment: #{ENV.to_hash}")
58
+ configuration.logger.info("\nTransmitter: #{transmitter.inspect}") if configuration.debug?
59
+ configuration.logger.info("\nBlack Box: #{black_box.to_json}") if configuration.debug?
60
+ configuration.logger.info("\nIgnorable Exception? #{ignorable_exception?(e)}") if configuration.debug?
61
+ configuration.logger.info("\nEnvironment: #{ENV.to_hash}") if configuration.debug?
61
62
  transmitter.relay(black_box)
62
63
  rescue
63
64
  configuration.logger.info("[Errplane] Something went terribly wrong. Exception failed to take off.")
@@ -69,19 +70,12 @@ module Errplane
69
70
  end
70
71
 
71
72
  private
72
- def assemble_black_box_for(e, options = {})
73
- exception = unwrap_exception(e)
74
- black_box = BlackBox.new(:exception => exception)
75
- end
76
-
77
- def unwrap_exception(e)
78
- if e.respond_to?(:original_exception)
79
- e.original_exception
80
- elsif e.respond_to?(:continued_exception)
81
- e.continued_exception
82
- else
83
- e
84
- end
73
+ def assemble_black_box_for(e, opts = {})
74
+ configuration.logger.info("OPTS: #{opts}")
75
+ e = e.continued_exception if e.respond_to?(:continued_exception)
76
+ e = e.original_exception if e.respond_to?(:original_exception)
77
+ opts = opts.merge(:exception => e)
78
+ black_box = BlackBox.new(opts)
85
79
  end
86
80
  end
87
81
  end
@@ -1,25 +1,55 @@
1
1
  module Errplane
2
2
  class BlackBox
3
3
  attr_reader :exception
4
+ attr_reader :params
5
+ attr_reader :session_data
6
+ attr_reader :controller
7
+ attr_reader :action
8
+ attr_reader :request_url
4
9
 
5
10
  def initialize(params = {})
6
11
  @exception = params[:exception]
12
+ @params = params[:params] || {}
13
+ @session_data = params[:session_data] || {}
14
+ @controller = params[:controller]
15
+ @action = params[:action]
16
+ @request_url = params[:request_url]
7
17
  end
8
18
 
9
19
  def to_json
10
20
  {
11
21
  :time => Time.now.to_i,
12
- :message => @exception.message,
13
- :backtrace => @exception.backtrace || [],
14
- :exception_class => @exception.class.to_s,
15
22
  :application_name => Errplane.configuration.application_name,
16
- :rails_root => Errplane.configuration.rails_root,
17
- :language => Errplane.configuration.language,
18
- :language_version => Errplane.configuration.language_version,
23
+ :application_root => Errplane.configuration.application_root,
19
24
  :framework => Errplane.configuration.framework,
20
25
  :framework_version => Errplane.configuration.framework_version,
21
- :environment_variables => Errplane.configuration.environment_variables.to_hash,
26
+ :message => @exception.message,
27
+ :backtrace => @exception.backtrace || [],
28
+ :exception_class => @exception.class.to_s,
29
+ :language => "Ruby",
30
+ :language_version => "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}",
31
+ :environment_variables => ENV.to_hash,
32
+ :reporter => reporter,
33
+ :request_data => request_data
22
34
  }.to_json
23
35
  end
36
+
37
+ def reporter
38
+ {
39
+ :name => "Errplane",
40
+ :version => Errplane::VERSION,
41
+ :url => "http://github.com/errplane/gem"
42
+ }
43
+ end
44
+
45
+ def request_data
46
+ {
47
+ :params => @params,
48
+ :session_data => @session_data,
49
+ :controller => @controller,
50
+ :action => @action,
51
+ :request_url => @request_url
52
+ }
53
+ end
24
54
  end
25
55
  end
@@ -4,10 +4,10 @@ module Errplane
4
4
  attr_accessor :api_host
5
5
  attr_accessor :application_id
6
6
  attr_accessor :application_name
7
+ attr_accessor :application_root
7
8
 
8
9
  attr_accessor :logger
9
10
  attr_accessor :rails_environment
10
- attr_accessor :rails_root
11
11
  attr_accessor :framework
12
12
  attr_accessor :framework_version
13
13
  attr_accessor :language
@@ -16,6 +16,8 @@ module Errplane
16
16
  attr_accessor :ignored_environments
17
17
  attr_accessor :environment_variables
18
18
 
19
+ attr_accessor :debug
20
+
19
21
  DEFAULTS = {
20
22
  :api_host => "api.errplane.com",
21
23
  :ignored_exceptions => %w{ActiveRecord::RecordNotFound
@@ -27,6 +29,11 @@ module Errplane
27
29
  @api_host = DEFAULTS[:api_host]
28
30
  @ignored_exceptions = DEFAULTS[:ignored_exceptions].dup
29
31
  @ignored_environments = DEFAULTS[:ignored_environments].dup
32
+ @debug = false
33
+ end
34
+
35
+ def debug?
36
+ !!@debug
30
37
  end
31
38
 
32
39
  def ignore_current_environment?
@@ -0,0 +1,26 @@
1
+ module Errplane
2
+ module Rails
3
+ module AirTrafficController
4
+ def errplane_request_data
5
+ {
6
+ :params => params.to_hash,
7
+ :session_data => errplane_session_data,
8
+ :controller => params[:controller],
9
+ :action => params[:action],
10
+ :request_url => errplane_request_url
11
+ }
12
+ end
13
+
14
+ private
15
+ def errplane_session_data
16
+ session.respond_to?(:to_hash) ? session.to_hash : session.data
17
+ end
18
+
19
+ def errplane_request_url
20
+ url = "#{request.protocol}#{request.host}"
21
+ url << ":#{request.port}" unless [80, 443].include?(request.port)
22
+ url << request.fullpath
23
+ end
24
+ end
25
+ end
26
+ end
@@ -7,8 +7,10 @@ module Errplane
7
7
  end
8
8
 
9
9
  def render_exception_with_errplane(env, e)
10
- controller = env['action_controller.instance']
11
- Errplane.transmit_unless_ignorable(e, env)
10
+ controller = env["action_controller.instance"]
11
+ Errplane.configuration.logger.info("Controller: #{controller}")
12
+ Errplane.configuration.logger.info("Request Data: #{controller.try(:errplane_request_data)}")
13
+ Errplane.transmit_unless_ignorable(e, controller.try(:errplane_request_data))
12
14
  render_exception_without_errplane(env, e)
13
15
  end
14
16
  end
@@ -37,9 +37,26 @@ module Errplane
37
37
 
38
38
  puts "Generating sample request.."
39
39
  env = ::Rack::MockRequest.env_for("/errplane_test")
40
- ::Rails.application.call(env)
41
40
 
42
- puts "Done. Check your email or http://errplane.com for the exception notice."
41
+ puts "Attempting to raise exception via HTTP.."
42
+ response = ::Rails.application.call(env)
43
+
44
+ if response.try(:first) == 500
45
+ puts "Done. Check your email or http://errplane.com for the exception notice."
46
+ else
47
+ puts "Request failed: #{response}"
48
+
49
+ env["HTTPS"] = "on"
50
+ puts "Attempting to raise exception via HTTPS.."
51
+ response = ::Rails.application.call(env)
52
+
53
+ if response.try(:first) == 500
54
+ puts "Done. Check your email or http://errplane.com for the exception notice."
55
+ else
56
+ puts "Request failed: #{response}"
57
+ puts "We didn't get the exception we were expecting. Contact support@errplane.com and send them all of this output."
58
+ end
59
+ end
43
60
  end
44
61
  end
45
62
  end
@@ -52,13 +69,15 @@ module Errplane
52
69
  Errplane.configure(true) do |config|
53
70
  config.logger ||= ::Rails.logger
54
71
  config.rails_environment ||= ::Rails.env
55
- config.rails_root ||= ::Rails.root
72
+ config.application_root ||= ::Rails.root
56
73
  config.application_name ||= ::Rails.application.class.parent_name
57
74
  config.framework = "Rails"
58
75
  config.framework_version = ::Rails::VERSION::STRING
59
- config.language = "Ruby"
60
- config.language_version = "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
61
- config.environment_variables = ENV.to_hash
76
+ end
77
+
78
+ ActiveSupport.on_load(:action_controller) do
79
+ require 'errplane/rails/air_traffic_controller'
80
+ include Errplane::Rails::AirTrafficController
62
81
  end
63
82
 
64
83
  if defined?(::ActionDispatch::DebugExceptions)
@@ -1,12 +1,9 @@
1
1
  Errplane.configure(true) do |config|
2
2
  config.logger ||= logger
3
3
  config.rails_environment ||= settings.environment
4
- config.rails_root ||= settings.root
4
+ config.application_root ||= settings.root
5
5
  config.framework = "Sinatra"
6
6
  config.framework_version = ::Sinatra::VERSION
7
- config.language = "Ruby"
8
- config.language_version = "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
9
- config.environment_variables = ENV.to_hash
10
7
  end
11
8
 
12
9
  error do
@@ -1,3 +1,3 @@
1
1
  module Errplane
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: errplane
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-27 00:00:00.000000000 Z
12
+ date: 2012-06-29 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: This gem provides exception reporting with Errplane for Rails 3.x applications.
15
15
  email:
@@ -31,6 +31,7 @@ files:
31
31
  - lib/errplane/configuration.rb
32
32
  - lib/errplane/deployment.rb
33
33
  - lib/errplane/rack.rb
34
+ - lib/errplane/rails/air_traffic_controller.rb
34
35
  - lib/errplane/rails/middleware/hijack_render_exception.rb
35
36
  - lib/errplane/railtie.rb
36
37
  - lib/errplane/sinatra.rb