Repository navigation
feat(anthropic): expose the SDK's open_telemetry option on AnthropicConfig - #3519
Merged
Merged
Conversation
…onfig anthropic-sdk-python traces its own API calls with OpenTelemetry by default. AnthropicConfig had no way to configure or disable those spans other than the ANTHROPIC_OPEN_TELEMETRY environment variable. Pass a new open_telemetry field through to the message and files clients, and document the SDK spans. Closes ag2ai#3490
Lancetnik
approved these changes
Oct 27, 2026
Collaborator
|
Hi @ninglinLiu, thanks for the contribution! Before we can review or merge this PR, you need to sign our Contributor License Agreement — the license/cla check on this PR has the signing link. This applies to draft PRs as well: we don't want you to invest work into a change we can't accept. Once the CLA is signed, the check turns green, the status:needs-cla label is removed, and the PR proceeds through the normal flow. ⏳ If the CLA isn't signed within 3 days, this PR will be marked stale and closed 7 days after that. Signing later and reopening is always an option. |
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why are these changes needed?
anthropic1.14+ traces its own API calls with OpenTelemetry, on by default: with a global tracer provider each request also gets ananthropic.messages.createspan and atraceparentheader.AnthropicConfighad no way to configure or turn that off, so the only switch was theANTHROPIC_OPEN_TELEMETRYenvironment variable.This adds
open_telemetry: OpenTelemetryClientOption = NonetoAnthropicConfig(and itscopy()overrides) and passes it to the SDK client created bycreate()and bycreate_files_client().Nonekeeps the current behaviour (the SDK reads its env vars);Falsedisables the SDK's spans; a dict such as{"traces": {"content_mode": "content"}}configures them. The option type has been exported byanthropicsince before the>=1.15.0floor inpyproject.toml(checked against 1.15.0 and 2.3.0).The telemetry guide gets a short "Anthropic SDK spans" note describing the extra span and the opt-out.
Related issue number
Closes #3490
Checks
Local:
pytest test/config/anthropic→ 289 passed, 1 skipped, 1 xfailed (anthropic 2.3.0). New tests check the default, the pass-through ofNone/False/ a dict to both SDK clients, andcopy(open_telemetry=...). I also confirmed on a real client thatopen_telemetry=Falseresolves totraces.enabled = False.ruff check/ruff format --checkclean.AI assistance
AI assistance was used to draft the change; I reviewed the diff and ran the tests above.