Log4j and Logback appenders opt-in to using GlobalOpenTelemetry #8791
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.
Resolves #8773. Related to comment in #8637.
This adjusts the Log4j and Logback appenders to make the dependency on
GlobalOpenTelemetry.get()
opt-in. As discussed in the 6/22 Java SIG (and elsewhere) theGlobalOpenTelemetry.get()
dependency is problematic because once you call get, you cannot later call set. Since log config happens so early in the app lifecycle, the only practical way to useGlobalOpenTelemetry
is by opting into the autoconfigure side affect via-Dotel.java.global-autoconfigure.enabled=true
.The
GlobalOpenTelemetry.get()
dependency also is not aligned with our general advice against usingGlobalOpenTelemetry
. Despite the fact that usingGlobalOpenTelemetry
is more aligned with the log configuration tendency to use purely XML based configuration, I still think it makes sense for us to not useGlobalOpenTelemetry
by default so that our advice can remain consistent.Some degree of programatic configuration is present in virtually all of our library instrumentation. Though at first glance it feels a bit strange to add a programatic step, I think folks will get over it quickly given the symmetry to setup of other instrumentation (e.g. runtime metrics).
This PR also adjusts the log appender README files to contain instructions on one way of how to perform programatic configuration. There are many variations possible (especially with log4j), including versions which do not include any OpenTelemetry modifications to log4j2.xml / logback.xml.
In a followup PR, we should consider extending the appenders with a cache to store startup logs recorded before
setOpenTelemetry
is called.