Skip to content

Make SpanLevel compare equal to 'warning' - #2732

Merged
alexmojaki merged 1 commit into
pydantic:mainfrom
Fahmid-Arman:fix/span-level-warning-equality
Nov 6, 2026
Merged

alexmojaki merged 1 commit into
pydantic:mainfrom
Fahmid-Arman:fix/span-level-warning-equality

Conversation

@Fahmid-Arman

@Fahmid-Arman Fahmid-Arman commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

SpanLevel.__eq__ compared a string by level name, and NUMBER_TO_LEVEL[13] is 'warn'. So a level 13 span was equal to 'warn' but not to 'warning', although 'warning' is a valid LevelName for the same level and <, <=, > and >= already accept it:

level = SpanLevel(LEVEL_NUMBERS['warning'])
level >= 'warning'  # True
level == 'warning'  # before: False, after: True

The ExceptionCallback docs set helper.level = 'warning', after which helper.level == 'warning' was False; the same applied to span_info.level == 'warning' in a tail sampling callback. A string is now compared by its level number, like the ordering operators, and an unknown name is still unequal to every level.

Tests: test_span_levels in tests/test_tail_sampling.py now checks == 'warning' and != 'warning'. It fails on main and passes with the change. tests/test_tail_sampling.py and tests/test_exceptions.py pass (289), and ruff and pyright are clean.

View guided diff

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

View guided diff | Re-trigger cubic

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  logfire-sdk/logfire
  types.py
Project Total  

This report was generated by python-coverage-comment-action

@alexmojaki
alexmojaki added this pull request to the merge queue Nov 6, 2026
Merged via the queue into pydantic:main with commit d2b0110 Nov 6, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants