github.com/newrelic/go-agent@v3.26.0+incompatible/_integrations/nrlambda/example/main.go (about) 1 // Copyright 2020 New Relic Corporation. All rights reserved. 2 // SPDX-License-Identifier: Apache-2.0 3 4 package main 5 6 import ( 7 "context" 8 "fmt" 9 10 newrelic "github.com/newrelic/go-agent" 11 "github.com/newrelic/go-agent/_integrations/nrlambda" 12 ) 13 14 func handler(ctx context.Context) { 15 // The nrlambda handler instrumentation will add the transaction to the 16 // context. Access it using newrelic.FromContext to add additional 17 // instrumentation. 18 if txn := newrelic.FromContext(ctx); nil != txn { 19 txn.AddAttribute("userLevel", "gold") 20 txn.Application().RecordCustomEvent("MyEvent", map[string]interface{}{ 21 "zip": "zap", 22 }) 23 } 24 fmt.Println("hello world") 25 } 26 27 func main() { 28 // nrlambda.NewConfig should be used in place of newrelic.NewConfig 29 // since it sets Lambda specific configuration settings including 30 // Config.ServerlessMode.Enabled. 31 cfg := nrlambda.NewConfig() 32 // Here is the opportunity to change configuration settings before the 33 // application is created. 34 app, err := newrelic.NewApplication(cfg) 35 if nil != err { 36 fmt.Println("error creating app (invalid config):", err) 37 } 38 // nrlambda.Start should be used in place of lambda.Start. 39 // nrlambda.StartHandler should be used in place of lambda.StartHandler. 40 nrlambda.Start(handler, app) 41 }