Skip to content

Recommend JSON object encoding of an attribute for non-OTLP#5028

Open
pellared wants to merge 11 commits intoopen-telemetry:mainfrom
pellared:key-anyvalue-tuple-representation
Open

Recommend JSON object encoding of an attribute for non-OTLP#5028
pellared wants to merge 11 commits intoopen-telemetry:mainfrom
pellared:key-anyvalue-tuple-representation

Conversation

@pellared
Copy link
Copy Markdown
Member

@pellared pellared commented Apr 15, 2026

What

Adds in-development guidance for representing a single OpenTelemetry attribute as a string in non-OTLP or debugging contexts.

The recommended form is a single-entry JSON object, for example:

{"http.request.method":"GET"}

Implementation:

Why

I originally thought about key:value (and even key=value beforehand), but it is ambiguous when : appears in keys or string values and is not a robust debugging representation.

Using a JSON object improves clarity for debugging output by:

  • avoiding delimiter ambiguity
  • aligning with existing JSON-based guidance for complex AnyValue types
  • making the representation easier to read, copy, and process when needed

This also is consistent with how OTel Java, .NET, Python, Go are representing attributes in standard output exporters. Therefore, I think it would be most familiar representation for the users.

Notable conversations:

@pellared pellared marked this pull request as ready for review April 15, 2026 12:30
@pellared pellared requested review from a team as code owners April 15, 2026 12:30
Comment thread specification/common/README.md
@pellared pellared requested review from trentm and yurishkuro April 15, 2026 15:04
Comment thread specification/common/README.md Outdated
Comment thread specification/common/README.md Outdated
@pellared pellared requested a review from trentm April 15, 2026 20:31
Comment thread specification/common/README.md Outdated
@jmacd jmacd added the triage:accepted:ready Ready to be implemented. Small enough or uncontroversial enough to be implemented without sponsor label Apr 22, 2026
@jack-berg
Copy link
Copy Markdown
Member

non-OTLP or debugging contexts.

Can you clarify what this applies to? I can think of a couple of potential candidates:

  • Zipkin and other non-OTLP exporters which need to encode AnyValue types
  • Console exporter which writes to console/stout in an unspecified format
  • Generic "toString" representation called when you invoke printf or equivalent

Is this what you had in mind? Any other contexts you know of at the moment?

@pellared
Copy link
Copy Markdown
Member Author

pellared commented Apr 22, 2026

@jack-berg, mostly

Generic "toString" representation called when you invoke printf or equivalent

I thought that maybe some exporters may need a representation of a single attribute (we already have a defintion how to encode a map of AnyValue which is equivalent to a collection of attributes). This is why I decided to also include "For non-OTLP protocols".

Comment thread specification/common/README.md
Comment thread specification/common/README.md Outdated

- strings as JSON strings,
- booleans as JSON booleans,
- integers and floating point numbers as JSON numbers, except that `NaN`,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For "float64/int64" can you link to an RFC that needs to be followed? I know at least 2 ways of doing this, some use string to represent them (as proto) or others number.

Image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preventing the argument:

Ship has sailed. This is already stable for non-OTLP represnetation of AnyValue. See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/README.md#anyvalue-representation-for-non-otlp-protocols. It does not make sense to do it differently here.

Yes AnyValue was stabilized with that definition (which by the industry standard is less than ideal), but the argument can be made that since this is debugging and it cannot be read anyway by other systems better to do the right thing, and maybe reconsider the AnyValue representation since it is not readable by other systems (hence is a bug).

Copy link
Copy Markdown
Member Author

@pellared pellared Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think the concern is reasonable. There are multiple possible encodings here, and the existing non-OTLP AnyValue representation has tradeoffs, especially around numeric precision and lossless round-tripping.

However, for this PR I think we should keep the single-attribute representation aligned with the existing AnyValue representation. Using a different encoding for an Attribute value than for the same value inside map<string, AnyValue> would be awkward and arguably incompatible within the same domain model.

I updated the wording to avoid re-defining the value encoding rules here and instead refer to the existing “AnyValue representation for non-OTLP protocols” section. dccd5bb

I also created #5053 to refine the existing “AnyValue representation for non-OTLP protocols” section

If we want to address the broader concern, I think that should probably be a separate proposal for a revised/v2 non-OTLP representation. Since this is recommendation-level guidance, that proposal could potentially define two recommended representations and spell out the tradeoffs, for example compact/readable output versus a more explicit representation that preserves type information better. It is also worth noting that currently there is non public issue complaining that the non-OTLP representation is lossy (or at least I failed to find one). Also it looks like it was a conscious decision: #4848.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, for this PR I think we should keep the single-attribute representation aligned with the existing AnyValue representation. Using a different encoding for an Attribute value than for the same value inside map<string, AnyValue> would be awkward and arguably incompatible within the same domain model.

I am worried about this, why not consistent with the OTLP Json representation? Same question for the AnyValue?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pellared I don't see anywhere in the reference you pointed why did we decide to be inconsistent from OTLP JSON representation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pellared pellared requested a review from bogdandrutu April 27, 2026 07:01
@pellared pellared changed the title recommend JSON object encoding for attribute debugging Recommend JSON object encoding for attribute debugging Apr 27, 2026
@pellared pellared changed the title Recommend JSON object encoding for attribute debugging Recommend JSON object encoding for non-OTLP representation Apr 27, 2026
@pellared pellared changed the title Recommend JSON object encoding for non-OTLP representation Recommend JSON object encoding of an attribute for non-OTLP Apr 27, 2026
@pellared pellared requested review from Copilot and removed request for trentm and yurishkuro April 27, 2026 07:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds specification guidance for a consistent, unambiguous string representation of a single OpenTelemetry attribute in non-OTLP/debugging contexts, recommending a single-entry JSON object form.

Changes:

  • Add a new “Attribute representation for non-OTLP” section describing a single-entry JSON object encoding aligned with existing AnyValue non-OTLP encoding guidance.
  • Add an Unreleased changelog entry documenting the new in-development guidance.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
specification/common/README.md Introduces the new guidance section and examples for JSON-object attribute encoding in non-OTLP/debugging contexts.
CHANGELOG.md Adds an Unreleased “Common” entry describing the new guidance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread specification/common/README.md
Comment thread CHANGELOG.md Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage:accepted:ready Ready to be implemented. Small enough or uncontroversial enough to be implemented without sponsor

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.