Skip to content

Commit

Permalink
Disable Lambda Extension By Default (#20)
Browse files Browse the repository at this point in the history
This changes the behavior of the Lambda Extension. Instead of being
enabled by default, it will instead be disabled by default and need to
be enabled via a `NEW_RELIC_LAMBDA_EXTENSION_ENABLED` enviornment
variable.
  • Loading branch information
kolanos authored Sep 29, 2020
1 parent 6d3e540 commit da16114
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 13 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ to install the managed secret, and then add the permission for the secret to you

Each of the example functions in the `examples` directory has the appropriate license key secret permission.

The New Relic Lambda Extension is disabled by default. To enable it, after adding or
updating the Lambda layer, set the `NEW_RELIC_LAMBDA_EXTENSION_ENABLED` environment
variable to any value.

After deploying your AWS Lambda function with one of the layer ARNs from the
link above you should begin seeing telemetry data in New Relic.

Expand Down
12 changes: 6 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ package config
import "os"

type Configuration struct {
UseCloudWatchIngest bool
LicenseKey *string
LicenseKeySecretId *string
TelemetryEndpoint *string
ExtensionEnabled bool
LicenseKey *string
LicenseKeySecretId *string
TelemetryEndpoint *string
}

func ConfigurationFromEnvironment() Configuration {
_, useCW := os.LookupEnv("NEW_RELIC_CLOUDWATCH_INGEST")
_, extensionEnabled := os.LookupEnv("NEW_RELIC_LAMBDA_EXTENSION_ENABLED")
licenseKey, lkOverride := os.LookupEnv("NEW_RELIC_LICENSE_KEY")
licenseKeySecretId, lkSecretOverride := os.LookupEnv("NEW_RELIC_LICENSE_KEY_SECRET")
telemetryEndpoint, teOverride := os.LookupEnv("NEW_RELIC_TELEMETRY_ENDPOINT")

ret := Configuration{UseCloudWatchIngest: useCW}
ret := Configuration{ExtensionEnabled: extensionEnabled}

if lkOverride {
ret.LicenseKey = &licenseKey
Expand Down
17 changes: 12 additions & 5 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,27 @@ func TestConfigurationFromEnvironmentZero(t *testing.T) {
}

func TestConfigurationFromEnvironment(t *testing.T) {
os.Setenv("NEW_RELIC_CLOUDWATCH_INGEST", "set")
os.Unsetenv("NEW_RELIC_LAMBDA_EXTENSION_ENABLED")

conf := ConfigurationFromEnvironment()

assert.Equal(t, conf.ExtensionEnabled, false)

os.Setenv("NEW_RELIC_LAMBDA_EXTENSION_ENABLED", "set")
os.Setenv("NEW_RELIC_LICENSE_KEY", "lk")
os.Setenv("NEW_RELIC_LICENSE_KEY_SECRET", "secretId")
os.Setenv("NEW_RELIC_TELEMETRY_ENDPOINT", "endpoint")
defer func () {
os.Unsetenv("NEW_RELIC_CLOUDWATCH_INGEST")

defer func() {
os.Unsetenv("NEW_RELIC_LAMBDA_EXTENSION_ENABLED")
os.Unsetenv("NEW_RELIC_LICENSE_KEY")
os.Unsetenv("NEW_RELIC_LICENSE_KEY_SECRET")
os.Unsetenv("NEW_RELIC_TELEMETRY_ENDPOINT")
}()

conf := ConfigurationFromEnvironment()
conf = ConfigurationFromEnvironment()

assert.Equal(t, true, conf.UseCloudWatchIngest)
assert.Equal(t, conf.ExtensionEnabled, true)
assert.Equal(t, "lk", *conf.LicenseKey)
assert.Nil(t, conf.LicenseKeySecretId)
assert.Equal(t, "endpoint", *conf.TelemetryEndpoint)
Expand Down
1 change: 1 addition & 0 deletions examples/dotnet/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Resources:
Timeout: 6
Environment:
Variables:
NEW_RELIC_LAMBDA_EXTENSION_ENABLED: true
NEW_RELIC_ACCOUNT_ID: !Sub ${NRAccountId}
Layers:
# This layer includes the New Relic Lambda Extension, a sidecar process that sends telemetry.
Expand Down
1 change: 1 addition & 0 deletions examples/go/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Resources:
Runtime: provided
Environment:
Variables:
NEW_RELIC_LAMBDA_EXTENSION_ENABLED: true
NEW_RELIC_ACCOUNT_ID: !Sub ${NRAccountId}
NEW_RELIC_TRUSTED_ACCOUNT_KEY: !Sub ${NRAccountId}
Layers:
Expand Down
1 change: 1 addition & 0 deletions examples/java/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Resources:
MemorySize: 512
Environment:
Variables:
NEW_RELIC_LAMBDA_EXTENSION_ENABLED: true
NEW_RELIC_ACCOUNT_ID: !Sub ${NRAccountId}
Layers:
# This layer includes the New Relic Lambda Extension, a sidecar process that sends telemetry,
Expand Down
1 change: 1 addition & 0 deletions examples/node/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Resources:
Runtime: nodejs12.x
Environment:
Variables:
NEW_RELIC_LAMBDA_EXTENSION_ENABLED: true
# For the instrumentation handler to invoke your real handler, we need this value
NEW_RELIC_LAMBDA_HANDLER: app.lambdaHandler
NEW_RELIC_ACCOUNT_ID: !Sub ${NRAccountId}
Expand Down
1 change: 1 addition & 0 deletions examples/python/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Resources:
Runtime: python3.8
Environment:
Variables:
NEW_RELIC_LAMBDA_EXTENSION_ENABLED: true
# For the instrumentation handler to invoke your real handler, we need this value
NEW_RELIC_LAMBDA_HANDLER: app.lambda_handler
NEW_RELIC_ACCOUNT_ID: !Sub ${NRAccountId}
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ func main() {

registrationClient := client.New(http.Client{})
regReq := api.RegistrationRequest{
Events: []api.LifecycleEvent{api.Invoke, api.Shutdown},
Events: []api.LifecycleEvent{api.Invoke, api.Shutdown},
}

invocationClient, registrationResponse, err := registrationClient.Register(regReq)
if err != nil {
log.Fatal(err)
}

conf := config.ConfigurationFromEnvironment()

if conf.UseCloudWatchIngest {
if conf.ExtensionEnabled == false {
log.Println("Extension telemetry processing disabled")
noopLoop(invocationClient)
return
Expand Down

0 comments on commit da16114

Please sign in to comment.