opentelemetry-cpp icon indicating copy to clipboard operation
opentelemetry-cpp copied to clipboard

[API] Support for Logger::Enabled() is incomplete

Open marcalff opened this issue 1 year ago • 7 comments

  nostd::shared_ptr<opentelemetry::logs::Logger> logger = ...;

  if (logger->Enabled(severity)) {
  }

Logger::Enabled() always return false.

This is due to:

  inline bool Enabled(Severity severity) const noexcept
  {
    return static_cast<uint8_t>(severity) >= OPENTELEMETRY_ATOMIC_READ_8(&minimum_severity_);
  }

  mutable uint8_t minimum_severity_{kMaxSeverity};

The severity is kMaxSeverity by default, meaning all events are disabled by default.

There is a method to change the logger severity:

  void SetMinimumSeverity(uint8_t severity_or_max) noexcept
  {
    OPENTELEMETRY_ATOMIC_WRITE_8(&minimum_severity_, severity_or_max);
  }

but is it protected, and never called in the code base.

Any user code that checks for Enabled() can not emit logs.

Note that EmitLogRecord() helpers never honor the Enabled() flag either.

marcalff avatar May 14 '24 10:05 marcalff

To revisit once spec is merged:

  • https://github.com/open-telemetry/opentelemetry-specification/pull/4020

marcalff avatar May 14 '24 19:05 marcalff

Spec is now merged.

Adding a Enabled() method in the API is an ABI breaking change, to implement in ABI_VERSION_2 only.

marcalff avatar May 28 '24 16:05 marcalff

See related:

  • https://github.com/open-telemetry/opentelemetry-specification/pull/4063

marcalff avatar May 30 '24 20:05 marcalff

This issue was marked as stale due to lack of activity.

github-actions[bot] avatar Aug 01 '24 01:08 github-actions[bot]

This issue is available for anyone to work on. Make sure to reference this issue in your pull request. :sparkles: Thank you for your contribution! :sparkles:

github-actions[bot] avatar Feb 18 '25 15:02 github-actions[bot]

Since there have been no takers for this, I can take up this issue.

psx95 avatar Apr 16 '25 16:04 psx95