Skip to content

Commit

Permalink
Prohibit usage of enum value name strings in OTLP/JSON (#2758)
Browse files Browse the repository at this point in the history
* Prohibit usage of enum value name strings in OTLP/JSON

Resolves open-telemetry/opentelemetry-proto#424

This change disallows using enum value names as strings
in OTLP/JSON and requires to use enum integer values only.

* Fix grammar

Co-authored-by: Bogdan Drutu <[email protected]>
  • Loading branch information
ChengJinbao and bogdandrutu authored Sep 19, 2022
1 parent 8ae8851 commit 44ce854
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions specification/protocol/otlp.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,25 @@ response headers when sending binary Protobuf encoded payload.

JSON Protobuf encoded payloads use proto3 standard defined
[JSON Mapping](https://developers.google.com/protocol-buffers/docs/proto3#json)
for mapping between Protobuf and JSON, with one deviation from that mapping: the
`trace_id` and `span_id` byte arrays are represented as
[case-insensitive hex-encoded strings](https://tools.ietf.org/html/rfc4648#section-8),
they are not base64-encoded like it is defined in the standard
[JSON Mapping](https://developers.google.com/protocol-buffers/docs/proto3#json).
The hex encoding is used for `trace_id` and `span_id` fields in all OTLP
Protobuf messages, e.g. the `Span`, `Link`, `LogRecord`, etc. messages.
for mapping between Protobuf and JSON, with the following deviations from that mapping:

- The `trace_id` and `span_id` byte arrays are represented as
[case-insensitive hex-encoded strings](https://tools.ietf.org/html/rfc4648#section-8);
they are not base64-encoded like as it is defined in the standard
[Protobuf JSON Mapping](https://developers.google.com/protocol-buffers/docs/proto3#json).
The hex encoding is used for `trace_id` and `span_id` fields in all OTLP
Protobuf messages, e.g. the `Span`, `Link`, `LogRecord`, etc. messages.
For example, the `trace_id` field in a Span can be represented like this:
{ "trace_id": "5B8EFFF798038103D269B633813FC60C", ... }

- Values of enum fields MUST be encoded as integer values. Unlike the standard
[Protobuf JSON Mapping](https://developers.google.com/protocol-buffers/docs/proto3#json),
which allows values of enum fields to be encoded as either integer values or as enum
name strings, only integer enum values are allowed in OTLP JSON Protobuf Encoding;
the enum name strings MUST NOT be used.
For example, the `kind` field with a value of SPAN_KIND_SERVER in a Span can be
represented like this:
{ "kind": 2, ... }

Note that according to [Protobuf specs](
https://developers.google.com/protocol-buffers/docs/proto3#json) 64-bit integer
Expand Down

0 comments on commit 44ce854

Please sign in to comment.