diff --git a/cmd/poseidon/main.go b/cmd/poseidon/main.go index a2c54ab..7208356 100644 --- a/cmd/poseidon/main.go +++ b/cmd/poseidon/main.go @@ -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) diff --git a/configuration.example.yaml b/configuration.example.yaml index 5b24f2a..a3ac2b5 100644 --- a/configuration.example.yaml +++ b/configuration.example.yaml @@ -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.