File tree Expand file tree Collapse file tree 1 file changed +4
-8
lines changed
sentry_sdk/integrations/openai_agents/patches Expand file tree Collapse file tree 1 file changed +4
-8
lines changed Original file line number Diff line number Diff line change 1+ import copy
12from functools import wraps
23
34from sentry_sdk .integrations import DidNotEnable
@@ -31,11 +32,9 @@ def _create_get_model_wrapper(original_get_model):
3132 def wrapped_get_model (cls , agent , run_config ):
3233 # type: (agents.Runner, agents.Agent, agents.RunConfig) -> agents.Model
3334
34- model = original_get_model (agent , run_config )
35-
36- # check if we have already patched this model
37- if getattr (model , "_sentry_wrapped_get_model" , False ):
38- return model
35+ # copy the model to double patching its methods. We use copy on purpose here (instead of deepcopy)
36+ # because we only patch its direct methods, all underlying data can remain unchanged.
37+ model = copy .copy (original_get_model (agent , run_config ))
3938
4039 # Wrap _fetch_response if it exists (for OpenAI models) to capture raw response model
4140 if hasattr (model , "_fetch_response" ):
@@ -75,9 +74,6 @@ async def wrapped_get_response(*args, **kwargs):
7574
7675 model .get_response = wrapped_get_response
7776
78- # set marker that we have already patched this model
79- model ._sentry_wrapped_get_model = True
80-
8177 return model
8278
8379 return wrapped_get_model
You can’t perform that action at this time.
0 commit comments