Closed lmolkova closed 10 months ago
@jeanbisutti could you take a look
As you mentioned, Spring Boot re-initializes the logging system. So, the way to proceed with a programmatic use of the SDK is to install OpenTelemetry
in the OpenTelemetry appender after this re-initialization.
However, with Spring Boot, the OpenTelemetry documentation recommends using the OpenTelemetry Java agent or the OpenTelemetry starter, not a programmatic use of the SDK.
The OpenTelemetry starter automatically injects an OpenTelemetry instance into the OpenTelemetry Logback appender. A PR was created to remove the need to add the OpenTelemetry appender in the Logback xml file. So, with the OpenTelemetry starter having this PR code, the logging instrumentation will be available without configuration for Logback.
The opentelemetry-java-examples/spring-native shows an example with the OpenTelemetry starter.
nice! thank you @jeanbisutti for the detailed response and sharing the example.
Describe the bug
I have the following setup
opentelemetry-logback-appender-1.0
SpringApplication.run
is calledSteps to reproduce
full code: demo.zip
Expected behavior
if I uncomment
OpenTelemetryAppender.install(OTEL)
, things work as expected:Actual behavior
nothing is logged
Javaagent or library instrumentation version
1.34.1
Environment
JDK: 21 OS: windows
Additional context
Spring re-creates log appenders during
SpringApplication.run
callAs a result, this new
OTelAppender
never gets configured with otel instanceI believe it's possible to apply global otel in the constructor or default to it until another instance is provided.
Otherwise, this behavior should at least be documented (ideally as a spring-boot example with proper way to config otel there).