Skip to content

Consider making SeverityNumber an IntEnum #5785

Open

Description

@aabmass

Before stabilizing opentelemetry.logs, we should consider changing SeverityNumber from enum.Enum to enum.IntEnum:

  1. Ergonomics: It allows comparing enum values directly (e.g. severity_number < SeverityNumber.INFO in enabled() checks) without having to do .value on both sides. The type is already called SeverityNumber, so it's confusing that it isn't an IntEnum / comparable as a number.
  2. Performance: This came up while benchmarking the logging hot path for bottlenecks. On enum.Enum, .value is a descriptor lookup in Python, so comparing a.value >= b.value takes ~380 ns vs ~97 ns for a >= b with IntEnum (~4x faster). It also avoids getattr(record.severity_number, "value", None) in the OTLP encoder.
  3. Timing: IntEnum still supports .value and .name, but changing Enum to IntEnum after 1.0 would change isinstance(sev, int) and sev == 9 from False to True, so it's best to do before stabilizing opentelemetry.logs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions