2016-08-24 23:06:16 -04:00
|
|
|
module Gitlab
|
|
|
|
module Sentry
|
|
|
|
def self.enabled?
|
2018-02-02 13:39:55 -05:00
|
|
|
Rails.env.production? && Gitlab::CurrentSettings.sentry_enabled?
|
2016-08-24 23:06:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.context(current_user = nil)
|
|
|
|
return unless self.enabled?
|
|
|
|
|
2017-07-20 02:53:57 -04:00
|
|
|
Raven.tags_context(locale: I18n.locale)
|
|
|
|
|
2016-08-24 23:06:16 -04:00
|
|
|
if current_user
|
|
|
|
Raven.user_context(
|
|
|
|
id: current_user.id,
|
|
|
|
email: current_user.email,
|
2017-05-03 07:27:17 -04:00
|
|
|
username: current_user.username
|
2016-08-24 23:06:16 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-13 12:32:54 -04:00
|
|
|
# This can be used for investigating exceptions that can be recovered from in
|
|
|
|
# code. The exception will still be raised in development and test
|
|
|
|
# environments.
|
|
|
|
#
|
|
|
|
# That way we can track down these exceptions with as much information as we
|
|
|
|
# need to resolve them.
|
|
|
|
#
|
|
|
|
# Provide an issue URL for follow up.
|
|
|
|
def self.track_exception(exception, issue_url: nil, extra: {})
|
|
|
|
if enabled?
|
|
|
|
extra[:issue_url] = issue_url if issue_url
|
|
|
|
context # Make sure we've set everything we know in the context
|
|
|
|
|
|
|
|
Raven.capture_exception(exception, extra: extra)
|
|
|
|
end
|
|
|
|
|
|
|
|
raise exception if should_raise?
|
|
|
|
end
|
|
|
|
|
2016-08-24 23:06:16 -04:00
|
|
|
def self.program_context
|
|
|
|
if Sidekiq.server?
|
|
|
|
'sidekiq'
|
|
|
|
else
|
|
|
|
'rails'
|
|
|
|
end
|
|
|
|
end
|
2018-04-13 12:32:54 -04:00
|
|
|
|
|
|
|
def self.should_raise?
|
|
|
|
Rails.env.development? || Rails.env.test?
|
|
|
|
end
|
2016-08-24 23:06:16 -04:00
|
|
|
end
|
|
|
|
end
|