Bug: NonRecordingSpan crashes with 'NonRecordingSpan object has no attribute context' when observability exporter is enabled
@nikhilNava 已经在做这个了。
开始于 2026年5月27日。
评估
这个 Issue 还没有评估数据。
描述
Description
When ENABLE_A365_OBSERVABILITY_EXPORTER=true is set and the token resolver returns None for the first turn (e.g., agentic auth not yet established), the OpenTelemetry TracerProvider returns a NonRecordingSpan instead of a real Span. Multiple locations in the A365 observability code access .context directly on the span object, which does not exist on NonRecordingSpan — only get_span_context() is available.
This causes the agent to crash on the very first scope creation with:
Exception caught : 'NonRecordingSpan' object has no attribute 'context'
Reproduction
- Deploy a Python agent with
ENABLE_A365_OBSERVABILITY_EXPORTER=true - Ensure the token resolver returns
Noneon the first turn (e.g., agentic auth token not yet cached) - Send the first message via Teams @mention
- The agent crashes with the above error
Verified against opentelemetry-api==1.33.1:
from opentelemetry.trace import NonRecordingSpan, SpanContext
s = NonRecordingSpan(SpanContext(0, 0, False))
print(hasattr(s, 'context')) # False
print(hasattr(s, 'get_span_context')) # True
s.context # AttributeError
s.get_span_context() # Works correctly
Affected Files
| File | Lines | Pattern |
|---|---|---|
libraries/microsoft-agents-a365-observability-core/.../opentelemetry_scope.py |
161, 270 | self._span.context.span_id |
libraries/microsoft-agents-a365-observability-core/.../exporters/enriched_span.py |
57 | return self._span.context |
libraries/microsoft-agents-a365-observability-core/.../exporters/agent365_exporter.py |
333 | ctx = sp.context |
Root Cause
The Span interface in opentelemetry-api defines get_span_context() as the public method. The .context attribute is only available on the concrete ReadableSpan / recording span implementations but not on NonRecordingSpan. The A365 code uses .context (the attribute) instead of get_span_context() (the interface method), which works for recording spans but fails for non-recording spans.
Suggested Fix
Replace all span.context attribute accesses with span.get_span_context():
# Before (broken with NonRecordingSpan):
span_id = f"{self._span.context.span_id:016x}" if self._span.context else "unknown"
# After (safe for all span types):
sc = self._span.get_span_context()
span_id = f"{sc.span_id:016x}" if sc else "unknown"
Apply the same pattern to enriched_span.py and agent365_exporter.py.
Workaround
Set ENABLE_A365_OBSERVABILITY_EXPORTER=false and redeploy.
Environment
opentelemetry-apiversion: 1.33.1- Python 3.11+
- Agent deployed to Azure App Service with Teams channel
Related
The same bug exists in microsoft/opentelemetry-distro-python (the upstream distro repo). Tracked there as https://github.com/microsoft/opentelemetry-distro-python/issues/166.
- 主要语言
- Python
- 星标
- 41
- 派生
- 23
- 平均合并
- 7 小时 43 分钟
- 30 天内合并 PR
- 3
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/Agent365-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
microsoft/Agent365-python#249 ·
-
难度 3/5 1-2 天 新手友好度 78/100
microsoft/Agent365-python#271 ·
-
难度 3/5 1-2 天 新手友好度 68/100
microsoft/Agent365-python#270 ·
-
难度 4/5 3-5 天 新手友好度 38/100
microsoft/Agent365-python#262 ·
-
microsoft/Agent365-python#239 · 1 个 reaction · 已指派 2 人 ·
查看 microsoft/Agent365-python 的全部 Issue
相似的 Issue
-
area/auth bug comp/agent P3 platform/discord type/security
难度 2/5 1-3 小时 新手友好度 88/100
NousResearch/hermes-agent#117848 ·
-
难度 2/5 1-3 小时 新手友好度 74/100
bancolombia/sentinel#23 ·
-
test md 未关闭CI
难度 2/5 1-3 小时 新手友好度 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
难度 2/5 1-3 小时 新手友好度 74/100
langchain-ai/deepagents#6450 ·
-
bug client
难度 2/5 1-3 小时 新手友好度 88/100