Metrics API: Custom metrics not visible

I am trying to send custom metrics from my NextJs application like this.

    const url = `https://metric-api.newrelic.com/metric/v1`
    fetch(url, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Api-Key': process.env.NEXT_PUBLIC_NEWRELIC_KEY,
      },
      body: JSON.stringify([
        {
          metrics: [
            {
              name: 'fe_nextjs_portfolio_ttfb',
              type: 'gauge',
              value: 100,
              timestamp: dayjs().utc().valueOf(), // unix timestamp in milliseconds
              attributes: { 'next.env': 'dev' },
            },
          ],
        },
      ]),
    })

I get a 202 response with the request-id.
However, I am not able to see the metrics on the dashboard. Also there are no NrIntegrationError events.

Hi, @arpit2: There are NrIntegrationError events:

Hi @philweber ,

These errors are couple of days older than from when I posted this issue.
Also, after sending an event, how long does it take for newrelic to process the custom event and report an error ? The error timestamps I see on the dashboard are 2 days late. It’s quite difficult to debug like this, and if the events are getting processed after 2 days, then the error message in the screen shot you shared is expected.

I have other piplelines setup for metrics - one is the ‘newrelic infra agent’ and other is by converting logs to metrics. Those seem to be working fine, I am facing the issue only in custom events.

Parsing errors should be reported almost immediately (within a few seconds). This curl command works for me:

curl -k -H "Content-Type: application/json" \
-H "Api-Key: NEW_RELIC_LICENSE_KEY" \
-X POST https://metric-api.newrelic.com/metric/v1 \
--data '[{
  "metrics": [{
    "name": "fe_nextjs_portfolio_ttfb",
    "type": "gauge",
    "value": 100,
    "timestamp": 1664231078000,
    "attributes": { "next.env": "dev" }
  }]
}]'

I notice that your code has commas after curly braces and square brackets, and mine does not. Also, you have a comma after the attributes element and I don’t.

JSON. stringify() fixes the formatting. I don’t think that’s the issue here.

Also, I tried with the example data given in the documentation with curl. Those are also not visible.

curl -k -H "Content-Type: application/json" -H "Api-Key: KEY" -X POST https://metric-api.newrelic.com/metric/v1 --data '[
  {
    "metrics": [
      {
        "name": "cache.misses",
        "type": "count",
        "value": 15,
        "timestamp": 1664261589026,
        "interval.ms": 10000,
        "attributes": {
          "cache.name": "myCache",
          "host.name": "dev.server.com"
        }
      },
      { 
        "name": "temperature", 
        "type": "gauge", 
        "value": 15, 
        "timestamp": 1664261589026, 
        "attributes": { 
          "city": "Portland", 
          "state": "Oregon" 
        } 
      },
      {
        "name": "service.response.duration",
        "type": "summary",
        "value": {
          "count": 5, 
          "sum": 0.004382655, 
          "min": 0.0005093, 
          "max": 0.001708826
        },
        "interval.ms": 10000, 
        "timestamp": 1664261589026,
        "attributes": {
          "host.name": "dev.server.com",
          "app.name": "foo"
        }
      }
    ]
  }
]'
{"requestId":"97d35de2-0001-b3e5-a4b7-01837dbc8909"}

The only other suggestion I have is to make sure you are using an INGEST - LICENSE key for the API key. If that is not the problem, you will need a support engineer to help troubleshoot; someone will reply here as soon as possible.