Skip to content

[google-genai] Instrument interactions.get as fetch_response - #755

Merged
lmolkova merged 5 commits into
open-telemetry:mainfrom
eternalcuriouslearner:feat/interactions-get-instrumentation
Sep 22, 2026
Merged

lmolkova merged 5 commits into
open-telemetry:mainfrom
eternalcuriouslearner:feat/interactions-get-instrumentation

Conversation

@eternalcuriouslearner

Copy link
Copy Markdown
Contributor

Adds fetch_response spans for client.interactions.get (sync and async), covering non-streaming, streamed and resumed-streamed retrieval, plus the with_raw_response / with_streaming_response entry points. Fixes #561.

A fetch performs no inference, so the fetched interaction's token counts are deliberately not reported; gen_ai.response.status maps budget_exceeded onto incomplete and passes requires_action through as a provider-specific value.

Known gaps:

  • Three cassettes are AI-synthesized and carry a # TODO: this is generated by AI, re-record marker: the failed_status one needs a genuinely failed generation, and the two streaming ones need background=true plus model capacity (the API returned service_unavailable while recording). The other four are real recordings, including one of an in-band stream error.
  • The streamed-content accumulator's delta-merge rules are derived from the SDK's type definitions rather than captured traffic, since streaming retrieval could not be recorded end to end. Happy to split that part out if a maintainer would rather it landed separately.
  • interactions.create's stream wrappers have several of the same defects this fixes on the fetch path (the SSE completion event is compared against interaction_completed rather than interaction.completed, so streamed create spans silently lose response model, id, token usage and content). I'll file those separately.

🤖 Generated with Claude Code

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-09-22 18:31 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

🟡 Changes recommended

One or more issues must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity · 3 Low severity

Open (4)
What changed in this PR

Adds fetch_response tracing for Google GenAI interactions.get, extending the existing instrumentation and shared GenAI telemetry utilities.

Changes:

  • Adds sync/async fetch spans with status, model, cursor, content, and error handling.
  • Adds streamed, resumed-streamed, raw-response, and conformance coverage.
  • Updates documentation, changelog, tests, and VCR cassettes.
File Description
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​test_instrumentor.py Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​test_conformance.py Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​interactions/​util.py Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​interactions/​test_fetch_sync.py Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​interactions/​test_fetch_async.py Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​interactions/​test_e2e.py Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​interactions/​fetch_base.py Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​interactions/​cassettes/​test_sync_interactions_get.yaml Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​interactions/​cassettes/​test_sync_interactions_get_with_streaming_response.yaml Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​interactions/​cassettes/​test_sync_interactions_get_with_raw_response.yaml Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​interactions/​cassettes/​test_sync_interactions_get_streaming.yaml Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​interactions/​cassettes/​test_sync_interactions_get_stream_error.yaml Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​interactions/​cassettes/​test_sync_interactions_get_resumed_stream.yaml Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​interactions/​cassettes/​test_sync_interactions_get_not_found.yaml Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​interactions/​cassettes/​test_sync_interactions_get_failed_status.yaml Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​interactions/​cassettes/​test_async_interactions_get.yaml Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​interactions/​cassettes/​test_async_interactions_get_with_raw_response.yaml Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​conformance/​fetch_response.py Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​tests/​cassettes/​interactions_fetch_response_conformance.yaml Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​src/​opentelemetry/​instrumentation/​google_genai/​interactions.py Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​README.rst Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-google-genai/​.changelog/​PR_NUMBER.added Updated as part of this pull request.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

return
self._self_invocation.stop()

def _on_stream_error(self, error: Exception) -> None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

_on_stream_error should accept BaseException to match the _StreamTelemetry base class signature and handle cancellation cleanly (same on line 923 for AsyncFetchInteractionStreamWrapper):

Suggested change
def _on_stream_error(self, error: Exception) -> None:
def _on_stream_error(self, error: BaseException) -> None:

Emit a `fetch_response` span for `client.interactions.get`, sync and async,
covering non-streaming, streamed and resumed-streamed retrieval. A fetch
performs no inference, so the fetched interaction's token counts are
deliberately not reported.

Fixes open-telemetry#561

Assisted-by: Claude Opus 5
The attribute is not part of the fetch_response span in the GenAI semantic
conventions; a resumed fetch is identified by gen_ai.request.stream_cursor.
Matches the same removal made for the OpenAI package in open-telemetry#709.

Also name the changelog fragment after the PR and sort imports.

Assisted-by: Claude Opus 5
- Only serialize tool definitions when content capture is on; the attribute
  is opt-in, so the work is otherwise discarded.
- Widen `_on_stream_error` to `BaseException`, matching the base hook and the
  cancellation it actually receives.
- Report the HTTP status as `error.type` for interactions errors: they raise
  from the SDK's own hierarchy, unrelated to `google.genai.errors.APIError`,
  and carry the status as `status_code`.
- Cover `aio.interactions.with_streaming_response.get`.
- Mark the two synthesized cassettes for re-recording, and drop a stray
  interaction a record run appended to the failed-status one.

Assisted-by: Claude Opus 5
@eternalcuriouslearner
eternalcuriouslearner force-pushed the feat/interactions-get-instrumentation branch from b647d1f to 441b66a Compare September 22, 2026 10:51
@lmolkova
lmolkova added this pull request to the merge queue Sep 22, 2026
Merged via the queue into open-telemetry:main with commit 3d4ccb9 Sep 22, 2026
78 checks passed
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.

[google-genai] Add Interactions.get span

3 participants