From a341fd2a69392a38a004225d1f106b91499a6e0e Mon Sep 17 00:00:00 2001
From: Roger Meier <r.meier@siemens.com>
Date: Thu, 2 May 2019 22:44:46 +0200
Subject: [PATCH] feat: add option to set Sentry environment

---
 README.md | 9 ++++++++-
 raven.go  | 5 +++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 31ee06bb19587..a841770f18571 100644
--- a/README.md
+++ b/README.md
@@ -194,17 +194,24 @@ images. If you installed GitLab:
 GitLab-Workhorse supports remote error tracking with
 [Sentry](https://sentry.io). To enable this feature set the
 GITLAB_WORKHORSE_SENTRY_DSN environment variable.
+You can also set the GITLAB_WORKHORSE_SENTRY_ENVIRONMENT environment variable to
+use the Sentry environment functionality to separate staging, production and
+development.
 
 Omnibus (`/etc/gitlab/gitlab.rb`):
 
 ```
-gitlab_workhorse['env'] = {'GITLAB_WORKHORSE_SENTRY_DSN' => 'https://foobar'}
+gitlab_workhorse['env'] = {
+    'GITLAB_WORKHORSE_SENTRY_DSN' => 'https://foobar'
+    'GITLAB_WORKHORSE_SENTRY_ENVIRONMENT' => 'production'
+}
 ```
 
 Source installations (`/etc/default/gitlab`):
 
 ```
 export GITLAB_WORKHORSE_SENTRY_DSN='https://foobar'
+export GITLAB_WORKHORSE_SENTRY_ENVIRONMENT='production'
 ```
 
 ## Tests
diff --git a/raven.go b/raven.go
index c92fdb4cfefc2..f641203f142b6 100644
--- a/raven.go
+++ b/raven.go
@@ -13,8 +13,13 @@ func wrapRaven(h http.Handler) http.Handler {
 	// Use a custom environment variable (not SENTRY_DSN) to prevent
 	// clashes with gitlab-rails.
 	sentryDSN := os.Getenv("GITLAB_WORKHORSE_SENTRY_DSN")
+	sentryEnvironment := os.Getenv("GITLAB_WORKHORSE_SENTRY_ENVIRONMENT")
 	raven.SetDSN(sentryDSN) // sentryDSN may be empty
 
+	if sentryEnvironment != "" {
+		raven.SetEnvironment(sentryEnvironment)
+	}
+
 	if sentryDSN == "" {
 		return h
 	}
-- 
GitLab