Skip to content

opentelemetry-codegen-json: support decoding enums from names#5402

Open
herin049 wants to merge 3 commits into
open-telemetry:mainfrom
herin049:fix/json-codegen-str-enum
Open

opentelemetry-codegen-json: support decoding enums from names#5402
herin049 wants to merge 3 commits into
open-telemetry:mainfrom
herin049:fix/json-codegen-str-enum

Conversation

@herin049

@herin049 herin049 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Description

Per the ProtoJSON spec

The name of the enum value as specified in proto is used. Parsers accept both enum names and integer values. See Enum Aliasing for details on enums with aliases.

This is not relevant for the OpenTelemetry JSON exporter since it currently doesn't perform any decoding. However, it is required to support Jaeger remote sampling (see opentelemetry-go-contrib#3184).

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Tox

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@herin049 herin049 requested a review from a team as a code owner July 9, 2026 01:42
@herin049 herin049 requested a review from Copilot July 9, 2026 01:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds ProtoJSON-compliant enum decoding support to the JSON codegen/runtime so enum fields can be deserialized from either their integer value or their enum-name string (needed for Jaeger remote sampling interop).

Changes:

  • Introduces decode_enum in both the codegen runtime and the opentelemetry-proto-json runtime codec.
  • Updates generated OTLP JSON model deserializers to use decode_enum for enum fields and simplifies dataclass decoration (@dataclasses.dataclass(slots=True)).
  • Adds/updates unit tests to validate enum-name decoding and associated error behavior; adds changelog entry.

Reviewed changes

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

Show a summary per file
File Description
opentelemetry-proto-json/src/opentelemetry/proto_json/trace/v1/trace.py Switches enum field decoding to decode_enum; updates dataclass decorators/imports.
opentelemetry-proto-json/src/opentelemetry/proto_json/resource/v1/resource.py Updates dataclass decorators/imports to remove _dataclass partial.
opentelemetry-proto-json/src/opentelemetry/proto_json/profiles/v1development/profiles.py Updates dataclass decorators/imports to remove _dataclass partial.
opentelemetry-proto-json/src/opentelemetry/proto_json/metrics/v1/metrics.py Uses decode_enum for temporality enums; updates dataclass decorators/imports.
opentelemetry-proto-json/src/opentelemetry/proto_json/logs/v1/logs.py Uses decode_enum for severity enum; updates dataclass decorators/imports.
opentelemetry-proto-json/src/opentelemetry/proto_json/collector/trace/v1/trace_service.py Updates dataclass decorators/imports to remove _dataclass partial.
opentelemetry-proto-json/src/opentelemetry/proto_json/collector/profiles/v1development/profiles_service.py Updates dataclass decorators/imports to remove _dataclass partial.
opentelemetry-proto-json/src/opentelemetry/proto_json/collector/metrics/v1/metrics_service.py Updates dataclass decorators/imports to remove _dataclass partial.
opentelemetry-proto-json/src/opentelemetry/proto_json/collector/logs/v1/logs_service.py Updates dataclass decorators/imports to remove _dataclass partial.
opentelemetry-proto-json/src/opentelemetry/proto_json/_json_codec.py Adds decode_enum helper for ProtoJSON enum decoding.
codegen/opentelemetry-codegen-json/src/opentelemetry/codegen/json/runtime/json_codec.py Adds decode_enum helper in the codegen runtime.
codegen/opentelemetry-codegen-json/src/opentelemetry/codegen/json/generator.py Emits @dataclasses.dataclass(slots=True) directly and generates enum decoding via decode_enum.
codegen/opentelemetry-codegen-json/tests/test_serde.py Adds serde tests ensuring enum fields accept both name and integer; updates invalid-type expectations.
codegen/opentelemetry-codegen-json/tests/test_json_codec.py Adds direct unit tests for decode_enum success/error cases.
.changelog/5402.fixed Changelog entry for enum-name decoding support.

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

@herin049 herin049 added the Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary label Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants