Skip to content

fix(google-genai): trace embeddings caches and interactions - #374

Open
nik13 wants to merge 2 commits into
devfrom
fix/google-genai-resource-coverage
Open

nik13 wants to merge 2 commits into
devfrom
fix/google-genai-resource-coverage

Conversation

@nik13

@nik13 nik13 commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Retain traceAI-google-genai and fill its missing resource coverage; this package remains useful and should not be deleted. Existing generation tracing and the GoogleGenAIInstrumentor entry point stay unchanged.

  • Trace sync/async models.embed_content and cache create/get/update/delete.
  • Trace sync/async Interactions create/get, including both legacy InteractionsResource and current GeminiNextGenInteractions classes.
  • Keep Interactions spans open through consumption, error/cancellation, explicit close and context-manager exit; preserve event/response identity and parent context. Suppress nested resource wrappers to avoid duplicate spans.
  • Record embedding dimensions/vectors, interaction model/usage and cache metadata. Cache token counts are not generation usage. Preserve distinct streamed event fragments and sum usage over automatic-continuation completion events.
  • Bound content capture to 64 KiB; respect input/output/vector hiding before retaining content. Never serialize transport headers, HTTP options or whole SDK response envelopes. Telemetry extraction failures fail open with content-free warning logs.

No Live or agent instrumentation changes, native tracing replacement, new dependencies, version bump or release. PR #276 fixes generation stream part merging; this does not modify that implementation.

Reproduction and verification

The real SDK with httpx.MockTransport previously emitted only GenerateContent for generation + embedding + cache creation. With this change it emits all three expected spans. All tests below ran with outbound network denied except localhost. No vendor API or real credentials were used.

SDK Core Result
1.8.0 (declared minimum) repository core 36 passed, 13 skipped (Interactions absent)
1.24.0 (lock) published 1.1.0 36 passed, 13 skipped (Interactions absent)
1.75.0 (legacy Interactions) repository core 48 passed, 1 skipped (typed NextGen request absent)
2.34.0 (current) repository core 49 passed

Restoring only the original instrumentor entry point while retaining the regression tests produces 15 failures at 1.8.0 and 28 at 2.34.0. Local collector tests export actual OTLP/HTTP protobuf and inspect the wire for span shape, content hiding, vectors and transport-secret exclusion. Additional cases cover parentage, suppress/uninstrument, SDK errors, cancellation, early close, error events, nested calls, bounded buffering and telemetry extraction failures.

Re-run after installation:

python -I -m pytest python/frameworks/google-genai/tests/test_resources.py -q

A dedicated wheel-based, network-denied CI matrix covers Python 3.10–3.13 at SDK floor, lock, legacy and current versions. New modules/tests pass Ruff check and format. The entry-point file has the same eight pre-existing Ruff findings as the base; no unrelated formatting sweep is included.

Documentation and rollout

README states exact coverage and lifecycle/privacy behavior. The site guide is held until the corrected package is available on the registry; no docs PR claims unreleased support. Other SDK resources (including image generation and Live) are not covered by this package. Close streams when stopping early; abandoned, unclosed streams are not guaranteed to export.

E2E coverage

Not applicable (no product e2e/ harness); real SDK request/response/SSE parsing and localhost OTLP export are covered by offline tests.

Generated with Claude Code

nik13 and others added 2 commits October 31, 2026 06:55