# Sending no data point in registerMetric callback

**URL:** <https://discuss.elastic.co/t/sending-no-data-point-in-registermetric-callback/291175>\
**Category:** APM\
**Tags:** nodejs\
**Created:** [December 8, 2021, 3:18am UTC](https://discuss.elastic.co/t/sending-no-data-point-in-registermetric-callback/291175 "2021-12-08T03:18:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![apoco](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/apoco/32/98529_2.png) [@apoco](https://discuss.elastic.co/u/apoco)\
**Post date:** [December 8, 2021, 3:18am UTC](https://discuss.elastic.co/t/sending-no-data-point-in-registermetric-callback/291175/1 "2021-12-08T03:18:41Z")

</div>

I'm migrating an app from New Relic, and I'm trying to use registerMetric to give me a custom metric. The metric I'm recording is a duration average, so I'm collecting durations and a count of durations so that when the callback passed to registerMetric is called I can send the average as a response and reset the accumulators. Seems straightforward, but what should I return to indicate that there is no data available for a sampling window (when my divisor is 0). I tried returning null, but then the validation logic for registerMetric said that the function must return a number.

Is there a way to signal "no data" for a custom metric, or am I doomed to have ugly data like 0's?

---

<div class="post-metadata">

**Author:** ![trentm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/trentm/32/77647_2.png) [@trentm](https://discuss.elastic.co/u/trentm)\
**Post date:** [December 8, 2021, 8:29pm UTC](https://discuss.elastic.co/t/sending-no-data-point-in-registermetric-callback/291175/2 "2021-12-08T20:29:21Z")

</div>

@apoco Thanks for the question. Unfortunately, no, the Node.js APM agent's `registerMetric` handling doesn't provide a way to say "there is no value for this period" for a metric. Returning `null` or `undefined` from the registered callback results in the agent still sending an empty value for that metric, which gets translated to the zero numeric (because `registerMetric` supports only Gauge metric types) value, i.e. `0`.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 29, 2021, 4:29pm UTC](https://discuss.elastic.co/t/sending-no-data-point-in-registermetric-callback/291175/3 "2021-12-29T16:29:36Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
