Skip to content

[EXPORTER] Convert uint64_t attribute values exceeding INT64_MAX to s… - #862

Merged
malkia merged 1 commit into
malkia:mainfrom
open-telemetry:main
Jun 2, 2026
Merged

[EXPORTER] Convert uint64_t attribute values exceeding INT64_MAX to s…#862
malkia merged 1 commit into
malkia:mainfrom
open-telemetry:main

Conversation

@malkia

@malkia malkia commented Jun 2, 2026

Copy link
Copy Markdown
Owner

…tring per OTel spec (open-telemetry#4090)

Per OpenTelemetry attribute type-mapping spec (https://opentelemetry.io/ docs/specs/otel/common/attribute-type-mapping/#integer-values), integer values outside the 64-bit signed range MUST be encoded as AnyValue's string_value using decimal representation, not wrapped to a negative int64 via narrowing.

Pre-PR behavior at the four uint64_t conversion sites in otlp_populate_attribute_utils.cc was to implicitly narrow (suppressed via NOLINT). For uint64_t values exceeding INT64_MAX, this produced negative int_value on the wire — a long-standing spec violation that predates this PR.

This PR fixes the violation via a file-local helper SetUint64Value that dispatches to set_int_value or set_string_value based on the value's range. All four uint64_t sites in both PopulateAnyValue overloads now follow the spec.

Spec-compliance verified by three new tests in otlp_recordable_test.cc:

  • UINT64_MAX-equivalent value -> string_value with decimal representation
  • INT64_MAX boundary value -> int_value (encoding split is val > INT64_MAX)
  • Mixed-value array -> per-element dispatch (int + string in same array)

Side effect: the four bugprone-narrowing-conversions warnings clang-tidy v22 was reporting are eliminated (the static_cast is now in a guarded branch, suppressing the diagnostic). Ratchet drops accordingly:

  • abiv1-preview warning_limit lowered from 389 to 385
  • abiv2-preview warning_limit lowered from 395 to 391

Behavior change: existing callers relying on the wrap-to-negative behavior for uint64 > INT64_MAX will now see string_value on the wire instead of negative int_value. This was never spec-conformant; the new behavior aligns OTLP output with the protocol specification.

Part of open-telemetry#2053

Fixes # (issue)

Changes

Please provide a brief description of the changes here.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

…tring per OTel spec (#4090)

Per OpenTelemetry attribute type-mapping spec (https://opentelemetry.io/
docs/specs/otel/common/attribute-type-mapping/#integer-values), integer
values outside the 64-bit signed range MUST be encoded as AnyValue's
string_value using decimal representation, not wrapped to a negative
int64 via narrowing.

Pre-PR behavior at the four uint64_t conversion sites in
otlp_populate_attribute_utils.cc was to implicitly narrow (suppressed
via NOLINT). For uint64_t values exceeding INT64_MAX, this produced
negative int_value on the wire — a long-standing spec violation that
predates this PR.

This PR fixes the violation via a file-local helper SetUint64Value that
dispatches to set_int_value or set_string_value based on the value's
range. All four uint64_t sites in both PopulateAnyValue overloads now
follow the spec.

Spec-compliance verified by three new tests in otlp_recordable_test.cc:
- UINT64_MAX-equivalent value -> string_value with decimal representation
- INT64_MAX boundary value -> int_value (encoding split is val > INT64_MAX)
- Mixed-value array -> per-element dispatch (int + string in same array)

Side effect: the four bugprone-narrowing-conversions warnings clang-tidy
v22 was reporting are eliminated (the static_cast is now in a guarded
branch, suppressing the diagnostic). Ratchet drops accordingly:
* abiv1-preview warning_limit lowered from 389 to 385
* abiv2-preview warning_limit lowered from 395 to 391

Behavior change: existing callers relying on the wrap-to-negative
behavior for uint64 > INT64_MAX will now see string_value on the wire
instead of negative int_value. This was never spec-conformant; the new
behavior aligns OTLP output with the protocol specification.

Part of #2053

Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
Co-authored-by: Doug Barker <3782873+dbarker@users.noreply.github.com>
@malkia
malkia merged commit cc9d29d into malkia:main Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants