Class: Contrast::Agent::Telemetry::Base64Hash

Inherits:
Hash
  • Object
show all
Includes:
Components::Logger::InstanceMethods
Defined in:
lib/contrast/agent/telemetry/base64_hash.rb

Overview

This hash will store the telemetry data for the Protect InputAnalysis cache.

Constant Summary collapse

HASH_SIZE_LIMIT =

Set per request:

100

Instance Method Summary collapse

Methods included from Components::Logger::InstanceMethods

#cef_logger, #logger

Instance Method Details

#[]=(key, events) ⇒ Object?

Wrapper to set a value in this Telemetry::Hash only if the provided value is of the data_type for this Telemetry::CacheHash or the hash has not reached its limit for unique keys. Saves Array of reportable events.

Parameters:

  • key (Object)

    the key to which to associate the value

  • events (array<Object>)

Returns:

  • (Object, nil)

    echo back out the value as the Hash#[]= method does, or nil if not of the expected data_type



23
24
25
26
27
28
29
30
31
32
# File 'lib/contrast/agent/telemetry/base64_hash.rb', line 23

def []= key, events
  # If telemetry is not running, do not add more as we want to avoid a memory leak.
  return unless Contrast::Agent.telemetry_queue&.running?
  # If the Hash is full, do not add more as we want to avoid consuming all application resources.
  return if at_limit?
  # If the given value is of unexpected type, do not add it to avoid issues later where type is assumed.
  return unless valid_event?(events)

  super(key, events)
end

#at_limit?Boolean

Determine if hash has reached exception event limit.

Returns:

  • (Boolean)


37
38
39
40
41
42
43
# File 'lib/contrast/agent/telemetry/base64_hash.rb', line 37

def at_limit?
  unless length < HASH_SIZE_LIMIT
    logger.debug("[Telemetry] Number of IA base64 events exceeds limit of #{ HASH_SIZE_LIMIT }")
    return true
  end
  false
end