microsoft / microsoft/Agent365-python

Bug: NonRecordingSpan crashes with 'NonRecordingSpan object has no attribute context' when observability exporter is enabled

オープン
#257 コメント 2 件 リアクション 0 件 担当者 1 名 GitHub で見る

@nikhilNava がすでに取り組んでいます。

2026年5月27日 から。

主要言語
Python
スター
41
フォーク
23
平均マージ
7時間 43分
マージ済み PR(30日)
3

説明

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

  1. Deploy a Python agent with ENABLE_A365_OBSERVABILITY_EXPORTER=true
  2. Ensure the token resolver returns None on the first turn (e.g., agentic auth token not yet cached)
  3. Send the first message via Teams @mention
  4. 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-api version: 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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。