File: correlation_id.rb

package info (click to toggle)
ruby-gitlab-labkit 0.36.1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 444 kB
  • sloc: ruby: 1,705; makefile: 6
file content (27 lines) | stat: -rw-r--r-- 645 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

module Labkit
  module Correlation
    # CorrelationId module provides access the Correlation-ID
    # of the current request
    module CorrelationId
      LOG_KEY = Labkit::Context::CORRELATION_ID_KEY

      class << self
        def use_id(correlation_id)
          Labkit::Context.with_context(LOG_KEY => correlation_id) do |context|
            yield(context.correlation_id)
          end
        end

        def current_id
          Labkit::Context.correlation_id
        end

        def current_or_new_id
          current_id || Labkit::Context.push.correlation_id
        end
      end
    end
  end
end