Repository navigation
Conversation
Pull request dashboard statusWaiting on the author · refreshed 2026-10-16 02:30 UTC Two things need attention:
Status above doesn't look right?
|
There was a problem hiding this comment.
🟡 Changes recommended
Early filtering can silently drop wrapped records when their instrumentation scope differs from the logger’s scope.
1 open finding
What changed in this PR
Supports logs stabilization by expanding benchmarks and reducing disabled-logger overhead in the SDK.
Changes:
- Checks processor enablement before constructing log records.
- Adds disabled-logger and emission benchmarks.
- Updates filtering tests and preserves log metric accounting.
| File | Description |
|---|---|
opentelemetry-sdk/tests/logs/test_sdk_metrics.py |
Tests metric accounting with disabled processors. |
opentelemetry-sdk/tests/logs/test_logs.py |
Updates configuration assertions and tests early filtering. |
opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py |
Adds early processor enablement checks. |
opentelemetry-sdk/benchmarks/logs/test_benchmark_logs.py |
Adds exception, active-span, and emission-style benchmarks. |
opentelemetry-sdk/benchmarks/logs/test_benchmark_logs_enabled.py |
Benchmarks guarded and unguarded logging. |
.changelog/5784.added |
Documents benchmarks and performance improvements. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@aabmass Here are the updated results with info on allocations/GC collections (with kwargs vs log-record style emit):
Looks like none of the logger methods cause a gen-0 GC collection, which is good. I'd imagine we could improve the |
aabmass
left a comment
There was a problem hiding this comment.
Thank you Lukas, the benchmarks look good and that's what I was going for. My AI agreed they make sense and duplicate the results, and made some suggestions based on it. Feel free to ignore them or do later (review comments here)
|
|
||
| def _emit_log_record_unguarded(logger, index): | ||
| logger.emit( | ||
| LogRecord( |
There was a problem hiding this comment.
+1 on LogRecord.__init__ doing too much work eagerly (time_ns(), get_current(), and get_current_span()). Adding __slots__ to LogRecord (and ReadWriteLogRecord / ReadableLogRecord) would also save the extra 216 bytes/call (325 B vs 109 B) from the instance __dict__.
There was a problem hiding this comment.
Thanks, I've added __slots__ to all of these classes and the memory has improved a lot. I've deferred optimizing the LogRecord.__init__ method for now.
|
Filed one issue based on the doing the same benchmarking locally, lmk if it makes sense #5785 |
|
@aabmass Updates results based on a few small optimizations (mostly adding slots):
|
|
I've deferred making some of the calls inside |

Description
As part of the logs stabilization effort, this PR adds SDK logs benchmarks to show whether the API/SDK shape needs to change for performance reasons. In particular, it focuses on the overhead of calling a disabled logger.
The benchmarks showed that
Logger.emitonly checked the logger config and never checked the processor'senabled()result. Thus, an unguardedemitstill built the fullReadWriteLogRecordbefore dropping it. This PR fixes that as well.Part of: #3361
Benchmark Results
Benchmark results
Ran with Apple M5 Pro, Python 3.13.11
Disabled logger
logger_config-unguardedlogger_config-guardedprocessor_filter-unguardedprocessor_filter-guardedno_processors-unguardedno_processors-guardedsdk_disabled-unguardedsdk_disabled-guardedapi_proxy_noop-unguardedapi_proxy_noop-guardedThere is still likely room for some improvement here, but I don't think that this will require a change in the shape of the API/SDK. One performance-adjacent feature that we may want to add in the future is the ability to have a log format string that is evaluated lazily (like the Python logger). However, I personally don't think this use-case is very common -- most users still rely on the built-in logging module (with the instrumentation lib) and we still provide
logger.enabled(...)as a fallback.cc: @aabmass
Type of change
Please delete options that are not relevant.
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.
tox -e precommittox -e typecheck