[AI Projects] AIProjectInstrumentor: non-streamed responses.create raises AttributeError ('NonRecordingSpan' object has no attribute 'attributes') when the span is not sampled
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 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 sampler と、ストリーミングを使わない 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日 23時間
- マージ済み PR(30日)
- 184
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Azure/azure-sdk-for-python のほかの issue
-
azure-eventhub migration guide: legacy checkpoint sample writes "None" metadata for partitions that were never checkpointed対応中かも @hidingmyname が 8 日前に担当しました。 オープン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 件 ·
メンテナーはふだん 1 日以内に返信
-
Scheduled test pipelines fail at the Analyze_Test stage due to date formatting対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンEngSys
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Azure/azure-sdk-for-python#49614 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 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 件 · 担当者 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 件 ·
メンテナーはふだん 1 日以内に返信
-
Update CODEOWNERSオープン
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
Azure/azure-sdk-for-python#49183 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
Azure/azure-sdk-for-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
strawberry-graphql/strawberry#4794 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
dataforgoodfr/cetolog#21 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
btclib-org/btclib#2932 ·
メンテナーはふだん 1 日以内に返信
-
metrics priority: medium
難易度 1/5 1〜3時間 初心者へのやさしさ 86/100
LearningCircuit/local-deep-research#8336 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100