Bug Report: NotGiven sentinel leak in Anthropic instrumentation
Which component is this bug for?
Anthropic Instrumentation
Description
set_span_attribute() in \traceloop\openllmetry\tree\main\packages\opentelemetry-instrumentation-anthropic\opentelemetry\instrumentation\anthropic\\utils.py filters None and empty strings but not the Anthropic SDK's NOT_GIVEN sentinel (type Omit / NotGiven). When optional parameters like temperature or top_p are not explicitly set, the sentinel leaks into span.set_attribute(), producing OTel type warnings:
Invalid type Omit for attribute 'gen_ai.request.temperature' value.
Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those typesSame pattern as #4230(log Body) and #3472(OpenAI Omit), but in Anthropic span attributes.
Reproduction steps
- Install opentelemetry-instrumentation-anthropic and anthropic SDK (0.52+)
- Call client.messages.create(model="...", max_tokens=1024, messages=[...]) without setting temperature or top_p
- Observe warning: Invalid type Omit for attribute 'gen_ai.request.temperature'
Expected behavior
set_span_attribute() should silently skip NOT_GIVEN / Omit sentinel values, same as it skips None and "".
Actual Behavior with Screenshots
The sentinel passes through to span.set_attribute(), which rejects non-primitive types and logs a warning per attribute.
Python Version
3.11 / 3.13 (reproducible on both)
Provide any additional context for the Bug.
The OpenAI instrumentation already handles this in two places: ・_set_span_attribute checks value == openai.NOT_GIVEN ・_sanitize_sentinel_values() strips sentinels from kwargs(#3472)
Have you spent some time to check if this bug has been raised before?
- I checked and didn't find similar issue
Are you willing to submit PR?
Yes I am willing to submit a PR!
Source: traceloop/openllmetry