diff --git a/pkg/config/config.go b/pkg/config/config.go index 22401cdf..119b1a1a 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -69,6 +69,9 @@ func setupSentry() { logrus.FatalLevel, logrus.ErrorLevel, }) + if Config.SentryEnvironment != "" { + hook.SetEnvironment(Config.SentryEnvironment) + } if err != nil { logrus.WithField("err", err).Error("failed to hook logurs to sentry") return diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 0df269f4..9a3732db 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -9,48 +9,57 @@ import ( func TestSetupSentry(t *testing.T) { Config.SentryEnabled = true - assert.NotPanics(t, func() { - setupSentry() - }) - Config.SentryEnabled = false + Config.SentryEnvironment = "test" + defer func() { + Config.SentryEnabled = false + Config.SentryEnvironment = "" + }() + + assert.NotPanics(t, func() { setupSentry() }) } func TestSetupNewRelic(t *testing.T) { Config.NewRelicEnabled = true - assert.Panics(t, func() { - setupNewrelic() - }) - Config.NewRelicEnabled = false + defer func() { + Config.NewRelicEnabled = false + }() + + assert.Panics(t, func() { setupNewrelic() }) } func TestSetupStatsd(t *testing.T) { Config.StatsdEnabled = true - assert.NotPanics(t, func() { - setupStatsd() - }) - Config.StatsdEnabled = false + defer func() { + Config.StatsdEnabled = false + }() + + assert.NotPanics(t, func() { setupStatsd() }) } func TestSetupPrometheus(t *testing.T) { prometheus.DefaultRegisterer = prometheus.NewRegistry() - Config.PrometheusEnabled = false setupPrometheus() assert.Nil(t, Global.Prometheus.EvalCounter) + Config.PrometheusEnabled = true + defer func() { Config.PrometheusEnabled = false }() setupPrometheus() assert.NotNil(t, Global.Prometheus.EvalCounter) assert.NotNil(t, Global.Prometheus.RequestCounter) assert.Nil(t, Global.Prometheus.RequestHistogram) - Config.PrometheusEnabled = false } func TestSetupPrometheusWithLatencies(t *testing.T) { prometheus.DefaultRegisterer = prometheus.NewRegistry() Config.PrometheusEnabled = true Config.PrometheusIncludeLatencyHistogram = true + defer func() { + Config.PrometheusEnabled = false + Config.PrometheusIncludeLatencyHistogram = false + }() + setupPrometheus() assert.NotNil(t, Global.Prometheus.EvalCounter) assert.NotNil(t, Global.Prometheus.RequestCounter) assert.NotNil(t, Global.Prometheus.RequestHistogram) - Config.PrometheusEnabled = false } diff --git a/pkg/config/env.go b/pkg/config/env.go index 58396e72..e0a5454f 100644 --- a/pkg/config/env.go +++ b/pkg/config/env.go @@ -72,8 +72,9 @@ var Config = struct { CORSEnabled bool `env:"FLAGR_CORS_ENABLED" envDefault:"true"` // SentryEnabled - enable Sentry and Sentry DSN - SentryEnabled bool `env:"FLAGR_SENTRY_ENABLED" envDefault:"false"` - SentryDSN string `env:"FLAGR_SENTRY_DSN" envDefault:""` + SentryEnabled bool `env:"FLAGR_SENTRY_ENABLED" envDefault:"false"` + SentryDSN string `env:"FLAGR_SENTRY_DSN" envDefault:""` + SentryEnvironment string `env:"FLAGR_SENTRY_ENVIRONMENT" envDefault:""` // NewRelicEnabled - enable the NewRelic monitoring for all the endpoints and DB operations NewRelicEnabled bool `env:"FLAGR_NEWRELIC_ENABLED" envDefault:"false"`