Skip to content

fix: Logger.Enabled() #4011

Open
proost wants to merge 20 commits intoopen-telemetry:mainfrom
proost:fix-respect-severity
Open

fix: Logger.Enabled() #4011
proost wants to merge 20 commits intoopen-telemetry:mainfrom
proost:fix-respect-severity

Conversation

@proost
Copy link
Copy Markdown

@proost proost commented Apr 18, 2026

Fixes #2667

Changes

fix to Logger.Enabled() use severity. so it changes to default behavior that enabled all logs to emit.

I fix it as minimal what original issue mentioned. But the issue reported two years ago, spec is changed.

do I need to follow "DEVELOPMENT" status spec?(https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/sdk.md#enabled)

I think adding features to "LoggerConfig" is correct to me(default behavior can be annoyed because all logs enabled). But this is my first time, so I don't know what is rule in this project.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@proost proost requested a review from a team as a code owner April 18, 2026 15:17
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Apr 18, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 18, 2026

Codecov Report

❌ Patch coverage is 85.54217% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.08%. Comparing base (dbf6567) to head (22c01e3).

Files with missing lines Patch % Lines
api/include/opentelemetry/logs/logger.h 64.52% 11 Missing ⚠️
sdk/src/logs/logger.cc 96.30% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4011      +/-   ##
==========================================
+ Coverage   82.06%   82.08%   +0.03%     
==========================================
  Files         385      385              
  Lines       15891    15978      +87     
==========================================
+ Hits        13039    13114      +75     
- Misses       2852     2864      +12     
Files with missing lines Coverage Δ
sdk/include/opentelemetry/sdk/logs/logger_config.h 100.00% <100.00%> (ø)
sdk/include/opentelemetry/sdk/logs/processor.h 100.00% <100.00%> (ø)
sdk/src/logs/logger_config.cc 100.00% <100.00%> (ø)
sdk/src/logs/multi_log_record_processor.cc 93.25% <100.00%> (+0.82%) ⬆️
sdk/src/logs/multi_recordable.cc 90.55% <ø> (ø)
sdk/src/logs/logger.cc 90.79% <96.30%> (+2.79%) ⬆️
api/include/opentelemetry/logs/logger.h 68.84% <64.52%> (+3.97%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@marcalff
Copy link
Copy Markdown
Member

do I need to follow "DEVELOPMENT" status spec?(https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/sdk.md#enabled)

Yes.

The spec in "development" status means some changes are still possible before it reaches a stable state.

SDK like opentelemetry-cpp needs to implement these specs early (so, now), to discover possible issues with the spec, so it can be adjusted if needed before reaching the stable status.

Thanks for the contribution.

Comment thread api/include/opentelemetry/logs/logger.h Outdated
@proost
Copy link
Copy Markdown
Author

proost commented Apr 26, 2026

@marcalff @lalitb
I changed code to follow current api/sdk specs. If community is ok, can I divide fixing "EmitLogRecord" another PR? Because I think current change is meaningful and big enough.

// YAML-NODE: SeverityNumber
enum class SeverityNumber : std::uint8_t
{
unspecified = 0,
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

current code default is trace. if this is intended, I will rollback to current code.

@proost proost requested a review from lalitb April 27, 2026 15:59
@dbarker
Copy link
Copy Markdown
Member

dbarker commented May 1, 2026

@proost Thanks for the PR! Both the LoggerConfig and YAML parsing/building features are very much needed :)

The PR has grown a bit beyond the initial issue. To facilitate review please break out the yaml config parsing to a separate PR as follow up to this one.

@proost proost force-pushed the fix-respect-severity branch from 03e3214 to 22c01e3 Compare May 1, 2026 11:46
@lalitb
Copy link
Copy Markdown
Member

lalitb commented May 1, 2026

@proost - Thanks for fixing the earlier ShouldEmitLogRecord(...) case.

I think the same concern still matters for Enabled(severity) itself. Enabled() is called from application /
instrumentation code as the guard before doing expensive log work, so this is one of the most important hot paths in
the logs API.

For example:

  if (logger->Enabled(Severity::kDebug)) {
    // allocate/build expensive debug log payload
  }

When debug logging is disabled, applications should pay as little as possible here. Previously this was just the
cached minimum-severity check. With the current code, the disabled path can still pay for runtime-context lookup and
virtual dispatch through Logger::EnabledImplementation(...) / LogRecordProcessor::Enabled(...).

Can we preserve the severity-only fast path for Enabled(severity), so disabled logging remains just the cheap
cached check, and only use the context / processor filtering path when that extra filtering is explicitly configured?

@ThomsonTan - Can you have a quick look on this PR too. Thanks.

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.

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

4 participants