Help, How to monitor golang based cron job using newrelic?

My cron job purpose is start periodicially, get some information from an endpoint and insert into db. I wanted to add new relic monitoring to this cronjob.

I followed all the steps:

  1. Installed the New Relic Go agent
    go get github.com/newrelic/go-agent

  2. Created a Config and an Application

app, err := newrelic.NewApplication(
newrelic.ConfigAppName("my application name"),
newrelic.ConfigLicense("plugged in my license key"),
)
  1. Added Transactions to code some thing like:
txn := app.StartTransaction("myTxn", nil, nil)

code........

defer txn.End()
  1. I also added custom insights some thing like:
 app.RecordCustomEvent("my_event_type", map[string]interface{}{
        "myString": "hello",
        "myFloat":   0.603,
        "myInt":     123,
        "myBool":    true,
    })

I dont see any data on the new relic UI.

Like to know what i am doing wrong here?
My app runs only for less than a minute and exits the process.

Hi @sethu.kollu -

I do think the issue is the fact that your application is short-lived.

Take a look at this example: https://github.com/newrelic/go-agent/blob/master/examples/short-lived-process/main.go.

Take note especially of the WaitForConnection and app.Shutdown(10 * time.Second) calls which sandwich the rest of the code.

I think following that example should get things working.

I hope that helps!

t.