Skip to content

Python: Avoid duplicate log export when root logger already has an OTel handler - #9897

Open
Dineshsuriya D (droideronline) wants to merge 1 commit into
microsoft:mainfrom
droideronline:fix/otel-logging-handler-duplicate
Open

Dineshsuriya D (droideronline) wants to merge 1 commit into
microsoft:mainfrom
droideronline:fix/otel-logging-handler-duplicate

Conversation

@droideronline

Copy link
Copy Markdown
Contributor

Motivation & Context

configure_otel_providers attaches an OTel LoggingHandler to the agent_framework logger. When an application also has an OTel LoggingHandler on the root logger (for example to export its own, httpx and azure logs), agent_framework records propagate to root and are exported twice. The adjacent comment also said "root logger" while the code attaches to agent_framework.

Description & Review Guide

  • What are the major changes? In _configure_providers, skip adding the handler when the root logger already has an OTel LoggingHandler, and fix the comment. Added a test covering both the root-handler-present and absent cases.
  • What is the impact of these changes? Records are exported once when the app attaches its root handler before calling configure_otel_providers. Behavior is unchanged when there is no root OTel handler.
  • What do you want reviewers to focus on? The check only sees a root handler that exists at configure time; an app that adds one afterwards still gets duplicates. It also does not compare logger providers, so a root handler bound to a different provider would suppress MAF's own handler.

Related Issue

Fixes #9896

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: issue analysis, implementation, tests, and this description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

…el handler

configure_otel_providers attaches a LoggingHandler to the agent_framework logger. If the application already has an OTel LoggingHandler on the root logger, agent_framework records propagate to it and were exported twice. Skip adding the handler in that case and correct the comment to name the logger it attaches to.

This branch was previously deployed

1 inactive deployment
github-app-auth — 2a3684ad Deployed Oct 30, 2026 by droideronline via team_check #8172
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: configure_otel_providers duplicates log export when the app has a root OTel LoggingHandler

1 participant