anthropics / anthropics/claude-agent-sdk-python

OTel log events from bundled CLI have empty trace_id/span_id (upstream: claude-code#63074)

Đang mở
#1,034 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Python
Star
8.1k
Fork
1.3k
Merge trung bình
2 ngày 31 phút
Pull request đã merge (30 ngày)
1

Mô tả

## Summary

When OTel telemetry is enabled on the SDK subprocess (`CLAUDE_CODE_ENABLE_TELEMETRY=1`, `OTEL_LOGS_EXPORTER=otlp`), the bundled CLI emits `claude_code.*` log events (`user_prompt`, `api_request_body`, `tool_decision`, `hook_execution_complete`) with **empty `trace_id`/`span_id`**, while sibling spans (`claude_code.interaction`, `claude_code.tool`, `claude_code.llm_request`) correlate correctly with the parent span via auto-injected `TRACEPARENT`.

This breaks log↔trace correlation for any SDK app that opens a parent OTel span around `query()` — the documented integration pattern. The only usable label on the events is the SDK's auto-generated `session.id`, forcing DB-side joins instead of backend-side trace filtering.

## Root cause (upstream)

Tracked in the CLI repo: anthropics/claude-code#63074. The CLI's OTel logger emits from callbacks that have lost AsyncLocalStorage context, so LogRecords ship with an empty `spanContext`. Spans are unaffected.

## Why file here too

The fix lands in the CLI, but SDK users only receive it through the bundled CLI (`claude_agent_sdk/_cli_version.py` — 0.2.87 bundles 2.1.150). Filing so that:
1. SDK users hitting broken log↔trace correlation can find this from the SDK repo.
2. Once the CLI fix ships, the bundled CLI bump can be tracked here.

## Environment

- `claude-agent-sdk` 0.2.87 (bundled CLI 2.1.150); also reproduced on CLI 2.1.153
- Python 3.14, parent process with active OTel span around `query()`
- Subprocess env: `CLAUDE_CODE_ENABLE_TELEMETRY=1`, `OTEL_LOGS_EXPORTER=otlp`, `OTEL_LOG_USER_PROMPTS=1`, `OTEL_LOG_TOOL_DETAILS=1`

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.