Skip to content

docs(anthropic): use native Python SDK tracing with one tracing owner - #1081

Open
nik13 wants to merge 2 commits into
mainfrom
docs/anthropic-python-native-tracing
Open

nik13 wants to merge 2 commits into
mainfrom
docs/anthropic-python-native-tracing

Conversation

@nik13

@nik13 nik13 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Make the Anthropic SDK's native OpenTelemetry tracing the Python route, matching the Java guide (#1076), and keep existing AnthropicInstrumentor users on one tracing owner.

  • Python installs anthropic>=1.14.0 and fi-instrumentation-otel only, and passes the register() provider to the client with content_mode: "metadata_only". Changing it to "content" exports prompts and responses; TraceConfig/FI_HIDE_* and the session, user, metadata and tags set with context helpers (using_session, using_attributes) don't apply to the SDK's spans; readers who group traces by session or user are pointed to the instrumentor section.
  • The capture paragraph now distinguishes Python (no content by default) from TypeScript (content by default, hidden with FI_HIDE_*).
  • New "Keep AnthropicInstrumentor in Python" section: create clients with open_telemetry=False on SDK 1.14.0 and later so only the instrumentor records them; earlier SDKs don't accept the option.
  • Notes that native input tokens already include cache reads and writes, and adds troubleshooting for double spans, missing spans and unclosed streams.
  • TypeScript steps, catalog entry and URL are unchanged. Adds a regression check for the Python setup contract.

Every package the page installs is already published. The Python snippets were run as written against a loopback Anthropic stub and a loopback OTLP receiver with released traceAI-anthropic 0.1.12, anthropic 2.3.0 and fi-instrumentation-otel 1.2.2: the native route exports one anthropic.messages.create span to /tracer/v1/traces, and the instrumentor route exports one Messages span. node --test scripts/integrations.test.mjs scripts/new-doc.test.mjs passes (19 tests; the new checks fail on the old page), and the page renders locally with the expected headings and anchor.

Related traceAI change (when the SDK's span and the instrumentor's would reach the same provider, the instrumentor keeps its span and turns the SDK's off for that call): future-agi/traceAI#507. This page does not depend on it; open_telemetry=False stays the recommended setup for instrumentor users on every released version.

🤖 Generated with Claude Code

Python now sends the Anthropic SDK's own OpenTelemetry spans (SDK 1.14.0 and
later) to the register() provider, metadata-only by default, instead of
installing traceAI-anthropic. Existing AnthropicInstrumentor users keep a
section that creates clients with open_telemetry=False so each call is traced
once. TypeScript is unchanged. Adds a regression check for the setup contract.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The native route now says that the session, user, metadata and tags set
with using_session or using_attributes are not on the SDK's spans, and
points readers who group traces by session or user to AnthropicInstrumentor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant