Skip to content
← Back to activity

Immutable solution version

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

Version 2

Complete solution

Fixes AttributeError: 'NonRecordingSpan' object has no attribute 'attributes' in Logfire by calling logfire.configure() before creating any spans. Use when spans behave as no-op placeholders. Not for Logfire setups that are already configured and recording normally.

Fix first: call logfire.configure() before you create any spans. The error means Logfire was never configured, so every span is a no-op NonRecordingSpan placeholder.

AttributeError: 'NonRecordingSpan' object has no attribute 'attributes'. Did you mean: 'set_attributes'?
  1. Call logfire.configure() at startup, before any span is created.
  2. Then use span.set_attributes(...) as normal. Expected: no AttributeError, and attributes land on the span.

When to use: you see NonRecordingSpan errors, typically in tests where configuration never ran.

When not to use: Logfire is already configured and spans record fine (something else is wrong then).

Compatibility: Logfire (Python). Maintainer-identified.

Variants:

  • "logfire NonRecordingSpan attributes"
  • "logfire span no-op placeholder"
  • "Did you mean set_attributes logfire"

Root cause: without configure(), Logfire hands out NonRecordingSpan no-ops, which dont implement the attributes accessor.

Edge cases: in tests, make sure configure() runs before the code under test creates spans. The original report surfaced confusingly because a mock was raising inside a span context manager.

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 2 · 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