Skip to content

fix(anthropic): skip NotGiven/Omit sentinel in set_span_attribute - #4432

Open
nskun wants to merge 1 commit into
traceloop:mainfrom
nskun:main
Open

fix(anthropic): skip NotGiven/Omit sentinel in set_span_attribute#4432
nskun wants to merge 1 commit into
traceloop:mainfrom
nskun:main

Conversation

@nskun

@nskun nskun commented Aug 20, 2026

Copy link
Copy Markdown
  • I have added tests that cover my changes.
  • If adding a new instrumentation or changing an existing one, I've added screenshots from some observability platform showing the change.
  • PR name follows conventional commits format: feat(instrumentation): ... or fix(instrumentation): ....
  • (If applicable) I have updated the documentation accordingly.(Not applicable)

Summary

Skip Anthropic SDK Omit and NotGiven sentinel values in set_span_attribute.

This prevents unset optional parameters such as temperature and top_p from being passed to OpenTelemetry as invalid span attribute types.

Testing

Added regression coverage for both anthropic.NOT_GIVEN and anthropic.Omit().

Fixes #4431

Summary by CodeRabbit

  • Bug Fixes
    • Improved Anthropic instrumentation to ignore unspecified option values when recording telemetry.
    • Prevented internal sentinel values from appearing as span attributes.

@CLAassistant

CLAassistant commented Aug 20, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3841cc90-7e41-4a39-9048-3272ec90061d

📥 Commits

Reviewing files that changed from the base of the PR and between 62e24c2 and e2be0db.

📒 Files selected for processing (2)
  • packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic/utils.py
  • packages/opentelemetry-instrumentation-anthropic/tests/test_set_span_attribute.py

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The Anthropic instrumentation now skips Omit and NotGiven sentinel values before setting span attributes. Parameterized tests verify that both sentinel values do not call set_attribute.

Changes

Anthropic sentinel filtering

Layer / File(s) Summary
Filter sentinel values and validate behavior
packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic/utils.py, packages/opentelemetry-instrumentation-anthropic/tests/test_set_span_attribute.py
set_span_attribute skips Omit and NotGiven values. Tests verify that neither sentinel calls set_attribute.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to e2be0

This localized change skips unset Anthropic sentinel values from span attributes and adds regression coverage; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: skipping Anthropic NotGiven and Omit sentinels.
Linked Issues check ✅ Passed The implementation and regression tests satisfy issue #4431 by skipping both NOT_GIVEN and Omit sentinel values.
Out of Scope Changes check ✅ Passed The changes are limited to sentinel filtering and focused regression tests for the linked issue.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug Report: NotGiven sentinel leak in Anthropic instrumentation

2 participants