Skip to content

Commit

Permalink
update NEW_RELIC_ENABLED to Env bool (#234)
Browse files Browse the repository at this point in the history
* add ParseBool for env var
  • Loading branch information
chaudharysaket authored Sep 16, 2024
1 parent 2081151 commit ac7ad99
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit ac7ad99

Please sign in to comment.