Class: Honeybadger::Notice
- Inherits:
-
Object
- Object
- Honeybadger::Notice
- Extended by:
- Forwardable
- Includes:
- Conversions
- Defined in:
- lib/honeybadger/notice.rb
Defined Under Namespace
Classes: Cause
Constant Summary collapse
- TAG_SEPERATOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The String character used to split tag strings.
/,|\s/.freeze
- TAG_SANITIZER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The Regexp used to strip invalid characters from individual tags.
/\s/.freeze
- PROJECT_ROOT_CACHE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Cache project path substitutions for backtrace lines.
{}
- GEM_ROOT_CACHE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Cache gem path substitutions for backtrace lines.
{}
- BACKTRACE_FILTERS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
A list of backtrace filters to run all the time.
[ lambda { |line| return line unless defined?(Gem) GEM_ROOT_CACHE[line] ||= Gem.path.reduce(line) do |line, path| line.sub(path, GEM_ROOT) end }, lambda { |line, config| return line unless config c = (PROJECT_ROOT_CACHE[config[:root]] ||= {}) return c[line] if c.has_key?(line) c[line] ||= if config.root_regexp line.sub(config.root_regexp, PROJECT_ROOT) else line end }, lambda { |line| line.sub(RELATIVE_ROOT, STRING_EMPTY) }, lambda { |line| line if line !~ %r{lib/honeybadger} } ].freeze
Constants included from Conversions
Conversions::MAX_CONTEXT_DEPTH
Instance Attribute Summary collapse
-
#action ⇒ Object
The action (if any) that was called in this request.
-
#api_key ⇒ Object
The API key used to deliver this notice.
-
#backtrace ⇒ Object
The backtrace from the given exception or hash.
-
#breadcrumbs ⇒ Breadcrumbs::Collector
The collection of captured breadcrumbs.
-
#cause ⇒ Object
The exception cause if available.
-
#causes ⇒ Cause
readonly
A list of exception causes (see Cause).
-
#cgi_data ⇒ Object
CGI variables such as HTTP_METHOD.
-
#component ⇒ Object
(also: #controller)
The component (if any) which was used in this request (usually the controller).
-
#context ⇒ Object
The context Hash.
-
#details ⇒ Object
Custom details data.
-
#error_class ⇒ Object
The name of the class of error (example: RuntimeError).
-
#error_message ⇒ Object
The message from the exception, or a general description of the error.
-
#exception ⇒ Object
readonly
The exception that caused this notice, if any.
-
#fingerprint ⇒ Object
Custom fingerprint for error, used to group similar errors together.
-
#id ⇒ Object
readonly
The unique ID of this notice which can be used to reference the error in Honeybadger.
-
#local_variables ⇒ Object
Local variables are extracted from first frame of backtrace.
-
#params ⇒ Object
(also: #parameters)
A hash of parameters from the query string or post body.
-
#request_id ⇒ Object
The ID of the request which caused this notice.
-
#session ⇒ Object
A hash of session data from the request.
-
#source ⇒ Object
readonly
Deprecated: Excerpt from source file.
-
#tags ⇒ Object
Tags which will be applied to error.
-
#url ⇒ Object
The URL at which the error occurred (if any).
Instance Method Summary collapse
-
#as_json(*args) ⇒ Hash
private
Template used to create JSON payload.
-
#halt! ⇒ Object
Halts the notice and the before_notify callback chain.
-
#halted? ⇒ Boolean
private
Determines if this notice will be discarded.
-
#ignore? ⇒ Boolean
private
Determines if this notice should be ignored.
-
#initialize(config, opts = {}) ⇒ Notice
constructor
private
A new instance of Notice.
-
#parsed_backtrace ⇒ Array<{:number, :file, :method => String}>
The parsed exception backtrace.
-
#to_json(*a) ⇒ Hash
Converts the notice to JSON.
Methods included from Conversions
Constructor Details
#initialize(config, opts = {}) ⇒ Notice
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Notice.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/honeybadger/notice.rb', line 190 def initialize(config, opts = {}) @now = Time.now.utc @pid = Process.pid @id = SecureRandom.uuid @stats = Util::Stats.all @opts = opts @config = config @rack_env = opts.fetch(:rack_env, nil) @request_sanitizer = Util::Sanitizer.new(filters: params_filters) @exception = unwrap_exception(opts[:exception]) self.error_class = exception_attribute(:error_class, 'Notice') {|exception| exception.class.name } self. = exception_attribute(:error_message, 'No message provided') do |exception| = exception.respond_to?(:detailed_message) ? exception.(highlight: false).sub(" (#{exception.class.name})", '') # Gems like error_highlight append the exception class name : exception. "#{exception.class.name}: #{}" end self.backtrace = exception_attribute(:backtrace, caller) self.cause = opts.key?(:cause) ? opts[:cause] : (exception_cause(@exception) || $!) self.context = construct_context_hash(opts, exception) self.local_variables = local_variables_from_exception(exception, config) self.api_key = opts[:api_key] || config[:api_key] self. = (opts[:tags]) | (context[:tags]) self.url = opts[:url] || request_hash[:url] || nil self.action = opts[:action] || request_hash[:action] || nil self.component = opts[:controller] || opts[:component] || request_hash[:component] || nil self.params = opts[:parameters] || opts[:params] || request_hash[:params] || {} self.session = opts[:session] || request_hash[:session] || {} self.cgi_data = opts[:cgi_data] || request_hash[:cgi_data] || {} self.details = opts[:details] || {} self.request_id = opts[:request_id] || nil self.session = opts[:session][:data] if opts[:session] && opts[:session][:data] self. = opts[:breadcrumbs] || Breadcrumbs::Collector.new(config) # Fingerprint must be calculated last since callback operates on `self`. self.fingerprint = fingerprint_from_opts(opts) end |
Instance Attribute Details
#action ⇒ Object
The action (if any) that was called in this request.
124 125 126 |
# File 'lib/honeybadger/notice.rb', line 124 def action @action end |
#api_key ⇒ Object
The API key used to deliver this notice.
136 137 138 |
# File 'lib/honeybadger/notice.rb', line 136 def api_key @api_key end |
#backtrace ⇒ Object
The backtrace from the given exception or hash.
91 92 93 |
# File 'lib/honeybadger/notice.rb', line 91 def backtrace @backtrace end |
#breadcrumbs ⇒ Breadcrumbs::Collector
Returns The collection of captured breadcrumbs.
142 143 144 |
# File 'lib/honeybadger/notice.rb', line 142 def @breadcrumbs end |
#cause ⇒ Object
The exception cause if available.
81 82 83 |
# File 'lib/honeybadger/notice.rb', line 81 def cause @cause end |
#causes ⇒ Cause (readonly)
Returns A list of exception causes (see Cause).
88 89 90 |
# File 'lib/honeybadger/notice.rb', line 88 def causes @causes end |
#cgi_data ⇒ Object
CGI variables such as HTTP_METHOD.
112 113 114 |
# File 'lib/honeybadger/notice.rb', line 112 def cgi_data @cgi_data end |
#component ⇒ Object Also known as: controller
The component (if any) which was used in this request (usually the controller).
119 120 121 |
# File 'lib/honeybadger/notice.rb', line 119 def component @component end |
#context ⇒ Object
The context Hash.
109 110 111 |
# File 'lib/honeybadger/notice.rb', line 109 def context @context end |
#details ⇒ Object
Custom details data
145 146 147 |
# File 'lib/honeybadger/notice.rb', line 145 def details @details end |
#error_class ⇒ Object
The name of the class of error (example: RuntimeError).
103 104 105 |
# File 'lib/honeybadger/notice.rb', line 103 def error_class @error_class end |
#error_message ⇒ Object
The message from the exception, or a general description of the error.
106 107 108 |
# File 'lib/honeybadger/notice.rb', line 106 def @error_message end |
#exception ⇒ Object (readonly)
The exception that caused this notice, if any.
78 79 80 |
# File 'lib/honeybadger/notice.rb', line 78 def exception @exception end |
#fingerprint ⇒ Object
Custom fingerprint for error, used to group similar errors together.
94 95 96 |
# File 'lib/honeybadger/notice.rb', line 94 def fingerprint @fingerprint end |
#id ⇒ Object (readonly)
The unique ID of this notice which can be used to reference the error in Honeybadger.
75 76 77 |
# File 'lib/honeybadger/notice.rb', line 75 def id @id end |
#local_variables ⇒ Object
Local variables are extracted from first frame of backtrace.
133 134 135 |
# File 'lib/honeybadger/notice.rb', line 133 def local_variables @local_variables end |
#params ⇒ Object Also known as: parameters
A hash of parameters from the query string or post body.
115 116 117 |
# File 'lib/honeybadger/notice.rb', line 115 def params @params end |
#request_id ⇒ Object
The ID of the request which caused this notice.
148 149 150 |
# File 'lib/honeybadger/notice.rb', line 148 def request_id @request_id end |
#session ⇒ Object
A hash of session data from the request.
127 128 129 |
# File 'lib/honeybadger/notice.rb', line 127 def session @session end |
#source ⇒ Object (readonly)
Deprecated: Excerpt from source file.
139 140 141 |
# File 'lib/honeybadger/notice.rb', line 139 def source @source end |
#tags ⇒ Object
Tags which will be applied to error.
97 98 99 |
# File 'lib/honeybadger/notice.rb', line 97 def @tags end |
#url ⇒ Object
The URL at which the error occurred (if any).
130 131 132 |
# File 'lib/honeybadger/notice.rb', line 130 def url @url end |
Instance Method Details
#as_json(*args) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Template used to create JSON payload.
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/honeybadger/notice.rb', line 240 def as_json(*args) request = construct_request_hash request[:context] = s(context) request[:local_variables] = local_variables if local_variables { api_key: s(api_key), notifier: NOTIFIER, breadcrumbs: , error: { token: id, class: s(error_class), message: s(), backtrace: s(parsed_backtrace), fingerprint: fingerprint_hash, tags: s(), causes: s(prepare_causes(causes)) }, details: s(details), request: request, server: { project_root: s(config[:root]), revision: s(config[:revision]), environment_name: s(config[:env]), hostname: s(config[:hostname]), stats: stats, time: now, pid: pid }, correlation_context: { request_id: s(request_id) } } end |
#halt! ⇒ Object
Halts the notice and the before_notify callback chain.
Returns nothing.
291 292 293 |
# File 'lib/honeybadger/notice.rb', line 291 def halt! @halted ||= true end |
#halted? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determines if this notice will be discarded.
297 298 299 |
# File 'lib/honeybadger/notice.rb', line 297 def halted? !!@halted end |
#ignore? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determines if this notice should be ignored.
284 285 286 |
# File 'lib/honeybadger/notice.rb', line 284 def ignore? ignore_by_origin? || ignore_by_class? || ignore_by_callbacks? end |
#parsed_backtrace ⇒ Array<{:number, :file, :method => String}>
The parsed exception backtrace. Lines in this backtrace that are from installed gems have the base path for gem installs replaced by “[GEM_ROOT]”, while those in the project have “[PROJECT_ROOT]”.
154 155 156 |
# File 'lib/honeybadger/notice.rb', line 154 def parsed_backtrace @parsed_backtrace ||= parse_backtrace(backtrace) end |
#to_json(*a) ⇒ Hash
Converts the notice to JSON.
278 279 280 |
# File 'lib/honeybadger/notice.rb', line 278 def to_json(*a) ::JSON.generate(as_json(*a)) end |