@@ -116,6 +116,10 @@ def _calculate_chat_completion_usage(
116116
117117def _new_chat_completion_common (f , * args , ** kwargs ):
118118 # type: (Any, *Any, **Any) -> Any
119+ integration = sentry_sdk .get_client ().get_integration (OpenAIIntegration )
120+ if integration is None :
121+ return f (* args , ** kwargs )
122+
119123 if "messages" not in kwargs :
120124 # invalid call (in all versions of openai), let it return error
121125 return f (* args , ** kwargs )
@@ -144,8 +148,6 @@ def _new_chat_completion_common(f, *args, **kwargs):
144148 span .__exit__ (None , None , None )
145149 raise e from None
146150
147- integration = sentry_sdk .get_client ().get_integration (OpenAIIntegration )
148-
149151 with capture_internal_exceptions ():
150152 if should_send_default_pii () and integration .include_prompts :
151153 set_data_normalized (span , SPANDATA .AI_INPUT_MESSAGES , messages )
@@ -271,12 +273,15 @@ async def _sentry_patched_create_async(*args, **kwargs):
271273
272274def _new_embeddings_create_common (f , * args , ** kwargs ):
273275 # type: (Any, *Any, **Any) -> Any
276+ integration = sentry_sdk .get_client ().get_integration (OpenAIIntegration )
277+ if integration is None :
278+ return f (* args , ** kwargs )
279+
274280 with sentry_sdk .start_span (
275281 op = consts .OP .OPENAI_EMBEDDINGS_CREATE ,
276282 description = "OpenAI Embedding Creation" ,
277283 origin = OpenAIIntegration .origin ,
278284 ) as span :
279- integration = sentry_sdk .get_client ().get_integration (OpenAIIntegration )
280285 if "input" in kwargs and (
281286 should_send_default_pii () and integration .include_prompts
282287 ):
0 commit comments