Skip to content

Detect SDK handler in install_log_bridge#97

Merged
chris-colinsky merged 1 commit into
mainfrom
fix/log-bridge-sdk-handler-collision
May 29, 2026
Merged

Detect SDK handler in install_log_bridge#97
chris-colinsky merged 1 commit into
mainfrom
fix/log-bridge-sdk-handler-collision

Conversation

@chris-colinsky

Copy link
Copy Markdown
Member

Summary

  • install_log_bridge's idempotency check only recognized opentelemetry.instrumentation.logging.handler.LoggingHandler (what OA itself installs). If an application already attached opentelemetry.sdk._logs.LoggingHandler against the same LoggerProvider in its own logging setup, OA's bridge added a second OTel-Logs handler and every log record shipped to OTLP twice. Console handlers are independent so the duplication was OTLP-only — slow to diagnose.
  • Widen the check to detect either OTel-Logs handler class wired to the same provider; skip addHandler accordingly. The openarmature.correlation_id LogRecord factory still installs unconditionally. Provider-scoped: applications running a separate logs pipeline against a DIFFERENT LoggerProvider still get OA's bridge attached against the OA provider.
  • Document the collision shape in docs/agent/non-obvious-shapes.md and regenerate the bundled AGENTS.md.

Test plan

  • New unit test: SDK handler pre-attached against the same provider → OA skips its own addHandler, factory still installs.
  • New unit test: pre-attached handler against a DIFFERENT provider → OA does attach (no false-positive dedup).
  • Existing idempotency test still passes (instrumentation-handler marker path).
  • uv run pyright clean.
  • uv run pytest tests/unit/test_observability_otel.py -q green.

The install_log_bridge idempotency check only recognized the
instrumentation LoggingHandler (the class OA itself installs).
Applications that attached opentelemetry.sdk._logs.LoggingHandler
against the same LoggerProvider in their own logging setup got a
SECOND OTel-Logs handler from OA's bridge, doubling every record
through the OTLP export path. Console handlers are independent so
the duplication is OTLP-only, which made it slow to diagnose.

Widen the check to detect either OTel-Logs handler class wired to
the same provider. The correlation_id LogRecord factory still
installs regardless. Provider-scoped so applications running a
separate logs pipeline against a DIFFERENT LoggerProvider still
get OA's bridge attached against the OA provider.

Document the collision shape in docs/agent/non-obvious-shapes.md
and regenerate the bundled AGENTS.md.

Reported via downstream integration.
Copilot AI review requested due to automatic review settings May 29, 2026 23:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes a duplicate-OTLP-export bug where install_log_bridge only recognized the instrumentation LoggingHandler class and would attach a second OTel-Logs handler against the same LoggerProvider when an application had already attached the SDK LoggingHandler.

Changes:

  • Add _otel_logs_handler_already_bridges helper that detects either OTel LoggingHandler class (SDK or instrumentation) wired to the same provider and skips the duplicate addHandler.
  • Add two unit tests covering same-provider skip and different-provider attach.
  • Document the collision in docs/agent/non-obvious-shapes.md and regenerate src/openarmature/AGENTS.md.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/openarmature/observability/otel/logs.py Widens idempotency check to cover both OTel-Logs handler classes against the same provider.
tests/unit/test_observability_otel.py Adds two tests: SDK-handler same-provider skip, SDK-handler different-provider attach.
docs/agent/non-obvious-shapes.md Documents the dual-LoggingHandler collision and helper's provider-scoped dedup behavior.
src/openarmature/AGENTS.md Regenerated bundle reflecting the new non-obvious shape entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@chris-colinsky chris-colinsky merged commit 03dd599 into main May 29, 2026
7 checks passed
@chris-colinsky chris-colinsky deleted the fix/log-bridge-sdk-handler-collision branch May 29, 2026 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants