Detect SDK handler in install_log_bridge#97
Merged
Conversation
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.
There was a problem hiding this comment.
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_bridgeshelper that detects either OTelLoggingHandlerclass (SDK or instrumentation) wired to the same provider and skips the duplicateaddHandler. - Add two unit tests covering same-provider skip and different-provider attach.
- Document the collision in
docs/agent/non-obvious-shapes.mdand regeneratesrc/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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
install_log_bridge's idempotency check only recognizedopentelemetry.instrumentation.logging.handler.LoggingHandler(what OA itself installs). If an application already attachedopentelemetry.sdk._logs.LoggingHandleragainst the sameLoggerProviderin 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.addHandleraccordingly. Theopenarmature.correlation_idLogRecord factory still installs unconditionally. Provider-scoped: applications running a separate logs pipeline against a DIFFERENTLoggerProviderstill get OA's bridge attached against the OA provider.docs/agent/non-obvious-shapes.mdand regenerate the bundledAGENTS.md.Test plan
uv run pyrightclean.uv run pytest tests/unit/test_observability_otel.py -qgreen.