opentelemetry-codegen-json: support decoding enums from names#5402
Open
herin049 wants to merge 3 commits into
Open
opentelemetry-codegen-json: support decoding enums from names#5402herin049 wants to merge 3 commits into
herin049 wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
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_enumin both the codegen runtime and theopentelemetry-proto-jsonruntime codec. - Updates generated OTLP JSON model deserializers to use
decode_enumfor 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Per the ProtoJSON spec
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.
How Has This Been Tested?
Tox
Does This PR Require a Contrib Repo Change?
Checklist: