Skip to content

opentelemetry-api: make SeverityNumber an IntEnum - #5930

Open
herin049 wants to merge 4 commits into
open-telemetry:mainfrom
herin049:feat/severity-int-enum
Open

herin049 wants to merge 4 commits into
open-telemetry:mainfrom
herin049:feat/severity-int-enum

Conversation

@herin049

@herin049 herin049 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Description

Changes SeverityNumber from enum.Enum to enum.IntEnum before opentelemetry.logs is stabilized.

Resolves #5785

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • I am a human and not a bot
  • I have run tox -e precommit
  • I have run tox -e typecheck
  • I have run the relevant tests and linting tox environments
  • This requires the following PR in contrib:

@herin049
herin049 requested a review from a team as a code owner November 12, 2026 17:55
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-11-15 07:18 UTC

Respond to 1 review item (e.g. link a commit, explain why not, ask a follow-up):

  • Inline threads: 1
Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

Copilot AI 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.

🟢 Approval recommended

No active review issues are recorded for the change enabling direct numeric comparisons of severity values.

No open issues 🎉

What changed in this PR

Changes SeverityNumber to IntEnum before the logs API is stabilized, enabling direct numeric comparisons and addressing #5785.

Changes:

  • Switches SeverityNumber from enum.Enum to enum.IntEnum.
  • Adds tests for integer compatibility, severity ordering, and enum construction.
  • Documents the breaking change in the changelog.
File Description
opentelemetry-api/​tests/​logs/​test_severity.py Tests integer equality, ordering, and enum identity.
opentelemetry-api/​src/​opentelemetry/​_logs/​severity/​__init__.py Makes SeverityNumber inherit from IntEnum.
.changelog/​5930.changed Announces the breaking change and direct comparison support.

Review effort: Balanced

@github-project-automation github-project-automation Bot moved this to Approved PRs in Python PR digest Nov 12, 2026


class SeverityNumber(enum.Enum):
class SeverityNumber(enum.IntEnum):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we also update test_benchmark_logs_enabled.py:39 and the OTLP encoders to compare directly without .value and getattr (and ensure #5724 uses direct comparison in Logger.enabled())? It would be great to run test_benchmark_logs_enabled before and after to verify the speedup.

Comment thread .changelog/5930.changed Resolved
@aabmass aabmass mentioned this pull request Nov 12, 2026
4 of 6 tasks
@herin049

Copy link
Copy Markdown
Contributor Author

@aabmass

Per Claude:

Benchmark: test_benchmark_logs_enabled

Before: main (SeverityNumber(enum.Enum), processor compares severity_number.value >= min.value)
After: this PR (SeverityNumber(enum.IntEnum), processor compares severity_number >= min)
CPython 3.13, macOS arm64, uv run tox -e benchmark-opentelemetry-sdk -- -k test_benchmark_logs_enabled

Only the processor_filter and enabled-guard-overhead groups call LogRecordProcessor.enabled(), so only they run the severity comparison:

Test Median before (µs) Median after (µs) Δ
test_disabled_emit[processor_filter-kwargs-guarded] 0.225 0.135 -40.1%
test_disabled_emit[processor_filter-log_record-guarded] 0.225 0.135 -40.1%
test_disabled_emit[processor_filter-kwargs-unguarded] 0.392 0.301 -23.2%
test_disabled_emit[processor_filter-log_record-unguarded] 0.717 0.612 -14.5%
test_enabled_emit[guarded] 2.834 2.625 -7.4%
test_enabled_emit[unguarded] 2.584 2.500 -3.3%

@herin049
herin049 requested a review from aabmass November 15, 2026 07:17

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress
Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

Consider making SeverityNumber an IntEnum

5 participants