summaryrefslogtreecommitdiff
path: root/workhorse/raven.go
blob: 582900b15f480dd9484981584650c180f1b22ea7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main

import (
	"net/http"
	"os"

	raven "github.com/getsentry/raven-go"

	"gitlab.com/gitlab-org/gitlab/workhorse/internal/helper/exception"
)

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
	}

	raven.DefaultClient.SetRelease(Version)

	return http.HandlerFunc(raven.RecoveryHandler(
		func(w http.ResponseWriter, r *http.Request) {
			defer func() {
				if p := recover(); p != nil {
					exception.CleanHeaders(r)
					panic(p)
				}
			}()

			h.ServeHTTP(w, r)
		}))
}