honeybadger 1.16.7 → 2.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +19 -0
  3. data/README.md +37 -16
  4. data/bin/honeybadger +5 -0
  5. data/lib/honeybadger.rb +167 -191
  6. data/lib/honeybadger/agent.rb +136 -0
  7. data/lib/honeybadger/backend.rb +26 -0
  8. data/lib/honeybadger/backend/base.rb +66 -0
  9. data/lib/honeybadger/backend/debug.rb +12 -0
  10. data/lib/honeybadger/backend/null.rb +16 -0
  11. data/lib/honeybadger/backend/server.rb +51 -0
  12. data/lib/honeybadger/backend/test.rb +24 -0
  13. data/lib/honeybadger/backtrace.rb +29 -24
  14. data/lib/honeybadger/cli.rb +367 -0
  15. data/lib/honeybadger/config.rb +333 -0
  16. data/lib/honeybadger/config/callbacks.rb +70 -0
  17. data/lib/honeybadger/config/defaults.rb +175 -0
  18. data/lib/honeybadger/config/env.rb +40 -0
  19. data/lib/honeybadger/config/yaml.rb +43 -0
  20. data/lib/honeybadger/const.rb +28 -0
  21. data/lib/honeybadger/init/rails.rb +84 -0
  22. data/lib/honeybadger/init/sinatra.rb +27 -0
  23. data/lib/honeybadger/logging.rb +133 -0
  24. data/lib/honeybadger/notice.rb +243 -280
  25. data/lib/honeybadger/plugin.rb +110 -0
  26. data/lib/honeybadger/plugins/delayed_job.rb +22 -0
  27. data/lib/honeybadger/{integrations → plugins}/delayed_job/plugin.rb +6 -7
  28. data/lib/honeybadger/{integrations → plugins}/local_variables.rb +7 -8
  29. data/lib/honeybadger/{integrations → plugins}/net_http.rb +10 -8
  30. data/lib/honeybadger/plugins/passenger.rb +24 -0
  31. data/lib/honeybadger/plugins/rails.rb +61 -0
  32. data/lib/honeybadger/plugins/sidekiq.rb +35 -0
  33. data/lib/honeybadger/{integrations → plugins}/thor.rb +9 -8
  34. data/lib/honeybadger/{integrations → plugins}/unicorn.rb +10 -9
  35. data/lib/honeybadger/rack/error_notifier.rb +44 -27
  36. data/lib/honeybadger/rack/metrics_reporter.rb +41 -0
  37. data/lib/honeybadger/rack/request_hash.rb +50 -0
  38. data/lib/honeybadger/rack/user_feedback.rb +15 -10
  39. data/lib/honeybadger/rack/user_informer.rb +14 -3
  40. data/lib/honeybadger/trace.rb +185 -0
  41. data/lib/honeybadger/util/http.rb +79 -0
  42. data/lib/honeybadger/util/request_sanitizer.rb +35 -0
  43. data/lib/honeybadger/util/sanitizer.rb +71 -0
  44. data/lib/honeybadger/util/stats.rb +31 -0
  45. data/lib/honeybadger/version.rb +4 -0
  46. data/lib/honeybadger/worker.rb +224 -0
  47. data/lib/honeybadger/worker/batch.rb +50 -0
  48. data/lib/honeybadger/worker/metered_queue.rb +80 -0
  49. data/lib/honeybadger/worker/metrics_collection.rb +61 -0
  50. data/lib/honeybadger/worker/metrics_collector.rb +96 -0
  51. data/{lib/honeybadger/capistrano.rb → vendor/capistrano-honeybadger/lib/capistrano/honeybadger.rb} +1 -3
  52. data/vendor/capistrano-honeybadger/lib/capistrano/tasks/deploy.cap +76 -0
  53. data/vendor/capistrano-honeybadger/lib/honeybadger/capistrano.rb +2 -0
  54. data/{lib → vendor/capistrano-honeybadger/lib}/honeybadger/capistrano/legacy.rb +16 -15
  55. data/vendor/thor/lib/thor.rb +484 -0
  56. data/vendor/thor/lib/thor/actions.rb +319 -0
  57. data/vendor/thor/lib/thor/actions/create_file.rb +103 -0
  58. data/vendor/thor/lib/thor/actions/create_link.rb +59 -0
  59. data/vendor/thor/lib/thor/actions/directory.rb +118 -0
  60. data/vendor/thor/lib/thor/actions/empty_directory.rb +135 -0
  61. data/vendor/thor/lib/thor/actions/file_manipulation.rb +316 -0
  62. data/vendor/thor/lib/thor/actions/inject_into_file.rb +107 -0
  63. data/vendor/thor/lib/thor/base.rb +656 -0
  64. data/vendor/thor/lib/thor/command.rb +133 -0
  65. data/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +77 -0
  66. data/vendor/thor/lib/thor/core_ext/io_binary_read.rb +10 -0
  67. data/vendor/thor/lib/thor/core_ext/ordered_hash.rb +98 -0
  68. data/vendor/thor/lib/thor/error.rb +32 -0
  69. data/vendor/thor/lib/thor/group.rb +281 -0
  70. data/vendor/thor/lib/thor/invocation.rb +178 -0
  71. data/vendor/thor/lib/thor/line_editor.rb +17 -0
  72. data/vendor/thor/lib/thor/line_editor/basic.rb +35 -0
  73. data/vendor/thor/lib/thor/line_editor/readline.rb +88 -0
  74. data/vendor/thor/lib/thor/parser.rb +4 -0
  75. data/vendor/thor/lib/thor/parser/argument.rb +73 -0
  76. data/vendor/thor/lib/thor/parser/arguments.rb +175 -0
  77. data/vendor/thor/lib/thor/parser/option.rb +125 -0
  78. data/vendor/thor/lib/thor/parser/options.rb +218 -0
  79. data/vendor/thor/lib/thor/rake_compat.rb +71 -0
  80. data/vendor/thor/lib/thor/runner.rb +322 -0
  81. data/vendor/thor/lib/thor/shell.rb +81 -0
  82. data/vendor/thor/lib/thor/shell/basic.rb +421 -0
  83. data/vendor/thor/lib/thor/shell/color.rb +149 -0
  84. data/vendor/thor/lib/thor/shell/html.rb +126 -0
  85. data/vendor/thor/lib/thor/util.rb +267 -0
  86. data/vendor/thor/lib/thor/version.rb +3 -0
  87. metadata +97 -305
  88. data/Appraisals +0 -95
  89. data/CHANGELOG.md +0 -422
  90. data/Gemfile +0 -8
  91. data/Gemfile.lock +0 -136
  92. data/Guardfile +0 -5
  93. data/MIT-LICENSE +0 -32
  94. data/Rakefile +0 -159
  95. data/features/metal.feature +0 -20
  96. data/features/rack.feature +0 -55
  97. data/features/rails.feature +0 -343
  98. data/features/rails3.x.feature +0 -26
  99. data/features/rake.feature +0 -25
  100. data/features/sinatra.feature +0 -27
  101. data/features/standalone.feature +0 -73
  102. data/features/step_definitions/metal_steps.rb +0 -24
  103. data/features/step_definitions/rack_steps.rb +0 -18
  104. data/features/step_definitions/rails_steps.rb +0 -270
  105. data/features/step_definitions/rake_steps.rb +0 -17
  106. data/features/step_definitions/standalone_steps.rb +0 -12
  107. data/features/step_definitions/thor_steps.rb +0 -4
  108. data/features/support/env.rb +0 -22
  109. data/features/support/honeybadger_failure_shim.rb.template +0 -5
  110. data/features/support/honeybadger_shim.rb.template +0 -6
  111. data/features/support/rails.rb +0 -202
  112. data/features/support/rake/Rakefile +0 -68
  113. data/features/support/test.thor +0 -22
  114. data/features/thor.feature +0 -5
  115. data/gemfiles/binding_of_caller.gemfile +0 -13
  116. data/gemfiles/delayed_job.gemfile +0 -13
  117. data/gemfiles/rack.gemfile +0 -13
  118. data/gemfiles/rails.gemfile +0 -16
  119. data/gemfiles/rails2.3.gemfile +0 -15
  120. data/gemfiles/rails3.0.gemfile +0 -16
  121. data/gemfiles/rails3.1.gemfile +0 -16
  122. data/gemfiles/rails3.2.gemfile +0 -16
  123. data/gemfiles/rails4.0.gemfile +0 -16
  124. data/gemfiles/rails4.1.gemfile +0 -16
  125. data/gemfiles/rake.gemfile +0 -13
  126. data/gemfiles/sinatra.gemfile +0 -13
  127. data/gemfiles/standalone.gemfile +0 -12
  128. data/gemfiles/thor.gemfile +0 -13
  129. data/generators/honeybadger/honeybadger_generator.rb +0 -95
  130. data/generators/honeybadger/lib/insert_commands.rb +0 -34
  131. data/generators/honeybadger/lib/rake_commands.rb +0 -24
  132. data/generators/honeybadger/templates/capistrano_hook.rb +0 -6
  133. data/generators/honeybadger/templates/honeybadger_tasks.rake +0 -25
  134. data/generators/honeybadger/templates/initializer.rb +0 -6
  135. data/honeybadger.gemspec +0 -174
  136. data/lib/honeybadger/array.rb +0 -53
  137. data/lib/honeybadger/capistrano/tasks.rake +0 -73
  138. data/lib/honeybadger/configuration.rb +0 -397
  139. data/lib/honeybadger/dependency.rb +0 -65
  140. data/lib/honeybadger/integrations.rb +0 -9
  141. data/lib/honeybadger/integrations/delayed_job.rb +0 -20
  142. data/lib/honeybadger/integrations/passenger.rb +0 -18
  143. data/lib/honeybadger/integrations/sidekiq.rb +0 -37
  144. data/lib/honeybadger/monitor.rb +0 -17
  145. data/lib/honeybadger/monitor/railtie.rb +0 -53
  146. data/lib/honeybadger/monitor/sender.rb +0 -44
  147. data/lib/honeybadger/monitor/trace.rb +0 -187
  148. data/lib/honeybadger/monitor/worker.rb +0 -169
  149. data/lib/honeybadger/payload.rb +0 -101
  150. data/lib/honeybadger/rack.rb +0 -12
  151. data/lib/honeybadger/rails.rb +0 -45
  152. data/lib/honeybadger/rails/action_controller_catcher.rb +0 -30
  153. data/lib/honeybadger/rails/controller_methods.rb +0 -78
  154. data/lib/honeybadger/rails/middleware/exceptions_catcher.rb +0 -29
  155. data/lib/honeybadger/rails3_tasks.rb +0 -94
  156. data/lib/honeybadger/railtie.rb +0 -52
  157. data/lib/honeybadger/rake_handler.rb +0 -66
  158. data/lib/honeybadger/sender.rb +0 -185
  159. data/lib/honeybadger/shared_tasks.rb +0 -56
  160. data/lib/honeybadger/stats.rb +0 -29
  161. data/lib/honeybadger/tasks.rb +0 -95
  162. data/lib/honeybadger/user_feedback.rb +0 -8
  163. data/lib/honeybadger/user_informer.rb +0 -8
  164. data/lib/honeybadger_tasks.rb +0 -69
  165. data/lib/rails/generators/honeybadger/honeybadger_generator.rb +0 -99
  166. data/rails/init.rb +0 -1
  167. data/resources/README.md +0 -34
  168. data/script/integration_test.rb +0 -38
  169. data/spec/allocation_stats.rb +0 -32
  170. data/spec/honeybadger/backtrace_spec.rb +0 -242
  171. data/spec/honeybadger/capistrano_spec.rb +0 -36
  172. data/spec/honeybadger/configuration_spec.rb +0 -328
  173. data/spec/honeybadger/dependency_spec.rb +0 -134
  174. data/spec/honeybadger/integrations/delayed_job_spec.rb +0 -82
  175. data/spec/honeybadger/integrations/local_variables_spec.rb +0 -60
  176. data/spec/honeybadger/integrations/net_http_spec.rb +0 -29
  177. data/spec/honeybadger/integrations/passenger_spec.rb +0 -29
  178. data/spec/honeybadger/integrations/sidekiq_spec.rb +0 -60
  179. data/spec/honeybadger/integrations/thor_spec.rb +0 -32
  180. data/spec/honeybadger/integrations/unicorn_spec.rb +0 -40
  181. data/spec/honeybadger/logger_spec.rb +0 -79
  182. data/spec/honeybadger/monitor/trace_spec.rb +0 -65
  183. data/spec/honeybadger/monitor/worker_spec.rb +0 -274
  184. data/spec/honeybadger/notice_spec.rb +0 -669
  185. data/spec/honeybadger/notifier_spec.rb +0 -328
  186. data/spec/honeybadger/payload_spec.rb +0 -162
  187. data/spec/honeybadger/rack_spec.rb +0 -85
  188. data/spec/honeybadger/rails/action_controller_spec.rb +0 -328
  189. data/spec/honeybadger/rails_spec.rb +0 -37
  190. data/spec/honeybadger/sender_spec.rb +0 -317
  191. data/spec/honeybadger/stats_spec.rb +0 -57
  192. data/spec/honeybadger/user_feedback_spec.rb +0 -80
  193. data/spec/honeybadger/user_informer_spec.rb +0 -30
  194. data/spec/honeybadger_tasks_spec.rb +0 -171
  195. data/spec/spec_helper.rb +0 -24
  196. data/spec/support/array_including.rb +0 -31
  197. data/spec/support/backtraced_exception.rb +0 -9
  198. data/spec/support/collected_sender.rb +0 -12
  199. data/spec/support/defines_constants.rb +0 -18
  200. data/spec/support/helpers.rb +0 -101
@@ -1,169 +0,0 @@
1
- require "singleton"
2
-
3
- module Honeybadger
4
- module Monitor
5
- class Worker
6
- include Singleton
7
-
8
- # Sub-class thread so we have a named thread (useful for debugging in Thread.list).
9
- class MetricsThread < Thread
10
- end
11
-
12
- def initialize
13
- init_metrics
14
- init_traces
15
- @delay = defined?(::Rails) && ::Rails.env.development? ? 10 : 60
16
- @per_request = 100
17
- @traces_per_request = 20
18
- @sender = Monitor::Sender.new(Honeybadger.configuration)
19
- @lock = Mutex.new
20
- start
21
- at_exit { stop }
22
- end
23
-
24
- def start
25
- Honeybadger.write_verbose_log('Starting worker')
26
-
27
- @thread = MetricsThread.new do
28
- begin
29
- until Thread.current[:should_exit] do
30
- send_metrics
31
- send_traces
32
- sleep @delay
33
- end
34
- rescue Exception => e
35
- Honeybadger.write_verbose_log("Error in MetricsThread (shutting down): #{e.class} - #{e.message}\n#{e.backtrace.join("\n\t")}", :error)
36
- raise e
37
- end
38
- end
39
- end
40
-
41
- def stop
42
- Honeybadger.write_verbose_log('Stopping worker')
43
- @thread[:should_exit] = true if @thread
44
- end
45
-
46
- def fork
47
- Honeybadger.write_verbose_log('Forking worker')
48
-
49
- stop
50
-
51
- @lock.unlock if @lock.locked?
52
- @lock.synchronize do
53
- init_metrics
54
- init_traces
55
- end
56
-
57
- start
58
- end
59
-
60
- def timing(name, value)
61
- add_metric(name, value, :timing)
62
- end
63
-
64
- def increment(name, value)
65
- add_metric(name, value, :counter)
66
- end
67
-
68
- def pending_traces
69
- @pending_traces ||= {}
70
- end
71
-
72
- def trace
73
- Thread.current[:hb_trace_id] ? @pending_traces[Thread.current[:hb_trace_id]] : nil
74
- end
75
-
76
- def queue_trace
77
- return unless trace
78
-
79
- @lock.synchronize do
80
- if trace.duration > Honeybadger.configuration.trace_threshold && (!@traces[trace.key] || @traces[trace.key].duration < trace.duration)
81
- @traces[trace.key] = trace
82
- end
83
- @pending_traces[Thread.current[:hb_trace_id]] = nil
84
- Thread.current[:hb_trace_id] = nil
85
- end
86
- end
87
-
88
- protected
89
-
90
- def init_metrics
91
- @metrics = { :timing => {}, :counter => {} }
92
- end
93
-
94
- def init_traces
95
- @traces = {}
96
- end
97
-
98
- def collect_metrics
99
- @lock.synchronize do
100
- metrics = @metrics
101
- init_metrics
102
- metrics
103
- end
104
- end
105
-
106
- def collect_traces
107
- @lock.synchronize do
108
- traces = @traces.values
109
- init_traces
110
- traces
111
- end
112
- end
113
-
114
- def send_metrics
115
- metrics = collect_metrics
116
- return unless metrics[:timing].any? || metrics[:counter].any?
117
-
118
- Honeybadger.write_verbose_log('Sending metrics')
119
-
120
- [].tap do |m|
121
- metrics[:counter].each do |metric, values|
122
- m << "#{metric} #{values.sum}"
123
- end
124
- metrics[:timing].each do |metric, values|
125
- m << "#{metric}:mean #{values.mean}"
126
- m << "#{metric}:median #{values.median}"
127
- m << "#{metric}:percentile_90 #{values.percentile(90)}"
128
- m << "#{metric}:min #{values.min}"
129
- m << "#{metric}:max #{values.max}"
130
- m << "#{metric}:stddev #{values.standard_dev}" if values.count > 1
131
- m << "#{metric} #{values.count}"
132
- end
133
- end.each_slice(@per_request) do |mm|
134
- begin
135
- @sender.send_metrics({ :metrics => mm.compact, :environment => Honeybadger.configuration.environment_name, :hostname => Honeybadger.configuration.hostname })
136
- rescue Exception => e
137
- log(:error, "[Honeybadger::Monitor::Worker#send_metrics] Failed to send #{mm.count} metrics: #{e.class} - #{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}")
138
- end
139
- end
140
- end
141
-
142
- def send_traces
143
- traces = collect_traces
144
- return unless traces.any?
145
-
146
- Honeybadger.write_verbose_log('Sending traces')
147
-
148
- traces.each_slice(@traces_per_request) do |t|
149
- begin
150
- @sender.send_traces({ :traces => t.compact.map(&:to_h), :environment => Honeybadger.configuration.environment_name, :hostname => Honeybadger.configuration.hostname })
151
- rescue Exception => e
152
- log(:error, "[Honeybadger::Monitor::Worker#send_traces] Failed to send #{t.count} metrics: #{e.class} - #{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}")
153
- end
154
- end
155
- end
156
-
157
- def add_metric(name, value, kind)
158
- @lock.synchronize do
159
- (@metrics[kind][name] ||= Honeybadger::Array.new) << value
160
- end
161
- end
162
-
163
- def log(level, message)
164
- Honeybadger.write_verbose_log(message, level)
165
- end
166
-
167
- end
168
- end
169
- end
@@ -1,101 +0,0 @@
1
- require 'delegate'
2
-
3
- module Honeybadger
4
- class Payload < SimpleDelegator
5
- TOP_LEVEL_KEYS = [:api_key, :notifier, :error, :request, :server]
6
- OBJECT_WHITELIST = [Hash, Array, String, Integer, Float, TrueClass, FalseClass, NilClass]
7
-
8
- # Define getters for top level keys
9
- TOP_LEVEL_KEYS.each do |key|
10
- define_method key do
11
- self[key]
12
- end
13
- end
14
-
15
- def initialize(hash = {}, options = {})
16
- fail ArgumentError, 'must be a Hash' unless hash.kind_of?(Hash)
17
-
18
- @max_depth = options[:max_depth] || 20
19
- @filters = options[:filters]
20
-
21
- super(sanitize(hash))
22
-
23
- TOP_LEVEL_KEYS.each {|k| self[k] ||= {} }
24
-
25
- filter_url!(request[:url]) if request[:url]
26
- filter_urls!(request[:cgi_data]) if request[:cgi_data]
27
-
28
- filter!(request[:params]) if request[:params]
29
- filter!(request[:session]) if request[:session]
30
- filter!(request[:cgi_data]) if request[:cgi_data]
31
- filter!(request[:local_variables]) if request[:local_variables]
32
- end
33
-
34
- protected
35
-
36
- attr_reader :max_depth, :filters
37
-
38
- # Removes non-serializable data and truncates to max depth.
39
- def sanitize(data, depth = 0, stack = [])
40
- return '[possible infinite recursion halted]' if stack.any?{|item| item == data.object_id }
41
-
42
- if data.respond_to?(:to_hash)
43
- return '[max depth reached]' if depth >= max_depth
44
- data.to_hash.reduce({}) do |result, (key, value)|
45
- result.merge(key => sanitize(value, depth+1, stack + [data.object_id]))
46
- end
47
- elsif data.respond_to?(:to_ary)
48
- return '[max depth reached]' if depth >= max_depth
49
- data.to_ary.collect do |value|
50
- sanitize(value, depth+1, stack + [data.object_id])
51
- end
52
- elsif OBJECT_WHITELIST.any? {|c| data.kind_of?(c) }
53
- data
54
- else
55
- data.to_s
56
- end
57
- end
58
-
59
- def filter!(hash)
60
- if filters
61
- hash.each do |key, value|
62
- if filter_key?(key)
63
- hash[key] = "[FILTERED]"
64
- elsif value.respond_to?(:to_hash)
65
- filter!(hash[key])
66
- end
67
- end
68
- end
69
- end
70
-
71
- def filter_key?(key)
72
- return false unless filters
73
-
74
- filters.any? do |filter|
75
- if filter.is_a?(Regexp)
76
- key.to_s =~ filter
77
- else
78
- key.to_s.eql?(filter.to_s)
79
- end
80
- end
81
- end
82
-
83
- def filter_url!(url)
84
- return nil unless url =~ /\S/
85
-
86
- url.scan(/(?:^|&|\?)([^=?&]+)=([^&]+)/).each do |m|
87
- next unless filter_key?(m[0])
88
- url.gsub!(/#{m[1]}/, '[FILTERED]')
89
- end
90
-
91
- url
92
- end
93
-
94
- def filter_urls!(hash)
95
- hash.each_pair do |key, value|
96
- next unless value.kind_of?(String) && key =~ /\A[A-Z_]+\Z/ && value =~ /\S/
97
- filter_url!(value)
98
- end
99
- end
100
- end
101
- end
@@ -1,12 +0,0 @@
1
- require 'honeybadger/rack/error_notifier'
2
- require 'honeybadger/rack/user_informer'
3
- require 'honeybadger/rack/user_feedback'
4
-
5
- module Honeybadger
6
- module Rack
7
- def self.new(*args, &block)
8
- warn '[DEPRECATION] Honeybadger::Rack is deprecated in 2.0. Use Honeybadger::Rack::ErrorNotifier.'
9
- ErrorNotifier.new(*args, &block)
10
- end
11
- end
12
- end
@@ -1,45 +0,0 @@
1
- require 'honeybadger'
2
- require 'honeybadger/rails/controller_methods'
3
- require 'honeybadger/rails/action_controller_catcher'
4
-
5
- module Honeybadger
6
- module Rails
7
- def self.initialize
8
- if defined?(ActionController::Base)
9
- ActionController::Base.send(:include, Honeybadger::Rails::ActionControllerCatcher)
10
- ActionController::Base.send(:include, Honeybadger::Rails::ControllerMethods)
11
- end
12
-
13
- rails_logger = if defined?(::Rails.logger)
14
- ::Rails.logger
15
- elsif defined?(RAILS_DEFAULT_LOGGER)
16
- RAILS_DEFAULT_LOGGER
17
- end
18
-
19
- if defined?(::Rails.configuration) && ::Rails.configuration.respond_to?(:middleware)
20
- ::Rails.configuration.middleware.insert_after 'ActionController::Failsafe',
21
- Honeybadger::Rack::ErrorNotifier
22
- ::Rails.configuration.middleware.insert_after 'Rack::Lock',
23
- Honeybadger::Rack::UserInformer
24
- ::Rails.configuration.middleware.insert_after Honeybadger::Rack::UserInformer,
25
- Honeybadger::Rack::UserFeedback
26
- end
27
-
28
- Honeybadger.configure(true) do |config|
29
- config.logger = rails_logger
30
- config.environment_name = defined?(::Rails.env) && ::Rails.env || defined?(RAILS_ENV) && RAILS_ENV
31
- config.project_root = defined?(::Rails.root) && ::Rails.root || defined?(RAILS_ROOT) && RAILS_ROOT
32
- config.framework = defined?(::Rails.version) && "Rails: #{::Rails.version}" || defined?(::Rails::VERSION::STRING) && "Rails: #{::Rails::VERSION::STRING}"
33
- end
34
-
35
- if defined?(::Rails.configuration) && ::Rails.configuration.respond_to?(:after_initialize)
36
- ::Rails.configuration.after_initialize do
37
- Honeybadger::Dependency.inject!
38
- Honeybadger.ping(Honeybadger.configuration)
39
- end
40
- end
41
- end
42
- end
43
- end
44
-
45
- Honeybadger::Rails.initialize
@@ -1,30 +0,0 @@
1
- module Honeybadger
2
- module Rails
3
- module ActionControllerCatcher
4
-
5
- # Sets up an alias chain to catch exceptions when Rails does
6
- def self.included(base) #:nodoc:
7
- base.send(:alias_method, :rescue_action_in_public_without_honeybadger, :rescue_action_in_public)
8
- base.send(:alias_method, :rescue_action_in_public, :rescue_action_in_public_with_honeybadger)
9
- end
10
-
11
- private
12
-
13
- # Overrides the rescue_action method in ActionController::Base, but does not inhibit
14
- # any custom processing that is defined with Rails 2's exception helpers.
15
- def rescue_action_in_public_with_honeybadger(exception)
16
- unless honeybadger_ignore_user_agent?
17
- error_id = Honeybadger.notify_or_ignore(exception, honeybadger_request_data)
18
- request.env['honeybadger.error_id'] = error_id
19
- end
20
- rescue_action_in_public_without_honeybadger(exception)
21
- end
22
-
23
- def honeybadger_ignore_user_agent? #:nodoc:
24
- # Rails 1.2.6 doesn't have request.user_agent, so check for it here
25
- user_agent = request.respond_to?(:user_agent) ? request.user_agent : request.env["HTTP_USER_AGENT"]
26
- Honeybadger.configuration.ignore_user_agent.flatten.any? { |ua| ua === user_agent }
27
- end
28
- end
29
- end
30
- end
@@ -1,78 +0,0 @@
1
- module Honeybadger
2
- module Rails
3
- module ControllerMethods
4
- def honeybadger_request_data
5
- { :parameters => honeybadger_filter_if_filtering(params.to_hash),
6
- :session_data => honeybadger_filter_if_filtering(honeybadger_session_data),
7
- :controller => params[:controller],
8
- :action => params[:action],
9
- :url => honeybadger_request_url,
10
- :cgi_data => honeybadger_filter_if_filtering(request.env) }
11
- end
12
-
13
- private
14
-
15
- # This method should be used for sending manual notifications while you are still
16
- # inside the controller. Otherwise it works like Honeybadger.notify.
17
- def notify_honeybadger(hash_or_exception)
18
- unless honeybadger_local_request?
19
- Honeybadger.notify(hash_or_exception, honeybadger_request_data)
20
- end
21
- end
22
-
23
- # Same as the notify_honeybadger method but taking into account the ignored exceptions.
24
- def notify_honeybadger_or_ignore(hash_or_exception)
25
- unless honeybadger_local_request?
26
- Honeybadger.notify_or_ignore(hash_or_exception, honeybadger_request_data)
27
- end
28
- end
29
-
30
- def honeybadger_local_request?
31
- if defined?(::Rails.application.config)
32
- ::Rails.application.config.consider_all_requests_local || (request.local? && (!request.env["HTTP_X_FORWARDED_FOR"]))
33
- else
34
- consider_all_requests_local || (local_request? && (!request.env["HTTP_X_FORWARDED_FOR"]))
35
- end
36
- end
37
-
38
- def honeybadger_ignore_user_agent? #:nodoc:
39
- # Rails 1.2.6 doesn't have request.user_agent, so check for it here
40
- user_agent = request.respond_to?(:user_agent) ? request.user_agent : request.env["HTTP_USER_AGENT"]
41
- Honeybadger.configuration.ignore_user_agent.flatten.any? { |ua| ua === user_agent }
42
- end
43
-
44
- def honeybadger_filter_if_filtering(hash)
45
- return hash if ! hash.is_a?(Hash)
46
-
47
- # Rails 2 filters parameters in the controller
48
- # In Rails 3+ we use request.env['action_dispatch.parameter_filter']
49
- # to filter parameters in Honeybadger::Notice (avoids filtering twice)
50
- if respond_to?(:filter_parameters)
51
- filter_parameters(hash)
52
- else
53
- hash
54
- end
55
- end
56
-
57
- def honeybadger_session_data
58
- return {} unless session
59
- if session.respond_to?(:to_hash)
60
- session.to_hash
61
- else
62
- session.data
63
- end
64
- end
65
-
66
- def honeybadger_request_url
67
- url = "#{request.protocol}#{request.host}"
68
-
69
- unless [80, 443].include?(request.port)
70
- url << ":#{request.port}"
71
- end
72
-
73
- url << request.fullpath
74
- url
75
- end
76
- end
77
- end
78
- end
@@ -1,29 +0,0 @@
1
- module Honeybadger
2
- module Rails
3
- module Middleware
4
- module ExceptionsCatcher
5
- def self.included(base)
6
- base.send(:alias_method_chain,:render_exception,:honeybadger)
7
- end
8
-
9
- def skip_user_agent?(env)
10
- user_agent = env["HTTP_USER_AGENT"]
11
- ::Honeybadger.configuration.ignore_user_agent.flatten.any? { |ua| ua === user_agent }
12
- rescue
13
- false
14
- end
15
-
16
- def render_exception_with_honeybadger(env,exception)
17
- controller = env['action_controller.instance']
18
- env['honeybadger.error_id'] = Honeybadger.
19
- notify_or_ignore(exception,
20
- (controller.respond_to?(:honeybadger_request_data) ? controller.honeybadger_request_data : {:rack_env => env})) unless skip_user_agent?(env)
21
- if defined?(controller.rescue_action_in_public_without_honeybadger)
22
- controller.rescue_action_in_public_without_honeybadger(exception)
23
- end
24
- render_exception_without_honeybadger(env,exception)
25
- end
26
- end
27
- end
28
- end
29
- end