Suppress duplicate warning log for same application logger factory class#19088
Suppress duplicate warning log for same application logger factory class#19088bhuvan-somisetty wants to merge 3 commits into
Conversation
In Spring Boot, LoggingApplicationListener can initialize the logging system multiple times. When the Java agent hooks into the initialization, this triggers multiple registration calls of Slf4jApplicationLoggerBridge, causing a warning log that multiple application logger implementations were provided. Track the class of the registered factory and return early if a subsequent registration is for the same factory class. A warning is still logged if a different factory class is provided. Fixes open-telemetry#14889 Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR suppresses a spurious WARN log emitted by the javaagent's application-logger bridge. In Spring Boot apps, LoggingApplicationListener#initialize (and/or the SLF4J LoggerFactory path) can drive multiple registration calls of the same Slf4jApplicationLoggerBridge into ApplicationLoggerFactory. Previously, every install after the first logged "Multiple application logger implementations were provided…", even when the registering factory was the identical class. The change records the class of the first successfully installed factory and short-circuits subsequent installs of the same class without warning, while still warning when a genuinely different factory class is provided. This addresses issue #14889.
Changes:
- Track the installed factory's class (
actualFactoryClass) and return early on repeat installs of the same class instead of logging a warning. - Preserve the existing warning behavior when a different factory class attempts to install after the first.
- Update/add unit tests to distinguish same-class repeated installs (no warning) from different-class installs (warning), using concrete
FirstFactory/SecondFactorymock targets.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
javaagent-internal-logging-application/src/main/java/io/opentelemetry/javaagent/logging/application/ApplicationLoggerFactory.java |
Adds actualFactoryClass field and same-class early-return in install(...) to suppress the duplicate warning. |
javaagent-internal-logging-application/src/test/java/io/opentelemetry/javaagent/logging/application/ApplicationLoggerFactoryTest.java |
Updates the first-bridge test to use distinct factory classes and adds a test asserting same-class re-install logs no warning; introduces FirstFactory/SecondFactory test helpers. |
Replace AtomicBoolean + separate volatile field with a single AtomicReference<Class<?>> so the winning factory class is stored atomically as part of the CAS gate. Any thread that loses the race now always reads a non-null value from installedFactoryClass.get(), closing the narrow window where a same-class re-install could still emit the spurious warning.
|
This PR has review comments. Review suggestions, whether from maintainers or automated reviewers, aren't always correct or required. Please evaluate each comment on its merits, then make sure each thread has a clear outcome. For example, link to the commit if you applied a suggestion, explain why it wasn't applied, or ask a follow-up question. Automation flags a PR for human review once every review thread has a reply or is marked as resolved. Status across open PRs is visible on the pull request dashboard. |
Fixes #14889
Problem
When running a Spring Boot app with
-Dotel.javaagent.logging=application, the following warning appears spuriously at startup:Spring Boot's
LoggingApplicationListenercallsinitialize()more than once during startup (e.g. forApplicationEnvironmentPreparedEventandApplicationStartedEvent). The javaagent instruments this method on exit, soSlf4jApplicationLoggerBridge.install()is invoked each time. On the second call the factory is already set, and the existing code unconditionally logs the warning even though the exact same factory class is being re-registered and nothing went wrong.Fix
Replace the
AtomicBoolean installedgate and a separatevolatile actualFactoryClassfield with a singleAtomicReference<Class<? extends InternalLogger.Factory>>. The CAS is nownull → incomingClass, so the winning factory class is stored atomically at the moment the gate is claimed.Any thread that loses the CAS immediately sees a non-null value from
installedFactoryClass.get(), closing the race window where a same-class re-install could still emit the warning before the previous approach had a chance to assignactualFactoryClass.Behaviour:
Changes
ApplicationLoggerFactory.javareplaceAtomicBoolean+volatilefield withAtomicReference<Class<...>>and CASnull → incomingClassApplicationLoggerFactoryTest.javaaddshouldIgnoreSubsequentInstallationsOfSameClasstest; updateshouldOnlyInstallTheFirstBridgeto use distinctFirstFactory/SecondFactoryclasses so the warning is still triggered for genuinely different implementations