Skip to content

[opentelemetry-instrumentation-genai-anthropic] Capture reasoning token counts on messages - #779

Merged
lmolkova merged 7 commits into
open-telemetry:mainfrom
rads-1996:capture-reasoning-tokens-anthropic
Oct 1, 2026
Merged

lmolkova merged 7 commits into
open-telemetry:mainfrom
rads-1996:capture-reasoning-tokens-anthropic

Conversation

@rads-1996

Copy link
Copy Markdown
Contributor

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How has this been tested?

Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. List any relevant details for your test
configuration.

  • uv run tox -e py312-test-instrumentation-genai-anthropic-- -q
  • uv run tox -e py312-test-instrumentation-genai-anthropic-conformance -- -q
  • uv run --python 3.12 tox -e lint-instrumentation-genai-anthropic

Checklist

See CONTRIBUTING.md
for the style guide, changelog guidance, and more.

  • Followed the style guidelines of this project
  • Changelog updated if the change requires an entry
  • Unit tests added
  • Documentation updated

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-10-01 17:09 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@rads-1996
rads-1996 force-pushed the capture-reasoning-tokens-anthropic branch from ac1036f to f0e392f Compare September 23, 2026 18:42
@rads-1996
rads-1996 marked this pull request as ready for review September 23, 2026 20:09
@rads-1996
rads-1996 requested a review from a team as a code owner September 23, 2026 20:09
Copilot AI lite review requested due to automatic review settings September 23, 2026 20:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

One or more issues must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds Anthropic reasoning-token telemetry using gen_ai.usage.reasoning.output_tokens.

Changes:

  • Extracts thinking_tokens from response usage.
  • Adds sync/async assertions and updated VCR fixtures.
  • Adds a changelog entry.
File Description
instrumentation/​opentelemetry-instrumentation-genai-anthropic/​tests/​test_sync_messages.py Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-genai-anthropic/​tests/​test_messages_extractors.py Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-genai-anthropic/​tests/​test_async_messages.py Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-genai-anthropic/​tests/​cassettes/​test_sync_messages_create_captures_thinking_content.yaml Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-genai-anthropic/​tests/​cassettes/​test_async_messages_create_captures_thinking_content.yaml Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-genai-anthropic/​src/​opentelemetry/​instrumentation/​genai/​anthropic/​messages_extractors.py Updated as part of this pull request.
instrumentation/​opentelemetry-instrumentation-genai-anthropic/​.changelog/​779.added Updated as part of this pull request.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified that would block approval.

Review effort: Lite
Findings: None

Resolved since last review (1)

@rads-1996
rads-1996 force-pushed the capture-reasoning-tokens-anthropic branch 2 times, most recently from ba188bc to 4c1850c Compare September 24, 2026 16:29

@eternalcuriouslearner eternalcuriouslearner left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!! Should we add the attributes to conformance test suite?

@rads-1996

Copy link
Copy Markdown
Contributor Author

LGTM!! Should we add the attributes to conformance test suite?

So, this PR already verifies that the attribute is correctly emitted in the test_async_wrappers and test_sync_wrappers proving that the integration tests work correctly, I don't see an additional value in adding the attribute to the conformace test suite, moreover other instrumentations like openai and langchain also do not add this attribute in their conformance test suite. WDYT?

@rads-1996
rads-1996 force-pushed the capture-reasoning-tokens-anthropic branch from de30969 to 6ce633b Compare September 29, 2026 21:17
@rads-1996
rads-1996 requested a review from aabmass September 29, 2026 21:55
@lmolkova
lmolkova added this pull request to the merge queue Oct 1, 2026
Merged via the queue into open-telemetry:main with commit 4af6aed Oct 1, 2026
77 checks passed
@rads-1996
rads-1996 deleted the capture-reasoning-tokens-anthropic branch October 1, 2026 17:09
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.

6 participants