Module: ForestAdminAgent::Http::CorrelationId

Defined in:
lib/forest_admin_agent/http/correlation_id.rb

Overview

Per-request correlation id, generated by the agent. Shared between the caller (so the audit trail can group every change made within one request) and the response header echoed back to the client. Mirrors the Node agent's context.state.requestId + x-forest-correlation-id header: the agent generates the id, never reads it from the incoming request.

Stored thread-locally and generated lazily on first read (e.g. when the caller is parsed). The host resets it at the start of each request so a pooled thread never reuses a previous id.

Constant Summary collapse

HEADER =
'x-forest-correlation-id'.freeze
KEY =
:forest_admin_correlation_id

Class Method Summary collapse

Class Method Details

.currentObject

Lazily generate and memoize the id for the current request/thread.



19
20
21
# File 'lib/forest_admin_agent/http/correlation_id.rb', line 19

def current
  Thread.current[KEY] ||= SecureRandom.uuid
end

.current=(value) ⇒ Object



28
29
30
# File 'lib/forest_admin_agent/http/correlation_id.rb', line 28

def current=(value)
  Thread.current[KEY] = value
end

.current?Boolean

The id if one was generated during this request, otherwise nil (does not generate one).

Returns:

  • (Boolean)


24
25
26
# File 'lib/forest_admin_agent/http/correlation_id.rb', line 24

def current?
  Thread.current[KEY]
end

.reset!Object



32
33
34
# File 'lib/forest_admin_agent/http/correlation_id.rb', line 32

def reset!
  Thread.current[KEY] = nil
end