Class: Contrast::Agent::Telemetry::Exception::Message
- Defined in:
- lib/contrast/agent/telemetry/exception/message.rb
Overview
This class will hold the all the information for the specific exceptions and will be passed in the the event to be sent to TS
Constant Summary collapse
- VALIDATIONS =
{ instance: { required: true, range: 12..64 }, tags: { required: true, range: 0..512 }, logger: { required: false, range: 1..128 }, message: { required: false, range: 1..512 }, exceptions: { required: true, range: 1..512, class: Contrast::Agent::Telemetry::Exception::MessageException } }.cs__freeze
Instance Attribute Summary collapse
-
#exceptions ⇒ Array<Contrast::Agent::Telemetry::Exception::MessageException>
readonly
Array of exceptions, but in our case the Array will only include one exception.
-
#instance ⇒ String
readonly
An Instance ID as defined in Unique Identification // Application ID.
-
#logger ⇒ String?
A string denoting the origin of this error.
-
#message ⇒ String | nil
A string message to provide additional context to the errors.
-
#occurrences ⇒ Integer
A number of the occurrences of the exception.
-
#tags ⇒ Hash{String => String}
readonly
Tags are key-value string pairs that annotate either metrics or errors to help provide context, filtering, grouping, and deduplication.
-
#timestamp ⇒ Integer
readonly
Timestamp of creation in ISO8601 format.
Class Method Summary collapse
Instance Method Summary collapse
-
#increment_occurrences ⇒ Object
Optional parameters will be set separately from the required This method is different and is regarding the way we proceed with incrementing occurrences If we keep track of them in different places and we store that value in separated variable - we may directly re-assign occurrences= But if we are not doing that - we may on same message generated to increment occurrences from here.
-
#initialize(instance, tags, exceptions) ⇒ Message
constructor
@raise.
- #to_controlled_hash ⇒ Object
Constructor Details
#initialize(instance, tags, exceptions) ⇒ Message
54 55 56 57 58 59 60 61 62 |
# File 'lib/contrast/agent/telemetry/exception/message.rb', line 54 def initialize instance, , exceptions super() @tags = @timestamp = Time.now.iso8601 @instance = instance @occurrences = 1 @exceptions = exceptions validate(VALIDATIONS) end |
Instance Attribute Details
#exceptions ⇒ Array<Contrast::Agent::Telemetry::Exception::MessageException> (readonly)
Array of exceptions, but in our case the Array will only include one exception
45 46 47 |
# File 'lib/contrast/agent/telemetry/exception/message.rb', line 45 def exceptions @exceptions end |
#instance ⇒ String (readonly)
An Instance ID as defined in Unique Identification // Application ID
33 34 35 |
# File 'lib/contrast/agent/telemetry/exception/message.rb', line 33 def instance @instance end |
#logger ⇒ String?
Returns A string denoting the origin of this error.
48 49 50 |
# File 'lib/contrast/agent/telemetry/exception/message.rb', line 48 def logger @logger end |
#message ⇒ String | nil
Returns A string message to provide additional context to the errors.
51 52 53 |
# File 'lib/contrast/agent/telemetry/exception/message.rb', line 51 def @message end |
#occurrences ⇒ Integer
Returns A number of the occurrences of the exception.
41 42 43 |
# File 'lib/contrast/agent/telemetry/exception/message.rb', line 41 def occurrences @occurrences end |
#tags ⇒ Hash{String => String} (readonly)
Tags are key-value string pairs that annotate either metrics or errors to help provide context, filtering, grouping, and deduplication.
38 39 40 |
# File 'lib/contrast/agent/telemetry/exception/message.rb', line 38 def @tags end |
#timestamp ⇒ Integer (readonly)
Timestamp of creation in ISO8601 format
29 30 31 |
# File 'lib/contrast/agent/telemetry/exception/message.rb', line 29 def @timestamp end |
Class Method Details
.build(tags, exceptions, logger = nil, message = nil) ⇒ Object
107 108 109 110 111 112 |
# File 'lib/contrast/agent/telemetry/exception/message.rb', line 107 def build , exceptions, logger = nil, = nil inst = new(Contrast::Agent::Telemetry::Identifier.instance_id, , exceptions) inst.logger = logger unless logger.nil? inst. = unless .nil? inst end |
Instance Method Details
#increment_occurrences ⇒ Object
Optional parameters will be set separately from the required This method is different and is regarding the way we proceed with incrementing occurrences If we keep track of them in different places and we store that value in separated variable - we may directly re-assign occurrences= But if we are not doing that - we may on same message generated to increment occurrences from here
89 90 91 |
# File 'lib/contrast/agent/telemetry/exception/message.rb', line 89 def increment_occurrences @occurrences += 1 end |
#to_controlled_hash ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/contrast/agent/telemetry/exception/message.rb', line 93 def to_controlled_hash super() { timestamp: , instance: instance, occurrences: occurrences, tags: , exceptions: exceptions.map(&:to_controlled_hash), logger: logger, message: }.compact end |