opentelemetry-js icon indicating copy to clipboard operation
opentelemetry-js copied to clipboard

How to represent 64bit integers as attribute value?

Open jmorrell-cloudflare opened this issue 6 months ago • 1 comments
trafficstars

The OpenTelemetry spec says valid attribute types include signed 64bit integers:

A primitive type: string, boolean, double precision floating point (IEEE 754-1985) or signed 64 bit integer.

However in opentelemetry-js attribute values are represented as number which has a max safe value of 2^53 – 1.

There was a previous request for supporting BigInt as an attribute value here though it was marked as not planned. This makes some sense to me since it could represent much larger numbers, but still leaves a gap between 2^53-1 and 2^63-1 IIUC.

If we need to attach a 64 bit integer (say, received from an external system) to an attribute today that exceeds Number.MAX_SAFE_INTEGER, what is the recommended approach? Serialize it to a string? Or is there maybe some alternative I am missing?

jmorrell-cloudflare avatar May 13 '25 18:05 jmorrell-cloudflare

Your understanding of the current behavior is correct.

Similar to a comment I left on this sort of thing in #573, my position is that PrometheusBuilder is already far too overloaded, and I can't add an escape hatch for every situation. If listening on multiple addresses is something you need, then my suggestion would be to write the boilerplate to do so, and spawn your own HTTP server that simply uses PrometheusHandle to render the metrics.

tobz avatar Apr 16 '25 13:04 tobz