Skip to content

fix(openai): Attach response model with streamed Completions API #7296

fix(openai): Attach response model with streamed Completions API

fix(openai): Attach response model with streamed Completions API #7296

Triggered via pull request February 27, 2026 09:17
Status Success
Total duration 29s
Artifacts

secret-scan.yml Required

on: pull_request
Secret Scan
25s
Secret Scan
Fit to window
Zoom out
Zoom in

Annotations

3 warnings
span.set_data call outside capture_internal_exceptions may propagate SDK errors to user code: sentry_sdk/integrations/openai.py#L615
The new `span.set_data(SPANDATA.GEN_AI_RESPONSE_MODEL, x.model)` call at line 615 is placed outside the `capture_internal_exceptions()` context manager. If accessing `x.model` raises an exception (e.g., if an API change or edge case results in a missing or differently-structured attribute), this exception will propagate to user code and potentially break their application. The existing pattern in this file (see lines 749-758 for the Responses API) places similar `span.set_data` calls inside `capture_internal_exceptions()` to prevent SDK bugs from affecting user applications.
[B8E-MPF] span.set_data call outside capture_internal_exceptions may propagate SDK errors to user code (additional location): sentry_sdk/integrations/openai.py#L659
The new `span.set_data(SPANDATA.GEN_AI_RESPONSE_MODEL, x.model)` call at line 615 is placed outside the `capture_internal_exceptions()` context manager. If accessing `x.model` raises an exception (e.g., if an API change or edge case results in a missing or differently-structured attribute), this exception will propagate to user code and potentially break their application. The existing pattern in this file (see lines 749-758 for the Responses API) places similar `span.set_data` calls inside `capture_internal_exceptions()` to prevent SDK bugs from affecting user applications.
Unguarded attribute access on streaming chunk can raise exception: sentry_sdk/integrations/openai.py#L615
The new `span.set_data(SPANDATA.GEN_AI_RESPONSE_MODEL, x.model)` call is placed outside the `capture_internal_exceptions()` block. If a streaming chunk does not have a `model` attribute (or if accessing it raises an exception), this will propagate to the user's code and potentially crash their streaming iteration. The existing pattern in `_set_streaming_responses_api_output_data` (line 758) wraps similar calls inside `with capture_internal_exceptions():` to prevent SDK instrumentation from affecting user code.