Skip to content

Clean up logs API, SDK, and TestBase utilities before logs stabilization - #5934

Open
DylanRussell wants to merge 6 commits into
open-telemetry:mainfrom
DylanRussell:logs-pre-stabilization-cleanups
Open

DylanRussell wants to merge 6 commits into
open-telemetry:mainfrom
DylanRussell:logs-pre-stabilization-cleanups

Conversation

@DylanRussell

@DylanRussell DylanRussell commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

Make some changes ahead of stabilization:

  1. opentelemetry-api (get_logger, LoggerProvider.get_logger & LogRecord):
    • [BREAKING] Align get_logger with LoggerProvider.get_logger and make optional arguments keyword-only (*): Rename instrumenting_module_name: str and instrumenting_library_version: str = "" to name: str and version: str | None = None, move logger_provider to the end of get_logger, and make optional arguments (version, schema_url, attributes, logger_provider) keyword-only (*) on both get_logger and LoggerProvider.get_logger (matching LogRecord.__init__, Logger.emit, and Logger.enabled). Previously, get_logger(name=...) raised TypeError, and omitting version set InstrumentationScope.version = "" instead of None (missing the LoggerProvider cache).
    • Drop ABC inheritance from LogRecord: LogRecord has no abstract methods and is instantiated directly.
  2. opentelemetry-sdk (ReadableLogRecord & Processors):
    • Include "instrumentation_scope" in ReadableLogRecord.to_json().
    • Call self._executor.shutdown() in ConcurrentMultiLogRecordProcessor.shutdown() after shutting down child processors so the ThreadPoolExecutor is not leaked, and guard post-shutdown calls (on_emit, force_flush, enabled, shutdown).
    • Clear api_log_record.exception = None alongside api_log_record.context = Context() on the shallow-copied LogRecord in BatchLogRecordProcessor.on_emit() so exception __traceback__ frames are not retained in memory while records sit in the batch queue (exception attributes are already extracted during Logger.emit()).
  3. opentelemetry-test-utils (TestBase):
    • Add create_logger_provider, self.logger_provider, self.memory_log_exporter, and get_finished_logs() to TestBase, and reset logging globals in setUp/tearDown alongside traces and metrics.

Requires companion contrib PR: open-telemetry/opentelemetry-python-contrib#5337

@DylanRussell
DylanRussell requested a review from a team as a code owner November 13, 2026 15:31
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-11-13 20:48 UTC

Investigate required status check failures.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

@DylanRussell
DylanRussell force-pushed the logs-pre-stabilization-cleanups branch 2 times, most recently from 7447822 to e34f88a Compare November 13, 2026 15:43
@DylanRussell
DylanRussell force-pushed the logs-pre-stabilization-cleanups branch from e34f88a to ba7a508 Compare November 13, 2026 15:54
@aabmass
aabmass requested a balanced review from Copilot November 13, 2026 16:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Executor shutdown leaves later processor calls submitting to a closed pool and raising RuntimeError, including during Python logging shutdown, so shutdown-state checks synchronized with submissions are needed.

1 open issue
What changed in this PR

Prepares OpenTelemetry Python logging for stabilization by aligning API signatures, improving SDK record handling and cleanup, and extending shared test utilities.

Changes:

  • Aligns get_logger parameters with LoggerProvider.get_logger and removes unnecessary LogRecord inheritance.
  • Updates JSON serialization, executor shutdown, and queued exception-reference cleanup.
  • Adds logging helpers to TestBase, regression tests, and changelog entries.
File Description
tests/​opentelemetry-test-utils/​tests/​test_base.py Tests log capture through TestBase.
tests/​opentelemetry-test-utils/​src/​opentelemetry/​test/​test_base.py Adds logging setup, global resets, and capture helpers.
opentelemetry-sdk/​tests/​logs/​test_multi_log_processor.py Tests executor shutdown.
opentelemetry-sdk/​tests/​logs/​test_log_record.py Tests scope serialization and nullable observed timestamps.
opentelemetry-sdk/​tests/​logs/​test_export.py Tests clearing copied exception references without modifying originals.
opentelemetry-sdk/​src/​opentelemetry/​sdk/​_logs/​_internal/​export/​__init__.py Clears exception references before batch queueing.
opentelemetry-sdk/​src/​opentelemetry/​sdk/​_logs/​_internal/​__init__.py Updates JSON output and closes the concurrent processor’s executor.
opentelemetry-api/​tests/​logs/​test_logger_provider.py Tests logger arguments and defaults.
opentelemetry-api/​src/​opentelemetry/​_logs/​_internal/​__init__.py Aligns logger parameters and simplifies LogRecord inheritance.
.changelog/​5934.fixed Documents SDK fixes and logging test helpers.
.changelog/​5934.changed Documents breaking API changes.

Review effort: Balanced

@github-project-automation github-project-automation Bot moved this to Approved PRs in Python PR digest Nov 13, 2026
@DylanRussell

Copy link
Copy Markdown
Contributor Author

Will need open-telemetry/opentelemetry-python-contrib#5337 to go in first in order to get a passing CI

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

4 participants