Class: Honeybadger::Notice
- Inherits:
-
Object
- Object
- Honeybadger::Notice
- Extended by:
- Forwardable
- Defined in:
- lib/honeybadger/notice.rb
Constant Summary collapse
- TAG_SEPERATOR =
Internal: The String character used to split tag strings.
','.freeze
- TAG_SANITIZER =
Internal: The Regexp used to strip invalid characters from individual tags.
/[^\w]/.freeze
- PROJECT_ROOT_CACHE =
Internal: Cache project path substitutions for backtrace lines.
{}
- GEM_ROOT_CACHE =
Internal: Cache gem path substitutions for backtrace lines.
{}
- BACKTRACE_FILTERS =
Internal: 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
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Public: The API key used to deliver this notice.
-
#backtrace ⇒ Object
readonly
Public: The backtrace from the given exception or hash.
-
#error_class ⇒ Object
readonly
Public: The name of the class of error.
-
#error_message ⇒ Object
readonly
Public: The message from the exception, or a general description of the error.
-
#exception ⇒ Object
readonly
Public: The exception that caused this notice, if any.
-
#fingerprint ⇒ Object
readonly
Public: Custom fingerprint for error, used to group similar errors together.
-
#id ⇒ Object
readonly
Public: The unique ID of this notice which can be used to reference the error in Honeybadger.
-
#local_variables ⇒ Object
readonly
Public: Local variables are extracted from first frame of backtrace.
-
#source ⇒ Object
readonly
Public: Excerpt from source file.
-
#tags ⇒ Object
readonly
Public: Tags which will be applied to error.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](method) ⇒ Object
Public: Allows properties to be accessed using a hash-like syntax.
-
#action ⇒ Object
Public: The action (if any) that was called in this request.
-
#as_json(*args) ⇒ Object
Internal: Template used to create JSON payload.
-
#cgi_data ⇒ Object
Public: CGI variables such as HTTP_METHOD.
-
#component ⇒ Object
(also: #controller)
Public: The component (if any) which was used in this request.
-
#ignore? ⇒ Boolean
Internal: Determines if this notice should be ignored.
-
#initialize(config, opts = {}) ⇒ Notice
constructor
A new instance of Notice.
-
#params ⇒ Object
(also: #parameters)
Public: A hash of parameters from the query string or post body.
- #session ⇒ Object
-
#to_json(*a) ⇒ Object
Public: Creates JSON.
-
#url ⇒ Object
Public: The URL at which the error occurred (if any).
Constructor Details
#initialize(config, opts = {}) ⇒ Notice
Returns a new instance of Notice.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/honeybadger/notice.rb', line 125 def initialize(config, opts = {}) @now = Time.now.utc @pid = Process.pid @id = SecureRandom.uuid @opts = opts @config = config @sanitizer = Util::Sanitizer.new @exception = unwrap_exception(opts[:exception]) @error_class = exception_attribute(:error_class) {|exception| exception.class.name } @error_message = exception_attribute(:error_message, 'Notification') do |exception| "#{exception.class.name}: #{exception.}" end @backtrace = parse_backtrace(exception_attribute(:backtrace, caller)) @source = extract_source_from_backtrace(@backtrace, config, opts) @fingerprint = construct_fingerprint(opts) @request = construct_request_hash(config, opts) @context = construct_context_hash(opts) @causes = unwrap_causes(@exception) @tags = (opts[:tags]) @tags = (context[:tags]) | @tags if context @stats = Util::Stats.all @local_variables = local_variables_from_exception(exception, config) @api_key = opts[:api_key] || config[:api_key] monkey_patch_action_dispatch_test_process! end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Public: The API key used to deliver this notice.
95 96 97 |
# File 'lib/honeybadger/notice.rb', line 95 def api_key @api_key end |
#backtrace ⇒ Object (readonly)
Public: The backtrace from the given exception or hash.
53 54 55 |
# File 'lib/honeybadger/notice.rb', line 53 def backtrace @backtrace end |
#error_class ⇒ Object (readonly)
Public: The name of the class of error. (example: RuntimeError)
62 63 64 |
# File 'lib/honeybadger/notice.rb', line 62 def error_class @error_class end |
#error_message ⇒ Object (readonly)
Public: The message from the exception, or a general description of the error.
65 66 67 |
# File 'lib/honeybadger/notice.rb', line 65 def @error_message end |
#exception ⇒ Object (readonly)
Public: The exception that caused this notice, if any.
50 51 52 |
# File 'lib/honeybadger/notice.rb', line 50 def exception @exception end |
#fingerprint ⇒ Object (readonly)
Public: Custom fingerprint for error, used to group similar errors together.
56 57 58 |
# File 'lib/honeybadger/notice.rb', line 56 def fingerprint @fingerprint end |
#id ⇒ Object (readonly)
Public: The unique ID of this notice which can be used to reference the error in Honeybadger.
47 48 49 |
# File 'lib/honeybadger/notice.rb', line 47 def id @id end |
#local_variables ⇒ Object (readonly)
Public: Local variables are extracted from first frame of backtrace.
92 93 94 |
# File 'lib/honeybadger/notice.rb', line 92 def local_variables @local_variables end |
#source ⇒ Object (readonly)
Public: Excerpt from source file.
68 69 70 |
# File 'lib/honeybadger/notice.rb', line 68 def source @source end |
#tags ⇒ Object (readonly)
Public: Tags which will be applied to error.
59 60 61 |
# File 'lib/honeybadger/notice.rb', line 59 def @tags end |
Class Method Details
.session ⇒ Object
476 477 478 |
# File 'lib/honeybadger/notice.rb', line 476 def @request.session @table[:session] end |
Instance Method Details
#[](method) ⇒ Object
Public: Allows properties to be accessed using a hash-like syntax
method - The given key for an attribute
Examples:
notice[:error_message]
Returns the attribute value, or self if given :request
210 211 212 213 214 215 216 217 |
# File 'lib/honeybadger/notice.rb', line 210 def [](method) case method when :request self else send(method) end end |
#action ⇒ Object
Public: The action (if any) that was called in this request.
82 |
# File 'lib/honeybadger/notice.rb', line 82 def action; @request[:action]; end |
#as_json(*args) ⇒ Object
Internal: Template used to create JSON payload
Returns Hash JSON representation of notice
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/honeybadger/notice.rb', line 165 def as_json(*args) { api_key: s(api_key), notifier: NOTIFIER, error: { token: id, class: s(error_class), message: s(), backtrace: s(backtrace), source: s(source), fingerprint: s(fingerprint), tags: s(), causes: s(causes) }, request: @request.update({ context: s(context), local_variables: s(local_variables) }), server: { project_root: s(config[:root]), environment_name: s(config[:env]), hostname: s(config[:hostname]), stats: stats, time: now, pid: pid } } end |
#cgi_data ⇒ Object
Public: CGI variables such as HTTP_METHOD.
71 |
# File 'lib/honeybadger/notice.rb', line 71 def cgi_data; @request[:cgi_data]; end |
#component ⇒ Object Also known as: controller
Public: The component (if any) which was used in this request. (usually the controller)
78 |
# File 'lib/honeybadger/notice.rb', line 78 def component; @request[:component]; end |
#ignore? ⇒ Boolean
Internal: Determines if this notice should be ignored
220 221 222 |
# File 'lib/honeybadger/notice.rb', line 220 def ignore? ignore_by_origin? || ignore_by_class? || ignore_by_callbacks? end |
#params ⇒ Object Also known as: parameters
Public: A hash of parameters from the query string or post body.
74 |
# File 'lib/honeybadger/notice.rb', line 74 def params; @request[:params]; end |
#session ⇒ Object
86 |
# File 'lib/honeybadger/notice.rb', line 86 def session; @request[:session]; end |
#to_json(*a) ⇒ Object
Public: Creates JSON
Returns valid JSON representation of Notice
197 198 199 |
# File 'lib/honeybadger/notice.rb', line 197 def to_json(*a) ::JSON.generate(as_json(*a)) end |
#url ⇒ Object
Public: The URL at which the error occurred (if any).
89 |
# File 'lib/honeybadger/notice.rb', line 89 def url; @request[:url]; end |