| 
22 | 22 | 
 
  | 
23 | 23 | try:  | 
24 | 24 |     try:  | 
25 |  | -        from anthropic import NOT_GIVEN  | 
 | 25 | +        from anthropic import NotGiven  | 
26 | 26 |     except ImportError:  | 
27 |  | -        NOT_GIVEN = None  | 
 | 27 | +        NotGiven = None  | 
 | 28 | + | 
 | 29 | +    try:  | 
 | 30 | +        from anthropic import Omit  | 
 | 31 | +    except ImportError:  | 
 | 32 | +        Omit = None  | 
28 | 33 | 
 
  | 
29 | 34 |     from anthropic.resources import AsyncMessages, Messages  | 
30 | 35 | 
 
  | 
@@ -168,12 +173,13 @@ def _set_input_data(span, kwargs, integration):  | 
168 | 173 |     }  | 
169 | 174 |     for key, attribute in kwargs_keys_to_attributes.items():  | 
170 | 175 |         value = kwargs.get(key)  | 
171 |  | -        if value is not NOT_GIVEN and value is not None:  | 
 | 176 | + | 
 | 177 | +        if value is not None and _is_given(value):  | 
172 | 178 |             set_data_normalized(span, attribute, value)  | 
173 | 179 | 
 
  | 
174 | 180 |     # Input attributes: Tools  | 
175 | 181 |     tools = kwargs.get("tools")  | 
176 |  | -    if tools is not NOT_GIVEN and tools is not None and len(tools) > 0:  | 
 | 182 | +    if tools is not None and _is_given(tools) and len(tools) > 0:  | 
177 | 183 |         set_data_normalized(  | 
178 | 184 |             span, SPANDATA.GEN_AI_REQUEST_AVAILABLE_TOOLS, safe_serialize(tools)  | 
179 | 185 |         )  | 
@@ -419,3 +425,15 @@ async def _sentry_patched_create_async(*args, **kwargs):  | 
419 | 425 |                     span.__exit__(None, None, None)  | 
420 | 426 | 
 
  | 
421 | 427 |     return _sentry_patched_create_async  | 
 | 428 | + | 
 | 429 | + | 
 | 430 | +def _is_given(obj):  | 
 | 431 | +    # type: (Any) -> bool  | 
 | 432 | +    """  | 
 | 433 | +    Check for givenness safely across different openai versions.  | 
 | 434 | +    """  | 
 | 435 | +    if NotGiven is not None and isinstance(obj, NotGiven):  | 
 | 436 | +        return False  | 
 | 437 | +    if Omit is not None and isinstance(obj, Omit):  | 
 | 438 | +        return False  | 
 | 439 | +    return True  | 
0 commit comments