Logs data model canonical OTLP encoding for null any values
What are you trying to achieve?
Updating the Python OTLP exporter to support None values nested within the Logs SDK any value https://github.com/open-telemetry/opentelemetry-python/pull/4400. It is unclear how to convert null values into OTLP protobuf AnyValue messages. I may have missed it in the spec already but there are some unclear cases:
-
KeyValue with null value:
{"foo": None}. ShouldKeyValue.valuebe left unset or get an emptyAnyValue? -
ArrayValue containing null:
{"foo": [1, 2, None]}. The common spec is pretty clear that exporters should preserve the ordering:If exporters do not support exporting
nullvalues, they MAY replace those values by 0,false, or empty strings. This is required for map/dictionary structures represented as two arrays with indices that are kept in syncI think the empty
AnyValuewould be appropriate here. -
Body is null. Should
LogRecord.bodybe left unset or be set to an explicit emptyAnyValue?
For languages with undefined vs null distinction, this all gets more complicated so we should consider OTel JS too.
Additional context.
Note that 2 affects tracing and metrics as well since "null values within arrays MUST be preserved as-is (i.e., passed on to span processors / exporters as null)".
Protobuf's standard Struct message uses a separate oneof variant for NullValue.
@open-telemetry/javascript-maintainers tagging you here to get your perspective on this, as @aabmass mentioned JS above.
@aabmass, is it not a duplicate of https://github.com/open-telemetry/opentelemetry-specification/issues/3835 which has been already addressed via https://github.com/open-telemetry/opentelemetry-specification/pull/3853?
For languages with undefined vs null distinction.
Both should be encoded as empty empty AnyValue?
Should LogRecord.body be left unset or be set to an explicit empty AnyValue?
What is the difference?
Notice that "log attributes" have currently different definition from "standard attributes". There is an ongoing work to extend the "standard attributes" so that they also contain the types from Logs Data Model. See:
- https://github.com/open-telemetry/opentelemetry-specification/issues/4602
- https://github.com/open-telemetry/opentelemetry-proto/pull/707
- https://github.com/open-telemetry/opentelemetry-specification/pull/4636
Can we close this issue as a duplicate of https://github.com/open-telemetry/opentelemetry-specification/issues/3835?
I don't think so. https://github.com/open-telemetry/opentelemetry-specification/pull/3853 is for the data model. It only says that values may be null but not how to serialize them into OTLP. I'm looking for clarity on how to serialize null values into OTLP (JSON and Protobuf).
The answer for OTLP Protobuf is:
Empty values MUST be converted to AnyValue with no value field being set.
As for OTLP JSON https://github.com/open-telemetry/opentelemetry-proto/blob/main/docs/specification.md#json-protobuf-encoding it should be JSON Protobuf encoded empty AnyValue. @open-telemetry/collector-approvers, is this what otlphttpexporter is doing?
@pellared Did some tests with the pdata JSON/protobuf serializer used by otlphttpexporter, and confirmed the results are as expected:
nilconverts to an emptyAnyValuewhen using theFromRawmethod- an empty
AnyValueis encoded as a zero byteAnyValuemessage in protobuf, and{}in JSON - a
KeyValuewith an empty value does not omit theKeyValue.valuefield - an
ArrayValuecontaining an empty value does not omit it, reorder it, or replace it by something else - a
LogRecordwith an empty body does not omit theLogRecord.bodyfield
This can be closed. See https://github.com/open-telemetry/opentelemetry-specification/pull/4656#issuecomment-3274648161
Thanks not sure how I missed that! https://github.com/open-telemetry/opentelemetry-specification/blob/v1.48.0/specification/common/attribute-type-mapping.md#empty-values