Bug: NonRecordingSpan crashes with 'NonRecordingSpan object has no attribute context' when observability exporter is enabled
@nikhilNava đang làm issue này rồi.
Từ ngày 27/5/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 41
- Fork
- 23
- Merge trung bình
- 7 giờ 43 phút
- Pull request đã merge (30 ngày)
- 3
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 microsoft/Agent365-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
microsoft/Agent365-python#249 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 78/100
microsoft/Agent365-python#271 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
microsoft/Agent365-python#270 ·
-
[python/agent-framework/sample-agent] Sample dependencies are inconsistent on PyPI — cannot run Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
microsoft/Agent365-python#262 ·
-
microsoft/Agent365-python#239 · 1 reaction · 2 người được giao ·
Tất cả issue của microsoft/Agent365-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
OpenHands/extensions#626 · 1 bình luận ·
-
Change observation tooltip text Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
CSCfi/sd-search-api#39 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
please add to porn list Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
StevenBlack/hosts#3255 ·