Skip to content

feat(anthropic): expose the SDK's open_telemetry option on AnthropicConfig - #3519

Merged
Lancetnik merged 1 commit into
ag2ai:mainfrom
ninglinLiu:feat/anthropic-open-telemetry
Oct 27, 2026
Merged

Lancetnik merged 1 commit into
ag2ai:mainfrom
ninglinLiu:feat/anthropic-open-telemetry

Conversation

@ninglinLiu

Copy link
Copy Markdown
Contributor

Why are these changes needed?

anthropic 1.14+ traces its own API calls with OpenTelemetry, on by default: with a global tracer provider each request also gets an anthropic.messages.create span and a traceparent header. AnthropicConfig had no way to configure or turn that off, so the only switch was the ANTHROPIC_OPEN_TELEMETRY environment variable.

This adds open_telemetry: OpenTelemetryClientOption = None to AnthropicConfig (and its copy() overrides) and passes it to the SDK client created by create() and by create_files_client(). None keeps the current behaviour (the SDK reads its env vars); False disables the SDK's spans; a dict such as {"traces": {"content_mode": "content"}} configures them. The option type has been exported by anthropic since before the >=1.15.0 floor in pyproject.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 of None / False / a dict to both SDK clients, and copy(open_telemetry=...). I also confirmed on a real client that open_telemetry=False resolves to traces.enabled = False. ruff check / ruff format --check clean.

AI assistance

  • I understand the changes in this PR and can explain them in my own words.
  • I have verified that the PR description accurately reflects the actual diff.
  • If AI assistance was used, I reviewed, tested, and validated the generated code/text before submitting.

AI assistance was used to draft the change; I reviewed the diff and ran the tests above.

…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
@ninglinLiu
ninglinLiu requested a review from marklysze as a code owner October 27, 2026 18:21
@github-actions github-actions Bot added area:docs Documentation (website/) area:providers LLM provider clients and mappers (ag2/config) labels Oct 27, 2026
@CLAassistant

CLAassistant commented Oct 27, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@vvlrff

vvlrff commented Oct 27, 2026

Copy link
Copy Markdown
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.

@vvlrff vvlrff added the status:needs-cla Gate: CLA not signed; not reviewed until signed label Oct 27, 2026
@Lancetnik
Lancetnik merged commit 4faabe7 into ag2ai:main Oct 27, 2026
20 of 21 checks passed
@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
ag2/config/anthropic/anthropic_client.py 81.22% <100.00%> (ø)
ag2/config/anthropic/config.py 92.30% <100.00%> (+0.41%) ⬆️
ag2/config/anthropic/files.py 100.00% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

area:docs Documentation (website/) area:providers LLM provider clients and mappers (ag2/config) status:needs-cla Gate: CLA not signed; not reviewed until signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: AnthropicConfig open_telemetry option

4 participants