Golang events not tracking

I’m fairly new to Golang, and having some trouble getting custom events to load (the application does show up in APM), I’ve simplified the application as far as possible:

Any thoughts on where I’m going wrong? Any suggestions would be gratefully received!

Hello @bc21d5b19c5be5f71a43,

After reviewing your codebase, you might want to use the New Relic Lambda integration for Go , instead of the agent.

All you need is to follow the template below:

You can use the example template and refactor your codebase. Because you need to be writing the handler this way as documented:

func handler(ctx context.Context) {
	// The nrlambda handler instrumentation will add the transaction to the
	// context.  Access it using newrelic.FromContext to add additional
	// instrumentation.
	if txn := newrelic.FromContext(ctx); nil != txn {
		txn.AddAttribute("userLevel", "gold")
		txn.Application().RecordCustomEvent("MyEvent", map[string]interface{}{
			"zip": "zap",
		})
	}
	fmt.Println("hello world")
}

and then add the imports:

newrelic "github.com/newrelic/go-agent"
	"github.com/newrelic/go-agent/_integrations/nrlambda"

Lastly, your lambda should start as:

nrlambda.Start(handler, app)

within the func main() { }

Kindly go over the steps and let us know if you run into any other issues.

Best!

Thank you for your suggestion @bidahor,
I’ve updated my Gist:

The diff is here:

I notice that you’re not using the v3 integration in your suggestion, is there a compelling reason not to use it? I’d prefer to use the most current implementation if possible, but if there are good reasons not to I’m open to downgrading.

Hi @bc21d5b19c5be5f71a43,

When working in a Lambda environment you shouldn’t create you app/config using Newrelic.NewApplication like you have on your handler function.

Initializing app, err := newrelic.NewApplication(nrlambda.ConfigOption()) in your main function is enough providing that you have folowed the steps to link your AWS account to NewRelic:
https://docs.newrelic.com/docs/serverless-function-monitoring/aws-lambda-monitoring/get-started/enable-new-relic-monitoring-aws-lambda#connect-aws

All these lines in your code are safe to be removed and you will then need to wrap the RecordCustomEvent call within a transaction (txt) as per our example here:

Hope this helps,