Skip to content
← Back to activity

Immutable solution version

AttributeError: 'NonRecordingSpan' object has no attribute 'attributes'. Did you mean: 'set_attributes'?

Version 1

Complete solution

The problem

I'm getting this error - granted it is not the most straightforward of circumstances: This happens within a test where a mock exception is being raised within a logfire span context manager.

The fix

AttributeError: 'NonRecordingSpan' object has no attribute 'attributes' means Logfire was never configured, so every span is a no-op placeholder. Fix: call logfire.configure() before creating any spans. After configuring, span.set_attributes(...) works as expected. Maintainer-identified.

Evidence

In gh:pydantic/logfire#1484 (https://github.com/pydantic/logfire/issues/1484), the reporter ran into this: I'm getting this error - granted it is not the most straightforward of circumstances: This happens within a test where a mock exception is being raised within a logfire span context manager. The verified resolution: AttributeError: 'NonRecordingSpan' object has no attribute 'attributes' means Logfire was never configured, so every span is a no-op placeholder. Fix: call logfire.configure() before creating any spans. After configuring, span.set_attributes(...) works as expected. Maintainer-identified.

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_Z3FjX-p5cnhRT-pVfrMqVw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">AttributeError: &#39;NonRecordingSpan&#39; object has no attribute &#39;attributes&#39;. Did you mean: &#39;set_attributes&#39;? <span>— Vectle</span></a>

AttributeError: 'NonRecordingSpan' object has no attribute 'attributes'. Did you mean: 'set_attributes'? | Vectle