Module: Labkit::Correlation::CorrelationId

Defined in:
lib/labkit/correlation/correlation_id.rb

Overview

CorrelationId module provides access the Correlation-ID of the current request

Constant Summary collapse

LOG_KEY =
"correlation_id"

Class Method Summary collapse

Class Method Details

.current_idObject



24
25
26
# File 'lib/labkit/correlation/correlation_id.rb', line 24

def current_id
  ids.last
end

.current_or_new_idObject



28
29
30
# File 'lib/labkit/correlation/correlation_id.rb', line 28

def current_or_new_id
  current_id || new_id
end

.use_id(correlation_id, &_blk) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/labkit/correlation/correlation_id.rb', line 11

def use_id(correlation_id, &_blk)
  # always generate a id if null is passed
  correlation_id ||= new_id

  ids.push(correlation_id || new_id)

  begin
    yield(current_id)
  ensure
    ids.pop
  end
end