Skip to content

[opentelemetry-util-genai] Deprecate should_emit_event, use private _should_emit_event, and support dataclass serialization - #746

Merged
lmolkova merged 2 commits into
open-telemetry:mainfrom
lmolkova:refactor/utils-event-mode-and-json-dataclass
Sep 20, 2026
Merged

lmolkova merged 2 commits into
open-telemetry:mainfrom
lmolkova:refactor/utils-event-mode-and-json-dataclass

Conversation

@lmolkova

@lmolkova lmolkova commented Sep 19, 2026

Copy link
Copy Markdown
Member

What does this change do?

Deprecates should_emit_event() in docstring and replaces internal usages with _should_emit_event(content_capturing_mode: ContentCapturingMode). Also adds dataclass serialization support to _GenAiJsonEncoder.

Why?

Avoids os.environ lookups on the hot path during _finish() and keeps event emission decisions internal to util-genai while preserving backward compatibility. This helps prepare for codegen (#702).

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 19, 2026

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-09-20 05:25 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

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.

Copilot review overview

🟢 Approval recommended

The focused changes preserve existing precedence behavior and include appropriate regression tests.

Review effort: Lite
Findings: None

What changed in this PR

Adds explicit content-capturing mode support to event emission and enables JSON serialization of dataclass message parts in the shared GenAI utility package.

Changes:

  • Adds content_capturing_mode to should_emit_event().
  • Serializes dataclass instances through _GenAiJsonEncoder.
  • Adds unit tests for both behaviors.
File Description
util/​opentelemetry-util-genai/​src/​opentelemetry/​util/​genai/​utils.py Implements explicit mode handling and dataclass serialization.
util/​opentelemetry-util-genai/​tests/​test_utils.py Tests explicit event modes and dataclass JSON output.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@lmolkova
lmolkova force-pushed the refactor/utils-event-mode-and-json-dataclass branch from daaffa8 to 762f233 Compare September 19, 2026 07:36
@lmolkova lmolkova changed the title [opentelemetry-util-genai] Support explicit content mode in should_emit_event and dataclass serialization [opentelemetry-util-genai] Make _should_emit_event private with required mode and support dataclass serialization Sep 19, 2026
…should_emit_event, and support dataclass serialization
@lmolkova
lmolkova force-pushed the refactor/utils-event-mode-and-json-dataclass branch from 762f233 to 92c55ed Compare September 19, 2026 07:47
@lmolkova lmolkova changed the title [opentelemetry-util-genai] Make _should_emit_event private with required mode and support dataclass serialization [opentelemetry-util-genai] Deprecate should_emit_event, use private _should_emit_event, and support dataclass serialization Sep 19, 2026
@lmolkova
lmolkova added this pull request to the merge queue Sep 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 20, 2026
@lmolkova
lmolkova added this pull request to the merge queue Sep 20, 2026
Merged via the queue into open-telemetry:main with commit 65847d1 Sep 20, 2026
75 checks passed
@lmolkova
lmolkova deleted the refactor/utils-event-mode-and-json-dataclass branch September 20, 2026 05:24
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.

3 participants