Commit 594f56e1 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'an-use-labkit-correlation-id' into 'master'

Remove all references to Gitlab::CorrelationId

See merge request gitlab-org/gitlab-ce!32228
parents 4e4fcf79 02347958
# frozen_string_literal: true
module Gitlab
module CorrelationId
LOG_KEY = 'correlation_id'.freeze
class << self
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
def current_id
ids.last
end
def current_or_new_id
current_id || new_id
end
private
def ids
Thread.current[:correlation_id] ||= []
end
def new_id
SecureRandom.uuid
end
end
end
end
...@@ -30,7 +30,7 @@ module Gitlab ...@@ -30,7 +30,7 @@ module Gitlab
# Avoid using `format` since it can throw TypeErrors # Avoid using `format` since it can throw TypeErrors
# which we want to avoid on unsanitised env var input # which we want to avoid on unsanitised env var input
tracing_url_template.to_s tracing_url_template.to_s
.gsub(/\{\{\s*correlation_id\s*\}\}/, Gitlab::CorrelationId.current_id.to_s) .gsub(/\{\{\s*correlation_id\s*\}\}/, Labkit::Correlation::CorrelationId.current_id.to_s)
.gsub(/\{\{\s*service\s*\}\}/, Gitlab.process_name) .gsub(/\{\{\s*service\s*\}\}/, Gitlab.process_name)
end end
end end
......
...@@ -59,7 +59,7 @@ describe Gitlab::Tracing do ...@@ -59,7 +59,7 @@ describe Gitlab::Tracing do
it 'returns the correct state for .tracing_url' do it 'returns the correct state for .tracing_url' do
expect(described_class).to receive(:tracing_url_enabled?).and_return(tracing_url_enabled?) expect(described_class).to receive(:tracing_url_enabled?).and_return(tracing_url_enabled?)
allow(described_class).to receive(:tracing_url_template).and_return(tracing_url_template) allow(described_class).to receive(:tracing_url_template).and_return(tracing_url_template)
allow(Gitlab::CorrelationId).to receive(:current_id).and_return(correlation_id) allow(Labkit::Correlation::CorrelationId).to receive(:current_id).and_return(correlation_id)
allow(Gitlab).to receive(:process_name).and_return(process_name) allow(Gitlab).to receive(:process_name).and_return(process_name)
expect(described_class.tracing_url).to eq(tracing_url) expect(described_class.tracing_url).to eq(tracing_url)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment