🐛 Bug Report: Anthropic: after uninstrument(), a client that used with_raw_response / with_streaming_response stays traced through them
维护者通常 1 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 半天
- 新手友好度
- 62/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
Start with the reproduction script in the issue: it instruments, uses the plain, with_raw_response and with_streaming_response accessors on one client, then uninstruments and counts spans. The cause is that the SDK's cached accessor keeps a bound reference to the instrumented create, which AnthropicInstrumentor().uninstrument() does not reset. Done when all three lines print 0 spans, including for AsyncAnthropic.
由索引模型根据 Issue 内容生成。
描述
Which component is this bug for?
Anthropic Instrumentation
📜 Description
After AnthropicInstrumentor().uninstrument(), calls made through client.messages.with_raw_response or client.messages.with_streaming_response are still traced, if that client used the accessor while the instrumentation was active. Plain client.messages.create(...) on the same client is correctly no longer traced, and a new client is fine.
The Anthropic SDK caches these accessor objects on the client (cached_property), and the cached wrapper keeps a reference to the instrumented create it was built from. uninstrument() restores the class method, but not the bound method inside the cached accessor, so those calls keep going through the instrumentation. The same happens with AsyncAnthropic.
(Unlike #4552 for OpenAI, where uninstrument() does nothing at all, the Anthropic instrumentation does uninstrument plain calls; only the cached accessors stay instrumented.)
👟 Reproduction steps
pip install anthropic opentelemetry-instrumentation-anthropic opentelemetry-sdk
import anthropic
from importlib.metadata import version
from anthropic._base_client import httpx2 as httpx # anthropic 1.x uses httpx2
from opentelemetry.sdk.trace import SpanProcessor, TracerProvider
from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor
class Count(SpanProcessor):
n = 0
def on_end(self, span): Count.n += 1
provider = TracerProvider(); provider.add_span_processor(Count())
def respond(request): # local stand-in for the Anthropic API
return httpx.Response(200, json={"id": "msg_1", "type": "message", "role": "assistant", "model": "claude-x",
"content": [{"type": "text", "text": "Hello"}], "stop_reason": "end_turn",
"usage": {"input_tokens": 3, "output_tokens": 1}})
KW = dict(model="claude-x", max_tokens=10, messages=[{"role": "user", "content": "hi"}])
print(f"opentelemetry-instrumentation-anthropic {version('opentelemetry-instrumentation-anthropic')} | anthropic {version('anthropic')}")
for accessor in ("plain", "with_raw_response", "with_streaming_response"):
AnthropicInstrumentor().instrument(tracer_provider=provider)
client = anthropic.Anthropic(api_key="x", http_client=httpx.Client(transport=httpx.MockTransport(respond)))
def call():
if accessor == "plain":
client.messages.create(**KW)
elif accessor == "with_raw_response":
client.messages.with_raw_response.create(**KW)
else:
with client.messages.with_streaming_response.create(**KW) as r:
r.parse()
call() # used while instrumented
AnthropicInstrumentor().uninstrument()
Count.n = 0
call() # the same client, after uninstrument()
print(f"{accessor:24s} spans after uninstrument(): {Count.n}")
👍 Expected behavior
After uninstrument(), no call is traced, whichever accessor it goes through: 0 spans in all three lines.
👎 Actual Behavior with Screenshots
opentelemetry-instrumentation-anthropic 0.62.4 | anthropic 1.13.0
plain spans after uninstrument(): 0
with_raw_response spans after uninstrument(): 1
with_streaming_response spans after uninstrument(): 1
🤖 Python Version
3.12
📃 Provide any additional context for the Bug.
opentelemetry-instrumentation-anthropic 0.62.4 (the latest release); anthropic 1.13.0 and 1.11.0. The same happens for AsyncAnthropic. Related: #4552 (OpenAI, uninstrument() a no-op).
👀 Have you spent some time to check if this bug has been raised before?
- I checked and didn't find similar issue
Are you willing to submit PR?
None
- 主要语言
- Python
- 星标
- 7.5k
- 派生
- 1.2k
- 平均合并
- 1 天 23 小时
- 30 天内合并 PR
- 3
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
traceloop/openllmetry 的其他 Issue
-
🐛 Bug Report: OpenAI Responses: with_raw_response.create() raises when the body can't be parsed, though the uninstrumented call returns可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug python
难度 2/5 1-3 小时 新手友好度 76/100
traceloop/openllmetry#4717 ·
维护者通常 1 天内回复
-
🐛 Bug Report: Incomplete cache token migration after #4243 breaks Bedrock and Groq instrumentation可能已有人在做 @Quantum-Enigma-dot 于 21 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
traceloop/openllmetry#4665 · 1 条评论 ·
维护者通常 1 天内回复
-
🐛 Bug Report: OpenAI instrumentation drops gen_ai.usage.reasoning_tokens on streamed chat completions可能已有人在做 @jayfeng7 于 23 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
traceloop/openllmetry#4660 · 1 条评论 ·
维护者通常 1 天内回复
-
Bug Report: Failed dataset deletes still remove local rows and columns可能已有人在做 @inchang-ing 于 32 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
traceloop/openllmetry#4630 ·
维护者通常 1 天内回复
-
🐛 Bug Report: LiteLLM instrumentation does not record seed, stop, frequency_penalty, presence_penalty可能已有人在做 @shantam77 于 39 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
traceloop/openllmetry#4598 · 2 条评论 ·
维护者通常 1 天内回复
查看 traceloop/openllmetry 的全部 Issue
相似的 Issue
-
ready-for-agent
难度 1/5 1-3 小时 新手友好度 79/100
gregwebs/agent-vm-images#216 ·
维护者通常 1 天内回复
-
Layout accepts a step threshold of 0 or less, then in-toto-verify crashes with StopIteration可能已有人在做 @BahaaMattar 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 2/5 1-3 小时 新手友好度 72/100
gcivil-nyu-org/team5-mon-fall26#145 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
gcivil-nyu-org/team3-mon-fall26#156 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
antlr/grammars-v4#5220 ·
维护者通常 1 天内回复