Add automatic detection for release version
This commit is contained in:

committed by
Sebastian Serth

parent
f79aa924f3
commit
efa746c940
@ -15,6 +15,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"runtime/debug"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"strconv"
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -29,7 +30,38 @@ var (
|
|||||||
pgoEnabled = "false"
|
pgoEnabled = "false"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func getVcsRevision() string {
|
||||||
|
vcsRevision := "unknown"
|
||||||
|
vcsModified := false
|
||||||
|
|
||||||
|
if info, ok := debug.ReadBuildInfo(); ok {
|
||||||
|
for _, setting := range info.Settings {
|
||||||
|
if setting.Key == "vcs.revision" {
|
||||||
|
vcsRevision = setting.Value
|
||||||
|
} else if setting.Key == "vcs.modified" {
|
||||||
|
var err error
|
||||||
|
vcsModified, err = strconv.ParseBool(setting.Value)
|
||||||
|
if err != nil {
|
||||||
|
vcsModified = true // fallback to true, so we can see that something is wrong
|
||||||
|
log.WithError(err).Error("Could not parse the vcs.modified setting")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if vcsModified {
|
||||||
|
return vcsRevision + "-modified"
|
||||||
|
} else {
|
||||||
|
return vcsRevision
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func initSentry(options *sentry.ClientOptions, profilingEnabled bool) {
|
func initSentry(options *sentry.ClientOptions, profilingEnabled bool) {
|
||||||
|
if options.Release == "" {
|
||||||
|
commit := getVcsRevision()
|
||||||
|
options.Release = commit
|
||||||
|
}
|
||||||
|
|
||||||
options.BeforeSendTransaction = func(event *sentry.Event, _ *sentry.EventHint) *sentry.Event {
|
options.BeforeSendTransaction = func(event *sentry.Event, _ *sentry.EventHint) *sentry.Event {
|
||||||
if event.Tags == nil {
|
if event.Tags == nil {
|
||||||
event.Tags = make(map[string]string)
|
event.Tags = make(map[string]string)
|
||||||
|
@ -76,9 +76,9 @@ sentry:
|
|||||||
# dsn: https://example.io
|
# dsn: https://example.io
|
||||||
# The environment to be sent with events.
|
# The environment to be sent with events.
|
||||||
# environment: staging
|
# environment: staging
|
||||||
# This release information is used by Poseidon to provide the version route.
|
# This release information is used by Poseidon to provide the version route and tag events in Sentry.
|
||||||
# Normally it is set by the deployment process.
|
# If no specific value is set, the git commit hash used to build the binary is used.
|
||||||
# release: this is replaced in the deployment process
|
# release: development
|
||||||
# In debug mode, the debug information is printed to stdout to help you understand what sentry is doing.
|
# In debug mode, the debug information is printed to stdout to help you understand what sentry is doing.
|
||||||
# debug: true
|
# debug: true
|
||||||
# Enable performance tracing.
|
# Enable performance tracing.
|
||||||
|
Reference in New Issue
Block a user