Skip to content

fix: apply filtering EmitLogRecord#4079

Open
proost wants to merge 38 commits into
open-telemetry:mainfrom
proost:fix-apply-filtering-emitlogrecord
Open

fix: apply filtering EmitLogRecord#4079
proost wants to merge 38 commits into
open-telemetry:mainfrom
proost:fix-apply-filtering-emitlogrecord

Conversation

@proost
Copy link
Copy Markdown
Contributor

@proost proost commented May 12, 2026

Fixes #2667

Changes

prev: #4011

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

A huge gap exists between API/SDK spec and C++ client for EmitLogRecord method.

  1. missing context parameter
  2. missing exception parameter
  3. support severity filtering in the "SDK".
  4. We currently handle ObservedTimestamp and Timestamp using same type. Spec tells both optional parameter how to divide which one is ObservedTimestamp and other one is Timestamp?

1 is easy, although ABI level breaking change is inevitable.
2 is quite confusing to me. Is just another attributes or std::exception? When i read data-model spec, It feels like one of attributes.
3 needs decision. Because In SDK level interface, we use "LogRecord" type. But we can't extract severity from "LogRecord" easily. Or do we have to overload "EmitLogRecord" with severity?
4 needs a design.

So i change very narrower code. Filtering in the severity filtering in the API level and trace based filtering in the sdk level.

  • 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 May 12, 2026 11:57
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 92.02899% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.08%. Comparing base (689612a) to head (f5e8558).

Files with missing lines Patch % Lines
sdk/src/logs/logger.cc 86.28% 7 Missing ⚠️
api/include/opentelemetry/logs/logger.h 94.29% 2 Missing ⚠️
...pi/include/opentelemetry/logs/logger_type_traits.h 95.24% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4079      +/-   ##
==========================================
+ Coverage   82.01%   82.08%   +0.07%     
==========================================
  Files         385      386       +1     
  Lines       16030    16131     +101     
==========================================
+ Hits        13145    13239      +94     
- Misses       2885     2892       +7     
Files with missing lines Coverage Δ
api/include/opentelemetry/logs/noop.h 47.37% <ø> (-26.31%) ⬇️
...pentelemetry/sdk/logs/batch_log_record_processor.h 100.00% <100.00%> (ø)
sdk/include/opentelemetry/sdk/logs/processor.h 100.00% <100.00%> (ø)
...entelemetry/sdk/logs/simple_log_record_processor.h 100.00% <100.00%> (ø)
sdk/src/logs/multi_log_record_processor.cc 93.68% <100.00%> (+0.43%) ⬆️
api/include/opentelemetry/logs/logger.h 81.12% <94.29%> (+12.26%) ⬆️
...pi/include/opentelemetry/logs/logger_type_traits.h 97.62% <95.24%> (-2.38%) ⬇️
sdk/src/logs/logger.cc 89.72% <86.28%> (+0.31%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@proost proost changed the title Fix apply filtering emitlogrecord fix: apply filtering EmitLogRecord May 12, 2026
Copy link
Copy Markdown
Member

@dbarker dbarker left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. We definitely need some discussion here (thanks for starting it) on how to align with the spec. As you noted there are a few gaps in how the full Context is handled and Enabled is checked when creating and emitting a log record. Generally it seems there should be a path to explicitly provide the full Context and avoid any implicit calls to get the current context from RuntimeContext.

Comment thread api/include/opentelemetry/logs/logger.h
Comment thread sdk/src/logs/logger.cc Outdated
Comment thread sdk/src/logs/logger.cc Outdated
@dbarker dbarker added the discuss To discuss in SIG meeting label May 12, 2026
@proost proost requested a review from dbarker May 14, 2026 08:24
Copy link
Copy Markdown
Member

@owent owent left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.

Comment thread api/include/opentelemetry/logs/logger.h Outdated
{
const EventId *event_id_ptr = detail::FindEventIdInArgs(args...);
#if OPENTELEMETRY_ABI_VERSION_NO >= 2
const bool is_enabled =
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.

Can we avoid making every enabled log call pay for the full Enabled(...) chain? The disabled and below-min-severity paths stay cheap, but the normal enabled path now pays virtual/context/processor cost before record creation. It may be better to cache whether full filtering is actually needed, and only call the full chain when trace-based filtering or processor-level filtering is configured.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thx, 5e67680

how about go through trace based filtering using current option?

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.

Thanks, this helps with the trace-based case, but I think the original concern is only partially addressed. We still need the cache to account for processor-level filtering too, otherwise the normal non-trace-based path can skip processor Enabled(...) checks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, now i understand your intention.
dc306d5

Later, i will add logger configuration.. this option might be needed in the configuration. But this is not in the spec. is ok?

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.

I would not add a new logger configuration option just for this. The spec defines the observable Enabled behavior, but the C++ SDK can still implement it efficiently.

For performance, I think this should stay as an internal cache/capability decision: full filtering is needed when trace_based is enabled or when a processor actually implements Enabled filtering. Otherwise the normal enabled path should avoid paying the full virtual/context/processor chain.

One thing to watch is that the cache must stay correct if processors are added after a logger is created.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, I integrate Context And SpanContext both allowed. 8a18dc7

@proost proost requested a review from lalitb May 15, 2026 07:02
Comment thread sdk/src/logs/logger.cc Outdated
Comment thread api/test/logs/logger_test.cc
@proost proost requested a review from dbarker May 17, 2026 13:59
Comment thread api/include/opentelemetry/logs/logger.h Outdated
@proost proost requested a review from lalitb May 20, 2026 08:35
Copy link
Copy Markdown
Member

@dbarker dbarker left a comment

Choose a reason for hiding this comment

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

Thanks for the updates. This is looking good. Please see a few minor points below.

Comment thread api/include/opentelemetry/logs/logger.h Outdated
Comment thread api/include/opentelemetry/logs/logger.h
Comment thread sdk/test/logs/logger_sdk_test.cc
@proost proost requested a review from dbarker May 27, 2026 16:26
// Logger subclass apply richer filtering (trace-based, processor-level
// Enabled, custom predicates).
//
mutable uint8_t extended_enabled_required_{0};
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.

This is an ABI breaking change. Please guard the new member on ABI v2 along with locations where used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

956f820

Sorry to miss that. you are right. It should be gated.

@proost proost requested review from dbarker May 29, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

discuss To discuss in SIG meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

6 participants