Skip to content

Commit 7d80e04

Browse files
committed
wip
1 parent 507bf17 commit 7d80e04

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

sentry_sdk/integrations/openai.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727
try:
2828
try:
29-
from openai import NOT_GIVEN
29+
from openai import NotGiven, Omit
3030
except ImportError:
31-
NOT_GIVEN = None
31+
NotGiven = None
3232

3333
from openai.resources.chat.completions import Completions, AsyncCompletions
3434
from openai.resources import Embeddings, AsyncEmbeddings
@@ -211,12 +211,12 @@ def _set_input_data(span, kwargs, operation, integration):
211211
for key, attribute in kwargs_keys_to_attributes.items():
212212
value = kwargs.get(key)
213213

214-
if value is not NOT_GIVEN and value is not None:
214+
if value is not None and _is_given(value):
215215
set_data_normalized(span, attribute, value)
216216

217217
# Input attributes: Tools
218218
tools = kwargs.get("tools")
219-
if tools is not NOT_GIVEN and tools is not None and len(tools) > 0:
219+
if tools is not None and _is_given(tools) and len(tools) > 0:
220220
set_data_normalized(
221221
span, SPANDATA.GEN_AI_REQUEST_AVAILABLE_TOOLS, safe_serialize(tools)
222222
)
@@ -696,3 +696,15 @@ async def _sentry_patched_responses_async(*args, **kwargs):
696696
return await _execute_async(f, *args, **kwargs)
697697

698698
return _sentry_patched_responses_async
699+
700+
701+
def _is_given(obj):
702+
# type: (Any) -> bool
703+
"""
704+
Check for givenness safely across different openai versions.
705+
"""
706+
if NotGiven is not None and isinstance(obj, NotGiven):
707+
return False
708+
if Omit is not None and isinstance(obj, Omit):
709+
return False
710+
return True

0 commit comments

Comments
 (0)