openllmetry
openllmetry copied to clipboard
Responses API: Clean up completed responses from the global responses dictionary
Description
The OpenAI Responses API instrumentation stores response trace data in a module-level responses dictionary. However, completed responses are not removed after their spans end.
In long-running applications, this causes the dictionary to grow with every Responses API call, resulting in unbounded memory growth.
Expected Behavior
Response entries should be removed from the responses dictionary when the corresponding response completes or fails and its span ends.
Proposed Fix
- Remove the response entry using
responses.pop(response_id, None)when the span ends. - Apply the cleanup consistently to the synchronous, asynchronous, and streaming response paths.
- Add tests to verify that completed responses are removed from the dictionary.
already fixed in #4531