Skip to content

Align GenAI message dataclasses with semconv message schemas#284

Open
lmolkova wants to merge 2 commits into
open-telemetry:mainfrom
lmolkova:genai-message-schema-parity
Open

Align GenAI message dataclasses with semconv message schemas#284
lmolkova wants to merge 2 commits into
open-telemetry:mainfrom
lmolkova:genai-message-schema-parity

Conversation

@lmolkova

Copy link
Copy Markdown
Member

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.

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.

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

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., name on messages, Compaction, updated FinishReason, extended Modality).
  • Introduced asdict_without_none and switched message/tool serialization paths to omit None fields for schema parity.
  • Updated Google GenAI instrumentation parsing and tests for the new GenericPart shape 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.

Comment thread util/opentelemetry-util-genai/src/opentelemetry/util/genai/types.py
Comment thread util/opentelemetry-util-genai/src/opentelemetry/util/genai/types.py Outdated
Comment thread util/opentelemetry-util-genai/.changelog/284.changed
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 18, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

- 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)
@lmolkova
lmolkova force-pushed the genai-message-schema-parity branch from 5e83670 to ac13891 Compare July 18, 2026 05:20
@opentelemetry-pr-dashboard

Copy link
Copy Markdown

Pull request dashboard status

  • Waiting on: Reviewers
  • Next step: Review the latest changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants