Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions sentry_sdk/integrations/openai_agents/patches/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
from functools import wraps

from sentry_sdk.integrations import DidNotEnable
Expand Down Expand Up @@ -31,8 +32,9 @@ def _create_get_model_wrapper(original_get_model):
def wrapped_get_model(cls, agent, run_config):
# type: (agents.Runner, agents.Agent, agents.RunConfig) -> agents.Model

model = original_get_model(agent, run_config)
original_get_response = model.get_response
# copy the model to double patching its methods. We use copy on purpose here (instead of deepcopy)
# because we only patch its direct methods, all underlying data can remain unchanged.
model = copy.copy(original_get_model(agent, run_config))

# Wrap _fetch_response if it exists (for OpenAI models) to capture raw response model
if hasattr(model, "_fetch_response"):
Expand All @@ -48,6 +50,8 @@ async def wrapped_fetch_response(*args, **kwargs):

model._fetch_response = wrapped_fetch_response

original_get_response = model.get_response

@wraps(original_get_response)
async def wrapped_get_response(*args, **kwargs):
# type: (*Any, **Any) -> Any
Expand Down