Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log4j and Logback appenders opt-in to using GlobalOpenTelemetry #8791

Merged
merged 5 commits into from
Jun 29, 2023

Conversation

jack-berg
Copy link
Member

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) the GlobalOpenTelemetry.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 use GlobalOpenTelemetry 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 using GlobalOpenTelemetry. Despite the fact that using GlobalOpenTelemetry is more aligned with the log configuration tendency to use purely XML based configuration, I still think it makes sense for us to not use GlobalOpenTelemetry 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.

@trask trask enabled auto-merge (squash) June 29, 2023 19:19
@trask trask merged commit d20da99 into open-telemetry:main Jun 29, 2023
45 checks passed
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.

Application does not start with the OTel Spring Boot starter + OTel Logback appender, from 1.27.0 version
5 participants