Open legendecas opened 2 years ago
OTLP streams will keep the type. Other streams have freedom to define their behavior. OTLP (preserves types) to Prometheus (string only) will have lossy conversion.
@jsuereth has an old PR on the Prometheus data model. Supporting boolean, number and non-empty string should be easy; null, empty string are tricky - should we prevent these from the API?
@reyang in the PrometheusExporter prototype for .NET - null will be converted to "(null)" for systems that only supports text. Empty string label (in PrometheusExporter) will be dropped (to be consistent with Prometheus).
@dyladan JavaScript has undefined
, null
and unset which make things harder. Unset if not a problem because it can be treated as the attribute key-value pair does not exist. null
in JavaScript means the user explicitly gives the value that is intentionally set as null
, undefined
by convention means it's not intentional.
For JavaScript, update the document to clarify that null
and undefined
have undefined behavior in the API, it's up to each exporter how to handle it.
The Prometheus related specs are still work-in-progress, but it is very likely that the following conversion would happen:
Not every language stringifies true
and false
with "true"
and "false"
. It is "True"
and "False"
in python. Should the serialized value to be language specific?
@legendecas for now, i'd stick with what the collector does here for Prometheus. It's likely we'll specify what the collector does as the common denominator between implementations. If this causes issues we can prioritize specification here.
What are you trying to achieve?
As the state,
Attribute
values can be primitive values like string, boolean, double and int64 (https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/common.md#attribute). SDKs treatAttribute
as part of the metric stream identity (https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#opentelemetry-protocol-data-model). So this seems that an attribute with value"0"
,false
,0.0
, and0
(and possiblynull
for reasons below) should be identified as different identities, i.e. there should be 4 (or 5) unique metric streams in memory for each of these values respectively.However, there are two problems with this behavior:
null
value on export can coarse thenull
to0
,false
, or empty strings""
. (stated in https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/common.md#attribute)0
and"0"
are exported as"0"
.So on exporting, several unique metric streams in SDK can be exported as indistinguishable two streams. I'm not sure if this is designed as is, but it seems at first look not suitable in cases.
Possible solutions