Class: Airbrake::Notice
- Inherits:
-
Object
- Object
- Airbrake::Notice
- Defined in:
- lib/airbrake-ruby/notice.rb
Overview
Represents a chunk of information that is meant to be either sent to Airbrake or ignored completely.
Constant Summary collapse
- CONTEXT =
Returns the information to be displayed in the Context tab in the dashboard.
{ os: RUBY_PLATFORM, language: "#{RUBY_ENGINE}/#{RUBY_VERSION}".freeze, notifier: Airbrake::NOTIFIER_INFO, }.freeze
- MAX_NOTICE_SIZE =
Returns the maxium size of the JSON payload in bytes.
64000
- PAYLOAD_MAX_SIZE =
Returns the maximum size of hashes, arrays and strings in the notice.
10000
- JSON_EXCEPTIONS =
Returns the list of possible exceptions that might be raised when an object is converted to JSON.
[ IOError, NotImplementedError, JSON::GeneratorError, Encoding::UndefinedConversionError, ].freeze
- WRITABLE_KEYS =
Returns the list of keys that can be be overwritten with #[]=.
%i[notifier context environment session params].freeze
- TRUNCATABLE_KEYS =
Returns parts of a Notice’s payload that can be modified by the truncator.
%i[errors environment session params].freeze
- HOSTNAME =
Returns the name of the host machine.
Socket.gethostname.freeze
- DEFAULT_SEVERITY =
'error'.freeze
Instance Attribute Summary
Attributes included from Ignorable
Instance Method Summary collapse
-
#[](key) ⇒ Object
Reads a value from notice’s payload.
-
#[]=(key, value) ⇒ void
Writes a value to the payload hash.
-
#initialize(exception, params = {}) ⇒ Notice
constructor
private
A new instance of Notice.
-
#to_json(*_args) ⇒ Hash{String=>String}?
private
Converts the notice to JSON.
Methods included from Stashable
Methods included from Loggable
Methods included from Ignorable
Constructor Details
#initialize(exception, params = {}) ⇒ 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.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/airbrake-ruby/notice.rb', line 50 def initialize(exception, params = {}) @config = Airbrake::Config.instance @truncator = Airbrake::Truncator.new(PAYLOAD_MAX_SIZE) @payload = { errors: NestedException.new(exception).as_json, context: context(exception), environment: { program_name: $PROGRAM_NAME, }, session: {}, params: params, } stash[:exception] = exception end |
Instance Method Details
#[](key) ⇒ Object
Reads a value from notice’s payload.
91 92 93 94 |
# File 'lib/airbrake-ruby/notice.rb', line 91 def [](key) raise_if_ignored @payload[key] end |
#[]=(key, value) ⇒ void
This method returns an undefined value.
Writes a value to the payload hash. Restricts unrecognized writes.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/airbrake-ruby/notice.rb', line 105 def []=(key, value) raise_if_ignored unless WRITABLE_KEYS.include?(key) raise Airbrake::Error, ":#{key} is not recognized among #{WRITABLE_KEYS}" end unless value.respond_to?(:to_hash) raise Airbrake::Error, "Got #{value.class} value, wanted a Hash" end @payload[key] = value.to_hash end |
#to_json(*_args) ⇒ Hash{String=>String}?
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.
Converts the notice to JSON. Calls to_json
on each object inside notice’s payload. Truncates notices, JSON representation of which is bigger than MAX_NOTICE_SIZE.
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/airbrake-ruby/notice.rb', line 73 def to_json(*_args) loop do begin json = @payload.to_json rescue *JSON_EXCEPTIONS => ex logger.debug("#{LOG_LABEL} `notice.to_json` failed: #{ex.class}: #{ex}") else return json if json && json.bytesize <= MAX_NOTICE_SIZE end break if truncate == 0 end end |