Skip to content

fix(proto): accept null AnyValue fields in OTLP JSON#3603

Open
bruno-espino wants to merge 2 commits into
open-telemetry:mainfrom
pydantic:fix/otlp-json-null-anyvalue
Open

fix(proto): accept null AnyValue fields in OTLP JSON#3603
bruno-espino wants to merge 2 commits into
open-telemetry:mainfrom
pydantic:fix/otlp-json-null-anyvalue

Conversation

@bruno-espino

@bruno-espino bruno-espino commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Changes

The ProtoJSON mapping requires parsers to accept null for any field and leave that field unset. The AnyValue protobuf definition permits its oneof to remain unset.

The custom AnyValue visitor introduced in #1753 deserializes recognized fields directly into their concrete type. As a result, {"intValue":null} fails with data did not match any variant of untagged enum StringOrInt instead of producing an empty AnyValue. This happens before the empty-value handling fixed in #3595, so it is a separate pre-existing case.

This occurs in real exporter traffic: the Vercel AI SDK can emit doubleValue: null for non-finite token attributes, and PostHog independently encountered whole-request failures in opentelemetry-proto and merged a receiver-side workaround that removes null-valued AnyValue fields before deserialization.

Deserialize each recognized field through Option, treating null as unset while preserving normal validation for non-null values. Regression coverage includes every AnyValue variant.

This was also tested through an OTLP receiver's JSON ingest path: upstream main rejected {"intValue":null} with the StringOrInt error; with this change it decodes as an unset value, while a fractional intValue remains rejected.

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated
  • Appropriate CHANGELOG.md updated
  • No public API changes

@bruno-espino
bruno-espino requested a review from a team as a code owner July 22, 2026 21:25
@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.2%. Comparing base (0e78170) to head (c21c95a).

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #3603   +/-   ##
=====================================
  Coverage   83.2%   83.2%           
=====================================
  Files        130     130           
  Lines      28246   28246           
=====================================
  Hits       23506   23506           
  Misses      4740    4740           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bruno-espino bruno-espino changed the title Accept null AnyValue fields in OTLP JSON fix(proto): accept null AnyValue fields in OTLP JSON Jul 22, 2026
@bruno-espino

bruno-espino commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

The integration test failure appears unrelated to this change, could a maintainer please rerun the failed job?

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.

1 participant