Skip to content

Suppress duplicate warning log for same application logger factory class#19088

Open
bhuvan-somisetty wants to merge 3 commits into
open-telemetry:mainfrom
bhuvan-somisetty:fix/application-logging-warning
Open

Suppress duplicate warning log for same application logger factory class#19088
bhuvan-somisetty wants to merge 3 commits into
open-telemetry:mainfrom
bhuvan-somisetty:fix/application-logging-warning

Conversation

@bhuvan-somisetty

@bhuvan-somisetty bhuvan-somisetty commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #14889

Problem

When running a Spring Boot app with -Dotel.javaagent.logging=application, the following warning appears spuriously at startup:

WARN - ApplicationLoggerBridge - Multiple application logger implementations were provided. \
The javaagent will use the first bridge provided and ignore the following ones (this one).

Spring Boot's LoggingApplicationListener calls initialize() more than once during startup (e.g. for ApplicationEnvironmentPreparedEvent and ApplicationStartedEvent). The javaagent instruments this method on exit, so Slf4jApplicationLoggerBridge.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 installed gate and a separate volatile actualFactoryClass field with a single AtomicReference<Class<? extends InternalLogger.Factory>>. The CAS is now null → 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 assign actualFactoryClass.

Behaviour:

  • Same class re-install → return silently; bridge is already correctly set up.
  • Different class → log the existing warning; this is a genuine conflict.

Changes

  • ApplicationLoggerFactory.java replace AtomicBoolean + volatile field with AtomicReference<Class<...>> and CAS null → incomingClass
  • ApplicationLoggerFactoryTest.java add shouldIgnoreSubsequentInstallationsOfSameClass test; update shouldOnlyInstallTheFirstBridge to use distinct FirstFactory/SecondFactory classes so the warning is still triggered for genuinely different implementations

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>
Copilot AI review requested due to automatic review settings June 26, 2026 18:44
@bhuvan-somisetty bhuvan-somisetty requested a review from a team as a code owner June 26, 2026 18:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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/SecondFactory mock 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.
@opentelemetry-pr-dashboard

Copy link
Copy Markdown

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.

@laurit laurit added this to the v2.30.0 milestone Jun 30, 2026
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.

otel.javaagent.logging=application causes warning log

3 participants