Module: EzLogsAgent::Correlation

Defined in:
lib/ez_logs_agent/correlation.rb

Constant Summary collapse

STORE_KEY =
:ez_logs_correlation_id

Class Method Summary collapse

Class Method Details

.clearvoid

This method returns an undefined value.

Clear the current correlation ID



36
37
38
# File 'lib/ez_logs_agent/correlation.rb', line 36

def self.clear
  RequestStore.store.delete(STORE_KEY)
end

.currentString?

Get the current correlation ID (or nil)

Returns:

  • (String, nil)

    The current correlation ID or nil if not set



21
22
23
# File 'lib/ez_logs_agent/correlation.rb', line 21

def self.current
  RequestStore.store[STORE_KEY]
end

.current=(value) ⇒ String?

Set the current correlation ID

Parameters:

  • value (String, nil)

    The correlation ID to store

Returns:

  • (String, nil)

    The stored value



29
30
31
# File 'lib/ez_logs_agent/correlation.rb', line 29

def self.current=(value)
  RequestStore.store[STORE_KEY] = value
end

.generateString

Generate a new unique correlation ID Format: ezl_<timestamp_ms>_<random_hex_8>

Returns:

  • (String)

    A new correlation ID



12
13
14
15
16
# File 'lib/ez_logs_agent/correlation.rb', line 12

def self.generate
  timestamp_ms = (Time.now.to_f * 1000).to_i
  random_hex = SecureRandom.hex(4) # 8 chars
  "ezl_#{timestamp_ms}_#{random_hex}"
end