Repository navigation
Conversation
Finalization already records with the invocation's own context, so __del__ no longer attaches it. The default _execution_context moves to the concrete wrappers, which own _self_invocation, dropping the getattr.
Pull request dashboard statusWaiting on the author · refreshed 2026-11-21 13:04 UTC Investigate required status check failures. Status above doesn't look right?
|
There was a problem hiding this comment.
🟡 Changes recommended
The abandonment tests cannot detect invocation-span activation during finalization and omit assertions for ERROR status and wrapper-specific error.type, leaving these behaviors insufficiently tested.
2 open issues
What changed in this PR
This PR updates shared GenAI stream wrappers so garbage-collection finalization no longer activates abandoned invocations, relying instead on invocation-owned telemetry context.
Changes:
- Removes activation from generic and tool stream destructors.
- Moves default execution-context handling to the sync and async wrappers through a shared helper.
- Updates abandonment tests to check finalization and context restoration.
| File | Description |
|---|---|
util/opentelemetry-util-genai/tests/test_stream.py |
Revises sync and async abandonment assertions. |
util/opentelemetry-util-genai/src/opentelemetry/util/genai/stream.py |
Removes destructor activation and relocates execution-context handling. |
Review effort: Balanced
…and records error Assisted-by: Claude Opus 4.6
AgentGymLeader
left a comment
There was a problem hiding this comment.
@lmolkova I abandoned instrumented OpenAI streams after one chunk and ran gc.collect() under a caller span. I covered sync and async chat create(stream=True) and sync responses.create(stream=True).
At 6ae5660 the span ended with ERROR status and error.type _OTHER as on main (43337da). The duration exemplar and both log records (details and exception) still point at it.
The only difference I saw is in _on_stream_error, which now sees the caller's span.

Abandoned stream wrappers no longer make the invocation current when
__del__finalizes them. The default_execution_context()moves from the shared base toSyncStreamWrapperandAsyncStreamWrapper, which own_self_invocation, so thegetattrgoes away.The scope in
__del__came from #817, whenfail()ran the completion hook in whatever context was current. Now the invocation attaches its own context around the hook, and metrics, the exception event and span end all pass that context explicitly. Attaching context from a GC finalizer adds nothing.