Skip to content

opentelemetry-instrumentation-logging: add optional inject_trace_context argument for injecting trace context attributes#4626

Open
herin049 wants to merge 4 commits into
open-telemetry:mainfrom
herin049:feat/logging-record-factory
Open

opentelemetry-instrumentation-logging: add optional inject_trace_context argument for injecting trace context attributes#4626
herin049 wants to merge 4 commits into
open-telemetry:mainfrom
herin049:feat/logging-record-factory

Conversation

@herin049
Copy link
Copy Markdown
Contributor

Description

This PR updates the opentelemetry-instrumentation-logging library to include an optional inject_trace_context keyword argument which allows for injection of trace context attributes for log records without setting the logging formatter.

Fixes #4595

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

uv run tox -e py314-test-instrumentation-logging

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@herin049 herin049 requested a review from a team as a code owner May 26, 2026 00:03
@herin049 herin049 requested a review from Copilot May 26, 2026 00:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an inject_trace_context option to opentelemetry-instrumentation-logging so trace correlation fields can be injected into LogRecord objects without forcing a logging.basicConfig() call (addressing the regression described in #4595).

Changes:

  • Add inject_trace_context kwarg to enable trace context attribute injection without modifying logging configuration.
  • Update documentation to describe the two modes: injection-only vs injection + basicConfig() formatting.
  • Add unit tests validating trace context injection via the new argument.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/init.py Implements inject_trace_context logic and updates public docs/docstrings.
instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/constants.py Updates rendered module documentation to explain the new injection-only path.
instrumentation/opentelemetry-instrumentation-logging/tests/test_logging.py Adds tests verifying record attributes are injected when inject_trace_context=True.
.changelog/4626.added Adds changelog entry for the new feature.

@github-project-automation github-project-automation Bot moved this to Approved PRs in Python PR digest May 26, 2026
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.

[Regression] provide a way to initialize opentelemetry-instrumentation-logging without calling logging.basicConfig()

3 participants