github.com/newrelic/go-agent@v3.26.0+incompatible/_integrations/nrlambda/config.go (about) 1 // Copyright 2020 New Relic Corporation. All rights reserved. 2 // SPDX-License-Identifier: Apache-2.0 3 4 package nrlambda 5 6 import ( 7 "os" 8 "time" 9 10 newrelic "github.com/newrelic/go-agent" 11 ) 12 13 // NewConfig populates a newrelic.Config with correct default settings for a 14 // Lambda serverless environment. NewConfig will populate fields based on 15 // environment variables common to all New Relic agents that support Lambda. 16 // Environment variables NEW_RELIC_ACCOUNT_ID, NEW_RELIC_TRUSTED_ACCOUNT_KEY, 17 // and NEW_RELIC_PRIMARY_APPLICATION_ID configure fields required for 18 // distributed tracing. Environment variable NEW_RELIC_APDEX_T may be used to 19 // set a custom apdex threshold. 20 func NewConfig() newrelic.Config { 21 return newConfigInternal(os.Getenv) 22 } 23 24 func newConfigInternal(getenv func(string) string) newrelic.Config { 25 cfg := newrelic.NewConfig("", "") 26 27 cfg.ServerlessMode.Enabled = true 28 29 cfg.ServerlessMode.AccountID = getenv("NEW_RELIC_ACCOUNT_ID") 30 cfg.ServerlessMode.TrustedAccountKey = getenv("NEW_RELIC_TRUSTED_ACCOUNT_KEY") 31 cfg.ServerlessMode.PrimaryAppID = getenv("NEW_RELIC_PRIMARY_APPLICATION_ID") 32 33 cfg.DistributedTracer.Enabled = true 34 35 if s := getenv("NEW_RELIC_APDEX_T"); "" != s { 36 if apdex, err := time.ParseDuration(s + "s"); nil == err { 37 cfg.ServerlessMode.ApdexThreshold = apdex 38 } 39 } 40 41 return cfg 42 }