summaryrefslogtreecommitdiff
path: root/lib/gitlab/sentry.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2016-08-24 20:06:16 -0700
committerStan Hu <stanhu@gmail.com>2016-08-25 19:42:52 -0700
commit0fe4cf2b0fdbc33572f11bba1a4426ee05ed7599 (patch)
treef1c8fb645d32aa6dca530cccef0350d6811b049d /lib/gitlab/sentry.rb
parent1bf2fe276ff084d3b2e0860710ec115a317dd9fc (diff)
downloadgitlab-ce-0fe4cf2b0fdbc33572f11bba1a4426ee05ed7599.tar.gz
Fix Sentry not reporting right program for Sidekiq workersfix-sidekiq-sentry-context
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
Diffstat (limited to 'lib/gitlab/sentry.rb')
-rw-r--r--lib/gitlab/sentry.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/gitlab/sentry.rb b/lib/gitlab/sentry.rb
new file mode 100644
index 00000000000..117fc508135
--- /dev/null
+++ b/lib/gitlab/sentry.rb
@@ -0,0 +1,27 @@
+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