Add automatic detection for release version

This commit is contained in:
Sebastian Serth
2023-02-28 10:53:41 +01:00
committed by Sebastian Serth
parent f79aa924f3
commit efa746c940
2 changed files with 35 additions and 3 deletions

View File

@ -15,6 +15,7 @@ import (
"net/http"
"os"
"os/signal"
"runtime/debug"
"runtime/pprof"
"strconv"
"syscall"
@ -29,7 +30,38 @@ var (
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) {
if options.Release == "" {
commit := getVcsRevision()
options.Release = commit
}
options.BeforeSendTransaction = func(event *sentry.Event, _ *sentry.EventHint) *sentry.Event {
if event.Tags == nil {
event.Tags = make(map[string]string)

View File

@ -76,9 +76,9 @@ sentry:
# dsn: https://example.io
# The environment to be sent with events.
# environment: staging
# This release information is used by Poseidon to provide the version route.
# Normally it is set by the deployment process.
# release: this is replaced in the deployment process
# This release information is used by Poseidon to provide the version route and tag events in Sentry.
# If no specific value is set, the git commit hash used to build the binary is used.
# release: development
# In debug mode, the debug information is printed to stdout to help you understand what sentry is doing.
# debug: true
# Enable performance tracing.