Repository navigation
Fix lazy request iterator capture in Anthropic instrumentation - #873
Merged
lmolkova merged 7 commits intoOct 13, 2026
Merged
Conversation
Pull request dashboard statusMerged · refreshed 2026-10-13 15:33 UTC Status above doesn't look right?
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Request-content extraction can mask SDK failures, and the new guidance contains a broken section link.
2 open findings
What changed in this PR
Adds lazy iterator capture to util-genai and integrates it with Anthropic request-content telemetry.
Changes:
- Introduces and tests
IteratorCapture. - Captures Anthropic message, system, tool, and nested-content iterators.
- Updates dependencies, documentation, guidance, and changelogs.
| File | Description |
|---|---|
util/opentelemetry-util-genai/src/opentelemetry/util/genai/iterator_capture.py |
Implements lazy iterator capture. |
util/opentelemetry-util-genai/tests/test_iterator_capture.py |
Tests capture behavior and transparency. |
util/opentelemetry-util-genai/.changelog/873.added |
Records the new utility. |
instrumentation/.../anthropic/patch.py |
Integrates capture into Anthropic wrappers. |
instrumentation/.../anthropic/wrappers.py |
Extracts captured stream-manager input. |
instrumentation/.../anthropic/messages_extractors.py |
Applies snapshots to invocations. |
instrumentation/.../tests/test_iterator_transparency.py |
Tests SDK transparency across variants. |
instrumentation/.../tests/test_sync_messages.py |
Adds generator telemetry assertions. |
instrumentation/.../tests/test_messages_extractors.py |
Tests incomplete-message handling. |
instrumentation/.../tests/requirements.oldest.txt |
Installs the current local util floor. |
instrumentation/.../pyproject.toml |
Raises the util-genai dependency floor. |
instrumentation/.../README.rst |
Documents lazy iterator capture. |
instrumentation/.../.changelog/873.fixed |
Records the Anthropic fix. |
AGENTS.md |
Adds iterator-capture contributor guidance. |
.github/instructions/instrumentation.instructions.md |
Adds corresponding review guidance. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Assisted-by: OpenAI Codex
Assisted-by: OpenAI Codex
Assisted-by: OpenAI Codex
Assisted-by: OpenAI Codex
lmolkova
marked this pull request as ready for review
October 11, 2026 19:55
eternalcuriouslearner
approved these changes
Oct 13, 2026
sangkyoonnam
added a commit
to sangkyoonnam/opentelemetry-python-genai
that referenced
this pull request
Oct 13, 2026
6 of 8 tasks
RichardoMrMu
pushed a commit
to RichardoMrMu/opentelemetry-python-genai
that referenced
this pull request
Oct 16, 2026
…try#866) * fix(bedrock): keep request extraction errors from failing the call * chore(bedrock): add changelog fragment for open-telemetry#866 * feat(util-genai): add suppress_extraction_errors and use it in bedrock Assisted-by: Claude Opus 5.5 * fix: use suppress_extraction_errors in openai, anthropic, portkey and google-genai Assisted-by: Claude Opus 5.5 * chore: add changelog fragments for open-telemetry#866 * fix(smolagents): keep request extraction errors from failing the call Assisted-by: Claude Opus 5.5 * refactor: drop suppress_extraction_errors Assisted-by: Claude Opus 5.5 * fix: handle malformed request inputs in extractors Assisted-by: Claude Opus 5.5 * chore: add changelog fragments for open-telemetry#866 * fix: tighten interactions fallback, empty contents and numeric parsing Assisted-by: Claude Opus 5.5 * chore: narrow the anthropic changelog fragment after open-telemetry#873 * fix(portkey): check numeric request parameter types instead of catching conversion errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Fix content capture for generators in Anthropic messages, nested content, system instructions, and tools. Add a shared
IteratorCapturehelper that records values as the SDK consumes them, preserving partial input when a request fails.Instrumentations can use the helper when content capture is enabled:
The helper wraps synchronous iterators inside built-in dictionaries, lists, and tuples. File objects pass through unchanged. Async iterators and custom containers are not captured.
Anthropic uses this automatically when message content capture is enabled.