[AI Projects] AIProjectInstrumentor: non-streamed responses.create raises AttributeError ('NonRecordingSpan' object has no attribute 'attributes') when the span is not sampled
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
从 azure/ai/projects/telemetry/_responses_instrumentor.py 中的 _append_to_message_attribute 开始,将其对 span 的处理与 _set_span_attribute_safe 和流式包装器进行比较。使用 OpenTelemetry ALWAYS_OFF 采样器和非流式 responses.create 调用复现问题。完成标准是:成功收到响应后,未记录的 span 不再引发异常,且响应仍可正常工作。
由索引模型根据 Issue 内容生成。
描述
Package: azure-ai-projects 2.10.0. Also seen on 2.9.0, and the helper is unchanged on main as of 2026-11-05.
Also installed: openai 3.35.1 to 3.46.0, opentelemetry-sdk 1.40.0, azure-core-tracing-opentelemetry 1.0.0b13, Python 3.12.
What happens
With AIProjectInstrumentor enabled, a non-streamed responses.create raises whenever the current span is not recording, for example when a sampler drops the trace:
AttributeError: 'NonRecordingSpan' object has no attribute 'attributes'
It raises after the service has answered with HTTP 200, so the caller loses a completed and billed response. Streamed calls are not affected.
Cause
In azure/ai/projects/telemetry/_responses_instrumentor.py (line 681 in 2.10.0), _append_to_message_attribute reads span.span_instance.attributes without checking span.span_instance.is_recording(). OpenTelemetry's NonRecordingSpan has no attributes. The neighbouring helpers, such as _set_span_attribute_safe and the stream wrappers, already guard with is_recording().
_responses_instrumentor.py:4777 inner -> self.trace_responses_create(...)
_responses_instrumentor.py:2248 trace_responses_create -> self._add_message_event(...)
_responses_instrumentor.py:765 _add_message_event -> self._append_to_message_attribute(...)
_responses_instrumentor.py:681 _append_to_message_attribute
existing_value = span.span_instance.attributes.get(attribute_name) if span.span_instance.attributes else None
AttributeError: 'NonRecordingSpan' object has no attribute 'attributes'
Repro (no network)
pip install azure-ai-projects==2.10.0 opentelemetry-sdk==1.40.0 azure-core-tracing-opentelemetry==1.0.0b13
import os
import httpx2
import openai
from azure.ai.projects.telemetry import AIProjectInstrumentor
from azure.core.settings import settings
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.sampling import ALWAYS_OFF
# Every span non-recording, as when a sampler drops the trace.
trace.set_tracer_provider(TracerProvider(sampler=ALWAYS_OFF))
settings.tracing_implementation = "opentelemetry"
os.environ["AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING"] = "true"
AIProjectInstrumentor().instrument()
RESPONSE = {
"id": "resp_1", "object": "response", "created_at": 0, "status": "completed", "model": "m",
"output": [{"type": "message", "id": "msg_1", "status": "completed", "role": "assistant",
"content": [{"type": "output_text", "text": "done", "annotations": []}]}],
"parallel_tool_calls": True, "tool_choice": "auto", "tools": [],
}
calls = []
def handler(request):
calls.append(request.url)
return httpx2.Response(200, json=RESPONSE)
client = openai.OpenAI(api_key="test", base_url="https://example.invalid/v1",
http_client=httpx2.Client(transport=httpx2.MockTransport(handler)))
try:
client.responses.create(input="hi")
print("no error")
except AttributeError as exc:
print(f"HTTP calls: {len(calls)}; then: AttributeError: {exc}")
Output:
HTTP calls: 1; then: AttributeError: 'NonRecordingSpan' object has no attribute 'attributes'
Why it matters in practice
When OTEL_TRACES_SAMPLER is unset, azure-monitor-opentelemetry 1.8.8 defaults to a rate-limited sampler at 5 traces/s. In an ordinary App Insights setup, some of these spans are therefore not recording, and production calls fail intermittently after the model has already run.
Expected
Telemetry should never change the outcome of the call. When the span is not recording, skip the attribute aggregation, as the other helpers already do.
Workaround
Leave AIProjectInstrumentor off (AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING unset), or stream the call.
- 主要语言
- Python
- 星标
- 5.6k
- 派生
- 3.4k
- 平均合并
- 2 天 19 小时
- 30 天内合并 PR
- 183
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Azure/azure-sdk-for-python 的其他 Issue
-
azure-eventhub migration guide: legacy checkpoint sample writes "None" metadata for partitions that were never checkpointed可能已有人在做 @hidingmyname 于 7 天前认领。 未关闭Client customer-reported Event Hubs needs-team-attention question Service Attention
难度 2/5 1-3 小时 新手友好度 78/100
Azure/azure-sdk-for-python#49723 · 2 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
Scheduled test pipelines fail at the Analyze_Test stage due to date formatting可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭EngSys
难度 2/5 1-3 小时 新手友好度 78/100
Azure/azure-sdk-for-python#49614 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
[Teams Chatbot]: Clarify Python dev-feed publication from a branch versus PyPI release可能已有人在做 @jianingwang123 于 22 天前认领。 未关闭customer-reported question
难度 2/5 1-3 小时 新手友好度 62/100
Azure/azure-sdk-for-python#49548 · 1 条评论 · 2 个 reaction · 已指派 2 人 ·
维护者通常 1 天内回复
-
azure-ai-evaluation: a content-harm score of 0 (no harm) is parsed as NaN in _parse_content_harm_response (numeric branch uses 0 < x instead of 0 <= x)可能已有人在做 @pujitha24 于 38 天前认领。 未关闭Evaluation Service Attention
难度 2/5 1-3 小时 新手友好度 84/100
Azure/azure-sdk-for-python#49190 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 90/100
Azure/azure-sdk-for-python#49183 · 1 个 reaction ·
维护者通常 1 天内回复
查看 Azure/azure-sdk-for-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 66/100
cline/mcp-marketplace#3576 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
griptape-ai/griptape-nodes-library-elevenlabs#30 ·
维护者通常 1 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 76/100
awslabs/social-messaging-agent-runtime-toolkit#140 ·
维护者通常 1 天内回复
-
subtask
难度 2/5 1-3 小时 新手友好度 72/100
fga-eps-mds/2026.2-MeasureSoftGram-DOC#187 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
NSPG13/agent-bounties#1747 ·
维护者通常 1 天内回复