Repository navigation
Conversation
Pull request dashboard statusMerged · refreshed 2026-10-16 15:55 UTC Status above doesn't look right?
|
There was a problem hiding this comment.
🟢 Approval recommended
The implementation preserves SDK exceptions and invocation finalization with comprehensive regression coverage.
0 open findings
What changed in this PR
Prevents Bedrock request-extraction failures from altering SDK behavior or leaving telemetry invocations unfinished.
Changes:
- Adds guarded request extraction with debug logging.
- Covers sync/async handlers and regression scenarios.
| File | Description |
|---|---|
patch.py |
Safely invokes Bedrock request extractors. |
tests/test_patch.py |
Tests extraction failures, SDK errors, and recovery. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| BEDROCK_AGENT_RUNTIME = "bedrock-agent-runtime" | ||
|
|
||
|
|
||
| def _extract_request( |
There was a problem hiding this comment.
i wonder if this method can be in utils instead, and all instrumentations can be updated to use it ? I think we have the same issue in all instrumentations ?
There was a problem hiding this comment.
Yes, I think the same shape is elsewhere. In the OpenAI instrumentation, for example, create_chat_invocation runs before the try in patch.py, and malformed message input can raise there when content capture is enabled. I kept this one Bedrock-only on purpose: a shared helper would be new util-genai API, so I'd rather agree on the approach first. Would you prefer an issue for a util-level helper, with this PR staying as the Bedrock fix, or should I fold it in here? Either way, I'm happy to take the follow-up for the other instrumentations.
There was a problem hiding this comment.
lets try putting it in utils and updating all instrumentations to use it..
There was a problem hiding this comment.
Moved it to util-genai as suppress_extraction_errors(), and bedrock, openai, anthropic, portkey, google-genai and smolagents use it now. The description lists the remaining gaps.
Assisted-by: Claude Opus 5.5
… google-genai Assisted-by: Claude Opus 5.5
Assisted-by: Claude Opus 5.5
lmolkova
left a comment
There was a problem hiding this comment.
Please fix the extraction paths that can throw. Do not add blanket exception suppression. Extractors should handle malformed inputs defensively at the point of extraction. Instrumentation code is written in defensive way and in most cases cannot throw. Adding blanket suppression logic pollutes the code and make it impossible to understand where exceptions should be handled (in the code that calls something that can throw)
| with suppress_extraction_errors(): | ||
| raw_agent_id = api_params.get("agentId") | ||
| if raw_agent_id: | ||
| invocation.agent_id = str(raw_agent_id) |
There was a problem hiding this comment.
We should not guard against arbitrary objects whose str raises where the SDK expects a string. This is outside the expected input contract, and the same kind of failure could occur anywhere, including in the exception handler or exporting pipeline
|
Thanks for the review and the direction. I'll drop |
Assisted-by: Claude Opus 5.5
Assisted-by: Claude Opus 5.5
Assisted-by: Claude Opus 5.5
|
@lmolkova Thanks, done. I dropped |
| def _safe_float(value: Any) -> float | None: | ||
| try: | ||
| return float(value) | ||
| except (TypeError, ValueError): | ||
| return None | ||
|
|
||
|
|
||
| def _safe_int(value: Any) -> int | None: | ||
| try: | ||
| return int(value) | ||
| except (TypeError, ValueError): | ||
| return None |
There was a problem hiding this comment.
These still raise: float(10**400) and int(float("inf")) throw OverflowError, and float(obj) runs arbitrary __float__. Could we check types up front instead of catching, so the code can't throw (same idea as _coerce_float in google-genai interactions.py)?
| def _safe_float(value: Any) -> float | None: | |
| try: | |
| return float(value) | |
| except (TypeError, ValueError): | |
| return None | |
| def _safe_int(value: Any) -> int | None: | |
| try: | |
| return int(value) | |
| except (TypeError, ValueError): | |
| return None | |
| def _as_float(value: Any) -> float | None: | |
| if isinstance(value, float): | |
| return value | |
| if ( | |
| isinstance(value, int) | |
| and not isinstance(value, bool) | |
| and abs(value) <= sys.float_info.max | |
| ): | |
| return float(value) | |
| return None | |
| def _as_int(value: Any) -> int | None: | |
| if isinstance(value, int) and not isinstance(value, bool): | |
| return value | |
| return None |
(needs import sys; a test case with temperature=10**400 would cover it.)
There was a problem hiding this comment.
Applied your suggestion in 9e48fd9 and added the 10**400 and inf cases; numeric strings are now dropped by the type check.
…ng conversion errors
|
The |
Resolve the single content conflict in tests/test_responses.py by keeping both sides: the Responses.parse() coverage added on this branch and the malformed-input test from open-telemetry#866 on main. Production files auto-merged; the parse() wiring in __init__.py and response_extractors.py is intact. Assisted-by: Doubao
Description
Fixes request extraction in bedrock, openai, anthropic, portkey and google-genai that raised on malformed input, so the request reaches the SDK and the SDK returns its own error. Each fix sits at the line that raised and uses a type check, safe field access or narrowly guarded numeric conversion: a Converse
document.formatthat isn't a string, chatmessages=None, a Responses orinteractions.createinput item whosetypeisn't a string, an Anthropic message withoutroleor asystemlist of plain strings, Portkey sampling or token parameters that don't convert to numbers, andgenerate_contentwithcontentsofNoneor an empty list.Known gaps: this covers the listed extraction failures; other malformed input paths and objects whose
__str__raises are out of scope.Type of change
How has this been tested?
Regression cases pass on this branch and fail against upstream/main source. tox latest and oldest for the five packages, plus typecheck.
Checklist