Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Golang events not tracking

golang
go-agent
go
follow-up
mod_queue
sla_breaching

#1

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!


#2

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!


#3

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.