Skip to content

fix(logging): export formatter-added attributes#4764

Open
pmcollins wants to merge 3 commits into
open-telemetry:mainfrom
pmcollins:fix/logging-formatter-attributes
Open

fix(logging): export formatter-added attributes#4764
pmcollins wants to merge 3 commits into
open-telemetry:mainfrom
pmcollins:fix/logging-formatter-attributes

Conversation

@pmcollins

@pmcollins pmcollins commented Jun 30, 2026

Copy link
Copy Markdown
Member

Description

Some logging formatters, such as Celery’s, add fields to the passed-in LogRecord during formatting. OTel’s LoggingHandler currently collects attributes before calling the formatter, so formatter-added fields are omitted from exported logs.

This change collects attributes after formatting the record so that formatter-added fields are exported by OTel Python.

Fixes open-telemetry/opentelemetry-python#4446

Type of change

  • 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 not to work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • tox -e py314-test-instrumentation-logging — 66 tests passed
  • Added test_formatter_added_attributes_are_exported, which verifies an attribute added by Formatter.format() is included in the exported log record
  • Ran a local OTLP/HTTP integration test using Celery's TaskFormatter and verified that task_id and task_name are exported as structured log attributes
  • Ran Ruff check and format validation on the changed source and test files

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

@pmcollins pmcollins marked this pull request as ready for review June 30, 2026 19:00
@pmcollins pmcollins requested a review from a team as a code owner June 30, 2026 19:00
@github-project-automation github-project-automation Bot moved this to Approved PRs in Python PR digest Jul 5, 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.

Extract attributes from stdlib record after formatting the log

3 participants