Align GenAI message dataclasses with semconv message schemas - #284
Align GenAI message dataclasses with semconv message schemas#284lmolkova wants to merge 2 commits into
Conversation
Add `name` to InputMessage/OutputMessage, add Compaction, SystemInstructionPart, MemoryRecord, and RetrievalDocument, extend Modality with `document`, and update FinishReason to the schema enum (`tool_calls` -> `tool_call`, add `compaction`). Message and tool-definition serialization now omits None-valued fields (new `asdict_without_none` helper) to match the semconv JSON schemas, on the span, event, and upload-hook paths.
There was a problem hiding this comment.
Pull request overview
Aligns opentelemetry-util-genai message/tool dataclasses and their JSON serialization with the GenAI semantic-conventions message schemas (notably: omit unset optional fields instead of emitting JSON null), and updates Google GenAI instrumentation tests to match.
Changes:
- Added/updated message schema dataclasses and enums in
opentelemetry-util-genai(e.g.,nameon messages,Compaction, updatedFinishReason, extendedModality). - Introduced
asdict_without_noneand switched message/tool serialization paths to omitNonefields for schema parity. - Updated Google GenAI instrumentation parsing and tests for the new
GenericPartshape and tool-definition JSON output.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| util/opentelemetry-util-genai/tests/test_upload.py | Updates expected uploaded tool-definition JSON to omit parameters: null. |
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/utils.py | Adds asdict_without_none helper for schema-aligned dataclass serialization. |
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/types.py | Updates/extends semconv-aligned message/tool dataclasses and literals. |
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/_upload/completion_hook.py | Uses asdict_without_none for tool/message serialization in upload paths. |
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/_invocation.py | Uses asdict_without_none for span/event content attributes. |
| util/opentelemetry-util-genai/.changelog/+message-schema-parity.changed | Adds a changelog fragment (but filename currently violates CI naming rules). |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/interactions/test_parser.py | Asserts GenericPart.type is preserved in the generic fallback. |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/interactions/base.py | Updates expected tool-definition JSON to omit parameters: null. |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/generate_content/nonstreaming_base.py | Updates expected tool-definition JSON fixtures to omit parameters: None/null. |
| instrumentation/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/interactions.py | Populates GenericPart(type=..., value=...) for unsupported parts. |
- Rename changelog fragment to PR number - Default Compaction.id/content to None (optional and omitted) - Bridge google-genai oldest env to workspace util-genai (needs 1.1b0 None-omitting serialization) Assisted-by: Claude Opus 4.8 (1M context)
5e83670 to
ac13891
Compare
Pull request dashboard statusWaiting on the author · refreshed 2026-07-29 19:40 UTC Respond to 2 review items (e.g. link a commit, explain why not, ask a follow-up): Status above doesn't look right?
|
| """Represents a single memory record exposed to or produced by the model. | ||
|
|
||
| This model is specified as part of semconv in `GenAI messages Python models - MemoryRecord | ||
| <https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/non-normative/models.ipynb>`__. |
There was a problem hiding this comment.
This link (and below) doesn't resolve, they point to the old repo
|
|
||
| content: Any | ||
| id: str | None = None | ||
| metadata: dict[str, Any] | None = None |
There was a problem hiding this comment.
I feel we should start just using AttributeValue instead of Any in these types, since they ultimately go into a span/log attribute right ?
For Input/OutputMessage we just end up completely serializing those (using json.dumps) types into a string.. so I think those Anys are fine to be left as is..
|
Hi @lmolkova — just a friendly reminder that this pull request has been waiting on you for a week. There are still items that need your attention. See the dashboard status comment for the full list. You don't need to push a code change to hand it back — replying to move each discussion forward is enough, whether that's answering a question, explaining why no change is needed, or asking a follow-up. The dashboard then automatically routes it back to reviewers. If you believe this pull request is incorrectly routed as waiting on the author, comment |
Add
nameto InputMessage/OutputMessage, add Compaction, SystemInstructionPart, MemoryRecord, and RetrievalDocument, extend Modality withdocument, and update FinishReason to the schema enum (tool_calls->tool_call, addcompaction).Message and tool-definition serialization now omits None-valued fields (new
asdict_without_nonehelper) to match the semconv JSON schemas, on the span, event, and upload-hook paths.