debian-mirror-gitlab/workhorse/raven.go

41 lines
866 B
Go
Raw Normal View History

2021-04-17 20:07:23 +05:30
package main
import (
"net/http"
"os"
raven "github.com/getsentry/raven-go"
2023-03-04 22:38:38 +05:30
"gitlab.com/gitlab-org/gitlab/workhorse/internal/helper/exception"
2021-04-17 20:07:23 +05:30
)
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 {
2023-03-04 22:38:38 +05:30
exception.CleanHeaders(r)
2021-04-17 20:07:23 +05:30
panic(p)
}
}()
h.ServeHTTP(w, r)
}))
}