Class: Contrast::Agent::Telemetry::Exception::Message

Inherits:
Base
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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, tags, exceptions
  super()
  @tags = tags
  @timestamp = Time.now.iso8601
  @instance = instance
  @occurrences = 1
  @exceptions = exceptions
  validate(VALIDATIONS)
end

Instance Attribute Details

#exceptionsArray<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

#instanceString (readonly)

An Instance ID as defined in Unique Identification // Application ID

Returns:



33
34
35
# File 'lib/contrast/agent/telemetry/exception/message.rb', line 33

def instance
  @instance
end

#loggerString?

Returns A string denoting the origin of this error.

Returns:

  • (String, nil)

    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

#messageString | nil

Returns A string message to provide additional context to the errors.

Returns:

  • (String | nil)

    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
  @message
end

#occurrencesInteger

Returns A number of the occurrences of the exception.

Returns:

  • (Integer)

    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

#tagsHash{String => String} (readonly)

Tags are key-value string pairs that annotate either metrics or errors to help provide context, filtering, grouping, and deduplication.

Returns:



38
39
40
# File 'lib/contrast/agent/telemetry/exception/message.rb', line 38

def tags
  @tags
end

#timestampInteger (readonly)

Timestamp of creation in ISO8601 format

Returns:

  • (Integer)


29
30
31
# File 'lib/contrast/agent/telemetry/exception/message.rb', line 29

def timestamp
  @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 tags, exceptions, logger = nil, message = nil
  inst = new(Contrast::Agent::Telemetry::Identifier.instance_id, tags, exceptions)
  inst.logger = logger unless logger.nil?
  inst.message = message unless message.nil?
  inst
end

Instance Method Details

#increment_occurrencesObject

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_hashObject



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: timestamp,
      instance: instance,
      occurrences: occurrences,
      tags: tags,
      exceptions: exceptions.map(&:to_controlled_hash),
      logger: logger,
      message: message
  }.compact
end