Commit 834abb31 authored by Quang-Minh Nguyen's avatar Quang-Minh Nguyen
parent b72f27c0
...@@ -108,8 +108,9 @@ module Gitlab ...@@ -108,8 +108,9 @@ module Gitlab
end end
if logging if logging
log_hash = {} formater = Gitlab::ErrorTracking::LogFormatter.new
Gitlab::ErrorTracking::LogFormatter.format!(log_hash, exception, context_payload) log_hash = formater.generate_log(exception, context_payload)
Gitlab::ErrorTracking::Logger.error(log_hash) Gitlab::ErrorTracking::Logger.error(log_hash)
end end
end end
......
...@@ -6,28 +6,34 @@ module Gitlab ...@@ -6,28 +6,34 @@ module Gitlab
# Note: all the accesses to Raven's contexts here are to keep the # Note: all the accesses to Raven's contexts here are to keep the
# backward-compatibility to Sentry's built-in integrations. In future, # backward-compatibility to Sentry's built-in integrations. In future,
# they can be removed. # they can be removed.
def self.format!(payload, exception, context_payload) def generate_log(exception, context_payload)
payload = {}
Gitlab::ExceptionLogFormatter.format!(exception, payload) Gitlab::ExceptionLogFormatter.format!(exception, payload)
append_user_to_log!(payload, context_payload) append_user_to_log!(payload, context_payload)
append_tags_to_log!(payload, context_payload) append_tags_to_log!(payload, context_payload)
append_extra_to_log!(payload, context_payload) append_extra_to_log!(payload, context_payload)
payload
end end
def self.append_user_to_log!(payload, context_payload) private
def append_user_to_log!(payload, context_payload)
user_context = Raven.context.user.merge(context_payload[:user]) user_context = Raven.context.user.merge(context_payload[:user])
user_context.each do |key, value| user_context.each do |key, value|
payload["user.#{key}"] = value payload["user.#{key}"] = value
end end
end end
def self.append_tags_to_log!(payload, context_payload) def append_tags_to_log!(payload, context_payload)
tags_context = Raven.context.tags.merge(context_payload[:tags]) tags_context = Raven.context.tags.merge(context_payload[:tags])
tags_context.each do |key, value| tags_context.each do |key, value|
payload["tags.#{key}"] = value payload["tags.#{key}"] = value
end end
end end
def self.append_extra_to_log!(payload, context_payload) def append_extra_to_log!(payload, context_payload)
extra = Raven.context.extra.merge(context_payload[:extra]) extra = Raven.context.extra.merge(context_payload[:extra])
extra = extra.except(:server) extra = extra.except(:server)
......
...@@ -43,9 +43,7 @@ RSpec.describe Gitlab::ErrorTracking::LogFormatter do ...@@ -43,9 +43,7 @@ RSpec.describe Gitlab::ErrorTracking::LogFormatter do
end end
it 'appends error-related log fields' do it 'appends error-related log fields' do
payload = {} payload = described_class.new.generate_log(exception, context_payload)
described_class.format!(payload, exception, context_payload)
expect(payload).to eql( expect(payload).to eql(
'exception.class' => 'StandardError', 'exception.class' => 'StandardError',
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
require 'rspec-parameterized'
RSpec.describe Gitlab::ErrorTracking::Processor::ContextPayloadProcessor do RSpec.describe Gitlab::ErrorTracking::Processor::ContextPayloadProcessor do
subject(:processor) { described_class.new } subject(:processor) { described_class.new }
......
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