Skip to content

feat(weave): Add Initial Claude Agents SDK OTEL integration#7002

Draft
andrewtruong wants to merge 5 commits into
masterfrom
andrew/claude-agent-sdk-instrumentation-v2
Draft

feat(weave): Add Initial Claude Agents SDK OTEL integration#7002
andrewtruong wants to merge 5 commits into
masterfrom
andrew/claude-agent-sdk-instrumentation-v2

Conversation

@andrewtruong
Copy link
Copy Markdown
Collaborator

@andrewtruong andrewtruong commented May 28, 2026

Initial Claude Agents SDK integration in OTEL

@w-b-hivemind
Copy link
Copy Markdown

w-b-hivemind Bot commented May 28, 2026

HiveMind Sessions

3 sessions · 1h 33m · $4.55

Session Agent Duration Tokens Cost Lines
My name is Ada. What is 2 + 2?
c4d3d3f8-573f-47a3-8566-a1f6b1026b20
claude 1s 12 $0.03 +0 -0
Use a shell command to count the markdown files in
d89ca80d-aeca-4bb7-b89b-d702a8744ee0
claude 7s 148 $0.10 +0 -0
Building Claude Agents SDK Weave Integration
091e51a5-6651-4214-b45a-81523bac3367
claude 1h 33m 479.8K $4.42 +2223 -572
Total 1h 33m 480.0K $4.55 +2223 -572

View all sessions in HiveMind →

Run claude --resume c4d3d3f8-573f-47a3-8566-a1f6b1026b20 to pickup where you left off.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

❌ Patch coverage is 0.89686% with 221 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../integrations/claude_agent_sdk/otel_integration.py 0.00% 216 Missing ⚠️
weave/integrations/patch.py 28.57% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@drtangible drtangible left a comment

Choose a reason for hiding this comment

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

👍 👍 👍

Comment on lines +128 to +129
assert chat_attrs["gen_ai.usage.input_tokens"] == 25
assert chat_attrs["gen_ai.usage.output_tokens"] == 10
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.

Looks like the pi-coding-agent integration sets gen_ai.usage.total_tokens -- though I don't see that attribute in our semconv.py mapping. Should I remove it from there?

Assume some of the other additional attributes set there (https://github.com/wandb/weave/blob/master/sdks/node/src/__tests__/integrations/piCodingAgent.test.ts#L270-L287) aren't relevant or possible to set in this integration's case?

Comment thread weave/integrations/claude_agent_sdk/otel_integration.py Outdated
Comment thread weave/integrations/claude_agent_sdk/otel_integration.py Outdated
Comment on lines +126 to +129
assert chat_attrs["gen_ai.request.model"] == "claude-sonnet-4-6"
assert chat_attrs["gen_ai.conversation.id"] == "s-abc123"
assert chat_attrs["gen_ai.usage.input_tokens"] == 25
assert chat_attrs["gen_ai.usage.output_tokens"] == 10
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.

Separate comment: this might not be very Pythonic, but on the TS side, I'm hoping to lean into more exhaustive assertions as we maintain more integrations. YMMV, but when confirming to a spec, kinda like being able to see the full data picture rather than parsing individual assertions and trying to understand if they cover everything. eg...

    assert chat_attrs == {
      'gen_ai.conversation.id': 's-abc123',
      'gen_ai.operation.name': 'chat',
      'gen_ai.provider.name': 'anthropic',
      'gen_ai.request.model': 'claude-sonnet-4-6',
      'gen_ai.output.messages': '[{"role": "assistant", "parts": [{"type": "text", ''"content": "The answer is 4."}]}]',
      'gen_ai.usage.input_tokens': 25,
      'gen_ai.usage.output_tokens': 10
    }

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, we can do it this way. It can get a little noisy for nested dicts, but for plain dicts this is ok

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.

2 participants