Skip to content

Commit ea63aaa

Browse files
committed
Removed the ensure_integration_enabled
1 parent 9b00313 commit ea63aaa

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

sentry_sdk/integrations/anthropic.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,17 @@ def _execute_sync(f, *args, **kwargs):
191191
return e.value
192192

193193
@wraps(f)
194-
@ensure_integration_enabled(AnthropicIntegration, f)
195194
def _sentry_patched_create_sync(*args, **kwargs):
196195
# type: (*Any, **Any) -> Any
196+
integration = sentry_sdk.get_client().get_integration(AnthropicIntegration)
197+
if integration is None or "messages" not in kwargs:
198+
return f(*args, **kwargs)
199+
197200
return _execute_sync(f, *args, **kwargs)
198201

199202
return _sentry_patched_create_sync
200203

201-
204+
202205
def _wrap_async_message_create(f):
203206
# type: (Any) -> Any
204207
async def _execute_async(f, *args, **kwargs):
@@ -220,10 +223,9 @@ async def _execute_async(f, *args, **kwargs):
220223
async def _sentry_patched_create_async(*args, **kwargs):
221224
# type: (*Any, **Any) -> Any
222225
integration = sentry_sdk.get_client().get_integration(AnthropicIntegration)
223-
224226
if integration is None or "messages" not in kwargs:
225-
return f(*args, **kwargs)
226-
227+
return await f(*args, **kwargs)
228+
227229
return await _execute_async(f, *args, **kwargs)
228230

229231
return _sentry_patched_create_async

sentry_sdk/integrations/openai.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,13 @@ def _execute_sync(f, *args, **kwargs):
227227
return e.value
228228

229229
@wraps(f)
230-
@ensure_integration_enabled(OpenAIIntegration, f)
231230
def _sentry_patched_create_sync(*args, **kwargs):
232231
# type: (*Any, **Any) -> Any
232+
integration = sentry_sdk.get_client().get_integration(OpenAIIntegration)
233+
if integration is None or "messages" not in kwargs:
234+
# no "messages" means invalid call (in all versions of openai), let it return error
235+
return f(*args, **kwargs)
236+
233237
return _execute_sync(f, *args, **kwargs)
234238

235239
return _sentry_patched_create_sync
@@ -253,9 +257,13 @@ async def _execute_async(f, *args, **kwargs):
253257
return e.value
254258

255259
@wraps(f)
256-
@ensure_integration_enabled(OpenAIIntegration, f)
257260
async def _sentry_patched_create_async(*args, **kwargs):
258261
# type: (*Any, **Any) -> Any
262+
integration = sentry_sdk.get_client().get_integration(OpenAIIntegration)
263+
if integration is None or "messages" not in kwargs:
264+
# no "messages" means invalid call (in all versions of openai), let it return error
265+
return await f(*args, **kwargs)
266+
259267
return await _execute_async(f, *args, **kwargs)
260268

261269
return _sentry_patched_create_async
@@ -327,9 +335,12 @@ def _execute_sync(f, *args, **kwargs):
327335
return e.value
328336

329337
@wraps(f)
330-
@ensure_integration_enabled(OpenAIIntegration, f)
331338
def _sentry_patched_create_sync(*args, **kwargs):
332339
# type: (*Any, **Any) -> Any
340+
integration = sentry_sdk.get_client().get_integration(OpenAIIntegration)
341+
if integration is None:
342+
return f(*args, **kwargs)
343+
333344
return _execute_sync(f, *args, **kwargs)
334345

335346
return _sentry_patched_create_sync
@@ -353,9 +364,12 @@ async def _execute_async(f, *args, **kwargs):
353364
return e.value
354365

355366
@wraps(f)
356-
@ensure_integration_enabled(OpenAIIntegration, f)
357367
async def _sentry_patched_create_async(*args, **kwargs):
358368
# type: (*Any, **Any) -> Any
369+
integration = sentry_sdk.get_client().get_integration(OpenAIIntegration)
370+
if integration is None:
371+
return await f(*args, **kwargs)
372+
359373
return await _execute_async(f, *args, **kwargs)
360374

361-
return _sentry_patched_create_async
375+
return _sentry_patched_create_async

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,5 +792,5 @@ commands =
792792
[testenv:linters]
793793
commands =
794794
flake8 tests sentry_sdk
795-
black --check tests sentry_sdk
795+
black tests sentry_sdk
796796
mypy sentry_sdk

0 commit comments

Comments
 (0)