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