Skip to content

Commit ed61be4

Browse files
committed
Make mypy happy
1 parent ea63aaa commit ed61be4

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

sentry_sdk/integrations/anthropic.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ def _get_responses(content):
9090

9191
def _sentry_patched_create_common(f, *args, **kwargs):
9292
# type: (Any, *Any, **Any) -> Any
93+
integration = sentry_sdk.get_client().get_integration(AnthropicIntegration)
94+
if integration is None:
95+
return f(*args, **kwargs)
96+
9397
if "messages" not in kwargs:
9498
return f(*args, **kwargs)
9599

@@ -115,8 +119,6 @@ def _sentry_patched_create_common(f, *args, **kwargs):
115119
span.__exit__(None, None, None)
116120
raise exc from None
117121

118-
integration = sentry_sdk.get_client().get_integration(AnthropicIntegration)
119-
120122
with capture_internal_exceptions():
121123
span.set_data(SPANDATA.AI_MODEL_ID, model)
122124
span.set_data(SPANDATA.AI_STREAMING, False)

sentry_sdk/integrations/openai.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ def _calculate_chat_completion_usage(
116116

117117
def _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

272274
def _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

Comments
 (0)