-
Notifications
You must be signed in to change notification settings - Fork 928
Description
Looking across language implementation the unit field for the metric instrument definition
is implemented differently.
In some cases it is implemented as a definite type, restricting it to well defined values:
But, in most cases it is an unconstrained string:
- https://github.com/open-telemetry/opentelemetry-python/blob/master/opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py#L151
- https://github.com/open-telemetry/opentelemetry-java/blob/master/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractInstrument.java#L102
- https://github.com/open-telemetry/opentelemetry-js/blob/master/packages/opentelemetry-metrics/src/export/types.ts#L83
I wasn't able to find a part of the specification that specifies a unit. Given the metric SDK is still a work in progress, I'm guessing that it would eventually at least be referenced there.
However, the proto does give some specification on what values a unit can have: https://github.com/open-telemetry/opentelemetry-proto/blob/b54688569186e0b862bf7462a983ccf2c50c0547/opentelemetry/proto/metrics/v1/metrics.proto#L117-L119
This uses the Unified Code For Units of Measure.
Questions
- Should implementation of units be standardized similar to semantic conventions and be supported as canonical strings? Or, should they be specified as distinct types? Could they be specified so that either implementation would suffice, meaning that languages that support a strong type system could used a dedicated type, and weaker typing systems could have a more flexible implementation?
- Should we stick with this UCUM standards body like in the proto to specify the unit structure we expect? What about IEEE, or SI? Should we specify our own and have a subset of these standards?
- Should the prefix be decoupled from the unit? If the unit is to be it's own type, should the prefix just be a dedicated field?
- How should the extensibility of the unit system be handled? Does it need to be specified?
- Should things like
count
,total
, orsum
be included in the unit specification?
Additional context.
This is all motivated by a need for interoperability between instrumentation and exporters. An exporter needs to know how instrumentation will define its units so it can identify, display, and possibly convert values correctly.
For example, if instrumentation sends time data and the exporter wants all time data in milliseconds. If the unit of time is unspecified and instrumentation sends data as microseconds
, micro-sec
, us
, and μs
the will have an insurmountable problem to solve doing this interpretation and conversion.
Additionally, if instrumentation records in one unit (say mmhg) but the exporter exports in another (i.e. kPa) the end user will not have their data interpreted appropriately.