2024-11-25 12:13:47 +00:00
|
|
|
package sentry
|
|
|
|
|
|
|
|
import (
|
|
|
|
_ "embed"
|
|
|
|
"os"
|
2024-12-02 16:32:26 +00:00
|
|
|
"strings"
|
2024-11-25 12:13:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
//go:generate sh -c "echo $SENTRY_CONTEXT_NAME > SENTRY_CONTEXT_NAME"
|
|
|
|
//go:generate sh -c "echo $SENTRY_CONTEXT_VERSION > SENTRY_CONTEXT_VERSION"
|
|
|
|
//go:generate sh -c "echo $SENTRY_PRODUCTION > SENTRY_PRODUCTION"
|
|
|
|
|
|
|
|
const productionEnvironment = "production"
|
|
|
|
|
|
|
|
var (
|
|
|
|
//go:embed SENTRY_CONTEXT_NAME
|
|
|
|
defaultContextName string
|
|
|
|
|
|
|
|
//go:embed SENTRY_CONTEXT_VERSION
|
|
|
|
defaultContextVersion string
|
|
|
|
|
|
|
|
//go:embed SENTRY_PRODUCTION
|
|
|
|
production string
|
|
|
|
)
|
|
|
|
|
2024-12-02 16:32:26 +00:00
|
|
|
func init() {
|
|
|
|
production = strings.TrimSpace(production)
|
|
|
|
}
|
|
|
|
|
2024-11-25 12:13:47 +00:00
|
|
|
func DefaultContext() string {
|
|
|
|
return defaultContextName
|
|
|
|
}
|
|
|
|
|
|
|
|
func DefaultContextVersion() string {
|
|
|
|
return defaultContextVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
func Production() bool {
|
|
|
|
return production == "true" || production == "1"
|
|
|
|
}
|
|
|
|
|
|
|
|
func Environment() string {
|
|
|
|
return environment(Production(), DefaultEnvVarEnvironment)
|
|
|
|
}
|
|
|
|
|
2024-12-02 16:32:26 +00:00
|
|
|
func environment(forceProduction bool, envvar string) string {
|
|
|
|
if forceProduction {
|
2024-11-25 12:13:47 +00:00
|
|
|
return productionEnvironment
|
|
|
|
}
|
|
|
|
env := os.Getenv(envvar)
|
|
|
|
if env == productionEnvironment {
|
|
|
|
// Production environment can only be set during build
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return env
|
|
|
|
}
|