[AI Projects] AIProjectInstrumentor: non-streamed responses.create raises AttributeError ('NonRecordingSpan' object has no attribute 'attributes') when the span is not sampled
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- observability
Hướng nghiên cứu
Bắt đầu tại azure/ai/projects/telemetry/_responses_instrumentor.py, ở _append_to_message_attribute, rồi so sánh cách xử lý span với _set_span_attribute_safe và các wrapper luồng dữ liệu. Tái hiện lỗi bằng sampler ALWAYS_OFF của OpenTelemetry và một lệnh gọi responses.create không truyền luồng. Hoàn tất khi span không được ghi nhận không còn gây lỗi sau khi phản hồi thành công và phản hồi vẫn hoạt động.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 5.6k
- Fork
- 3.4k
- Merge trung bình
- 2 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 184
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Azure/azure-sdk-for-python
-
azure-eventhub migration guide: legacy checkpoint sample writes "None" metadata for partitions that were never checkpointedCó thể đã có người làm @hidingmyname đã nhận 8 ngày trước. Đang mởClient customer-reported Event Hubs needs-team-attention question Service Attention
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Azure/azure-sdk-for-python#49723 · 2 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Scheduled test pipelines fail at the Analyze_Test stage due to date formattingCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởEngSys
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Azure/azure-sdk-for-python#49614 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Teams Chatbot]: Clarify Python dev-feed publication from a branch versus PyPI releaseCó thể đã có người làm @jianingwang123 đã nhận 23 ngày trước. Đang mởcustomer-reported question
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Azure/azure-sdk-for-python#49548 · 1 bình luận · 2 reaction · 2 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
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)Có thể đã có người làm @pujitha24 đã nhận 39 ngày trước. Đang mởEvaluation Service Attention
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Azure/azure-sdk-for-python#49190 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Update CODEOWNERSĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
Azure/azure-sdk-for-python#49183 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của Azure/azure-sdk-for-python
Issue tương tự
-
bug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
graphql-python/graphql-core#304 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
docs size:S
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
Gathin23/cleanyourtv#3464 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày