From ac7ad9926bb7730517cee05c59068b845d7d647d Mon Sep 17 00:00:00 2001 From: Saket Chaudhary <118331906+chaudharysaket@users.noreply.github.com> Date: Mon, 16 Sep 2024 23:12:10 +0530 Subject: [PATCH] update NEW_RELIC_ENABLED to Env bool (#234) * add ParseBool for env var --- config/config.go | 7 +++++-- config/config_test.go | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index 84126cf..b02eec0 100644 --- a/config/config.go +++ b/config/config.go @@ -57,8 +57,11 @@ func ConfigurationFromEnvironment() *Configuration { collectTraceIDStr, collectTraceIDOverride := os.LookupEnv("NEW_RELIC_COLLECT_TRACE_ID") extensionEnabled := true - if nrEnabledOverride && strings.ToLower(nrEnabledStr) == "false" { - extensionEnabled = false + if nrEnabledOverride { + b, err := strconv.ParseBool(nrEnabledStr) + if err == nil && !b { + extensionEnabled = false + } } if nrEnabledRubyOverride && strings.ToLower(nrEnabledRubyStr) == "false" { extensionEnabled = false diff --git a/config/config_test.go b/config/config_test.go index 63f6f51..5b8ea33 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -83,6 +83,14 @@ func TestConfigurationFromEnvironmentNREnabled(t *testing.T) { assert.Equal(t, conf.ExtensionEnabled, false) } +func TestConfigurationFromEnvironmentNREnabledBool(t *testing.T) { + os.Setenv("NEW_RELIC_ENABLED", "0") + defer os.Unsetenv("NEW_RELIC_ENABLED") + + conf := ConfigurationFromEnvironment() + assert.Equal(t, conf.ExtensionEnabled, false) +} + func TestConfigurationFromEnvironmentNRAgentEnabled(t *testing.T) { os.Setenv("NEW_RELIC_AGENT_ENABLED", "false") defer os.Unsetenv("NEW_RELIC_AGENT_ENABLED")