Skip to content

Commit

Permalink
NEW_RELIC_ENABLED Env issue (#233)
Browse files Browse the repository at this point in the history
* disable extension if env vars are false
  • Loading branch information
chaudharysaket authored Sep 11, 2024
1 parent 5e1d0d1 commit 2081151
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type Configuration struct {
}

func ConfigurationFromEnvironment() *Configuration {
nrEnabledStr, nrEnabledOverride := os.LookupEnv("NEW_RELIC_ENABLED")
nrEnabledRubyStr, nrEnabledRubyOverride := os.LookupEnv("NEW_RELIC_AGENT_ENABLED")
enabledStr, extensionEnabledOverride := os.LookupEnv("NEW_RELIC_LAMBDA_EXTENSION_ENABLED")
licenseKey, lkOverride := os.LookupEnv("NEW_RELIC_LICENSE_KEY")
licenseKeySecretId, lkSecretOverride := os.LookupEnv("NEW_RELIC_LICENSE_KEY_SECRET")
Expand All @@ -55,6 +57,12 @@ func ConfigurationFromEnvironment() *Configuration {
collectTraceIDStr, collectTraceIDOverride := os.LookupEnv("NEW_RELIC_COLLECT_TRACE_ID")

extensionEnabled := true
if nrEnabledOverride && strings.ToLower(nrEnabledStr) == "false" {
extensionEnabled = false
}
if nrEnabledRubyOverride && strings.ToLower(nrEnabledRubyStr) == "false" {
extensionEnabled = false
}
if extensionEnabledOverride && strings.ToLower(enabledStr) == "false" {
extensionEnabled = false
}
Expand Down
16 changes: 16 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ func TestConfigurationFromEnvironment(t *testing.T) {
assert.Equal(t, false, conf.LogsEnabled)
}

func TestConfigurationFromEnvironmentNREnabled(t *testing.T) {
os.Setenv("NEW_RELIC_ENABLED", "false")
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")

conf := ConfigurationFromEnvironment()
assert.Equal(t, conf.ExtensionEnabled, false)
}

func TestConfigurationFromEnvironmentSecretId(t *testing.T) {
os.Setenv("NEW_RELIC_LICENSE_KEY_SECRET", "secretId")
defer os.Unsetenv("NEW_RELIC_LICENSE_KEY_SECRET")
Expand Down

0 comments on commit 2081151

Please sign in to comment.