Prefer to use correlation-id in logs

This changes `correlation_id` to be `correlation-id` when passed via jobs
This commit is contained in:
Kamil Trzciński 2018-12-06 20:49:31 +01:00
parent 39c1731a53
commit 3560b11922
9 changed files with 12 additions and 12 deletions

View file

@ -2,7 +2,7 @@
module Gitlab
module CorrelationId
LOG_KEY = 'correlation_id'.freeze
LOG_KEY = 'correlation-id'.freeze
class << self
def use_id(correlation_id, &blk)

View file

@ -193,7 +193,7 @@ module Gitlab
feature = feature_stack && feature_stack[0]
metadata['call_site'] = feature.to_s if feature
metadata['gitaly-servers'] = address_metadata(remote_storage) if remote_storage
metadata['correlation_id'] = Gitlab::CorrelationId.current_id if Gitlab::CorrelationId.current_id
metadata[Gitlab::CorrelationId::LOG_KEY] = Gitlab::CorrelationId.current_id if Gitlab::CorrelationId.current_id
metadata.merge!(server_feature_flags)

View file

@ -45,7 +45,7 @@ module Gitlab
context # Make sure we've set everything we know in the context
tags = {
Gitlab::CorrelationId::LOG_KEY.to_sym => Gitlab::CorrelationId.current_id
correlation_id: Gitlab::CorrelationId.current_id
}
Raven.capture_exception(exception, tags: tags, extra: extra)

View file

@ -465,7 +465,7 @@ describe ApplicationController do
get :index
end
expect(controller.last_payload).to include('correlation_id' => 'new-id')
expect(controller.last_payload).to include('correlation-id' => 'new-id')
end
context '422 errors' do

View file

@ -11,7 +11,7 @@ describe 'lograge', type: :request do
it 'logs to api_json log' do
# we assert receiving parameters by grape logger
expect_any_instance_of(Gitlab::GrapeLogging::Formatters::LogrageWithTimestamp).to receive(:call)
.with(anything, anything, anything, a_hash_including("correlation_id" => "new-correlation-id"))
.with(anything, anything, anything, a_hash_including("correlation-id" => "new-correlation-id"))
.and_call_original
subject
@ -24,12 +24,12 @@ describe 'lograge', type: :request do
it 'logs to production_json log' do
# formatter receives a hash with correlation id
expect(Lograge.formatter).to receive(:call)
.with(a_hash_including("correlation_id" => "new-correlation-id"))
.with(a_hash_including("correlation-id" => "new-correlation-id"))
.and_call_original
# a log file receives a line with correlation id
expect(Lograge.logger).to receive(:send)
.with(anything, include('"correlation_id":"new-correlation-id"'))
.with(anything, include('"correlation-id":"new-correlation-id"'))
.and_call_original
subject

View file

@ -18,7 +18,7 @@ describe Gitlab::JsonLogger do
expect(data['severity']).to eq('INFO')
expect(data['time']).to eq(now.utc.iso8601(3))
expect(data['message']).to eq('Hello world')
expect(data['correlation_id']).to eq('new-correlation-id')
expect(data['correlation-id']).to eq('new-correlation-id')
end
it 'formats hashes' do
@ -29,7 +29,7 @@ describe Gitlab::JsonLogger do
expect(data['time']).to eq(now.utc.iso8601(3))
expect(data['hello']).to eq(1)
expect(data['message']).to be_nil
expect(data['correlation_id']).to eq('new-correlation-id')
expect(data['correlation-id']).to eq('new-correlation-id')
end
end
end

View file

@ -13,7 +13,7 @@ describe Gitlab::SidekiqLogging::StructuredLogger do
"jid" => "da883554ee4fe414012f5f42",
"created_at" => timestamp.to_f,
"enqueued_at" => timestamp.to_f,
"correlation_id" => 'cid'
"correlation-id" => 'cid'
}
end
let(:logger) { double() }

View file

@ -37,7 +37,7 @@ describe Gitlab::SidekiqMiddleware::CorrelationInjector do
expected_job_params = {
"class" => "TestWorker",
"args" => [1234],
"correlation_id" => "new-correlation-id"
"correlation-id" => "new-correlation-id"
}
expect(Sidekiq::Queues.jobs_by_worker).to a_hash_including(

View file

@ -30,6 +30,6 @@ describe Gitlab::SidekiqMiddleware::CorrelationLogger do
'queue' => 'test',
'class' => TestWorker,
'args' => [1234],
'correlation_id' => 'new-correlation-id')
'correlation-id' => 'new-correlation-id')
end
end