Commit 0fe4cf2b authored by Stan Hu's avatar Stan Hu

Fix Sentry not reporting right program for Sidekiq workers

Moves program tag into the global configuration since this doesn't
change and since Sidekiq workers get a unique context for each event.

Closes #21410
parent 1bf2fe27
module SentryHelper module SentryHelper
def sentry_enabled? def sentry_enabled?
Rails.env.production? && current_application_settings.sentry_enabled? Gitlab::Sentry.enabled?
end end
def sentry_context def sentry_context
return unless sentry_enabled? Gitlab::Sentry.context(current_user)
if current_user
Raven.user_context(
id: current_user.id,
email: current_user.email,
username: current_user.username,
)
end
Raven.tags_context(program: sentry_program_context)
end
def sentry_program_context
if Sidekiq.server?
'sidekiq'
else
'rails'
end
end end
end end
...@@ -18,6 +18,7 @@ if Rails.env.production? ...@@ -18,6 +18,7 @@ if Rails.env.production?
# Sanitize fields based on those sanitized from Rails. # Sanitize fields based on those sanitized from Rails.
config.sanitize_fields = Rails.application.config.filter_parameters.map(&:to_s) config.sanitize_fields = Rails.application.config.filter_parameters.map(&:to_s)
config.tags = { program: Gitlab::Sentry.program_context }
end end
end end
end end
module Gitlab
module Sentry
def self.enabled?
Rails.env.production? && current_application_settings.sentry_enabled?
end
def self.context(current_user = nil)
return unless self.enabled?
if current_user
Raven.user_context(
id: current_user.id,
email: current_user.email,
username: current_user.username,
)
end
end
def self.program_context
if Sidekiq.server?
'sidekiq'
else
'rails'
end
end
end
end
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