Add correlation id to all sentry errors
Before this, we were only adding the correlation id to the "acceptable exceptions" which we handle in code. But we need to add it to the default raven context so the information would be available for uncaught exceptions.
This commit is contained in:
parent
9dc41a0993
commit
4c2f681490
|
@ -10,7 +10,7 @@ module Gitlab
|
||||||
def self.context(current_user = nil)
|
def self.context(current_user = nil)
|
||||||
return unless enabled?
|
return unless enabled?
|
||||||
|
|
||||||
Raven.tags_context(locale: I18n.locale)
|
Raven.tags_context(default_tags)
|
||||||
|
|
||||||
if current_user
|
if current_user
|
||||||
Raven.user_context(
|
Raven.user_context(
|
||||||
|
@ -44,16 +44,19 @@ module Gitlab
|
||||||
extra[:issue_url] = issue_url if issue_url
|
extra[:issue_url] = issue_url if issue_url
|
||||||
context # Make sure we've set everything we know in the context
|
context # Make sure we've set everything we know in the context
|
||||||
|
|
||||||
tags = {
|
Raven.capture_exception(exception, tags: default_tags, extra: extra)
|
||||||
Labkit::Correlation::CorrelationId::LOG_KEY.to_sym => Labkit::Correlation::CorrelationId.current_id
|
|
||||||
}
|
|
||||||
|
|
||||||
Raven.capture_exception(exception, tags: tags, extra: extra)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.should_raise_for_dev?
|
def self.should_raise_for_dev?
|
||||||
Rails.env.development? || Rails.env.test?
|
Rails.env.development? || Rails.env.test?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.default_tags
|
||||||
|
{
|
||||||
|
Labkit::Correlation::CorrelationId::LOG_KEY.to_sym => Labkit::Correlation::CorrelationId.current_id,
|
||||||
|
locale: I18n.locale
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,12 +2,15 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe Gitlab::Sentry do
|
describe Gitlab::Sentry do
|
||||||
describe '.context' do
|
describe '.context' do
|
||||||
it 'adds the locale to the tags' do
|
it 'adds the expected tags' do
|
||||||
expect(described_class).to receive(:enabled?).and_return(true)
|
expect(described_class).to receive(:enabled?).and_return(true)
|
||||||
|
allow(Labkit::Correlation::CorrelationId).to receive(:current_id).and_return('cid')
|
||||||
|
|
||||||
described_class.context(nil)
|
described_class.context(nil)
|
||||||
|
|
||||||
expect(Raven.tags_context[:locale].to_s).to eq(I18n.locale.to_s)
|
expect(Raven.tags_context[:locale].to_s).to eq(I18n.locale.to_s)
|
||||||
|
expect(Raven.tags_context[Labkit::Correlation::CorrelationId::LOG_KEY.to_sym].to_s)
|
||||||
|
.to eq('cid')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -247,9 +247,8 @@ describe API::Helpers do
|
||||||
exception = RuntimeError.new('test error')
|
exception = RuntimeError.new('test error')
|
||||||
allow(exception).to receive(:backtrace).and_return(caller)
|
allow(exception).to receive(:backtrace).and_return(caller)
|
||||||
|
|
||||||
expect(Raven).to receive(:capture_exception).with(exception, tags: {
|
expect(Raven).to receive(:capture_exception).with(exception, tags:
|
||||||
correlation_id: 'new-correlation-id'
|
a_hash_including(correlation_id: 'new-correlation-id'), extra: {})
|
||||||
}, extra: {})
|
|
||||||
|
|
||||||
Labkit::Correlation::CorrelationId.use_id('new-correlation-id') do
|
Labkit::Correlation::CorrelationId.use_id('new-correlation-id') do
|
||||||
handle_api_exception(exception)
|
handle_api_exception(exception)
|
||||||
|
|
Loading…
Reference in New Issue