-
Notifications
You must be signed in to change notification settings - Fork 873
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
Initialize appenders in the spring boot starter #8888
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
|
||
package io.opentelemetry.instrumentation.spring.autoconfigure; | ||
|
||
import io.opentelemetry.api.GlobalOpenTelemetry; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.api.trace.TracerProvider; | ||
import io.opentelemetry.context.propagation.ContextPropagators; | ||
|
@@ -141,9 +140,6 @@ public OpenTelemetry openTelemetry( | |
|
||
ContextPropagators propagators = propagatorsProvider.getIfAvailable(ContextPropagators::noop); | ||
|
||
// global is needed for logging appenders | ||
GlobalOpenTelemetry.set(OpenTelemetrySdk.builder().setLoggerProvider(loggerProvider).build()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An OpenTelemtry instance is built twice: on line 145 and just after |
||
|
||
return OpenTelemetrySdk.builder() | ||
.setTracerProvider(tracerProvider) | ||
.setMeterProvider(meterProvider) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.autoconfigure.logging; | ||
|
||
import io.opentelemetry.api.OpenTelemetry; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.event.ApplicationPreparedEvent; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@SuppressWarnings("OtelPrivateConstructorForUtilityClass") | ||
@ConditionalOnBean(OpenTelemetry.class) | ||
public class OpenTelemetryAppenderAutoConfiguration { | ||
mateuszrzeszutek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Bean | ||
@ConditionalOnProperty( | ||
prefix = "otel.springboot.log4j-appender", | ||
name = "enabled", | ||
matchIfMissing = true) | ||
@ConditionalOnClass({ | ||
io.opentelemetry.instrumentation.log4j.appender.v2_17.OpenTelemetryAppender.class | ||
}) | ||
ApplicationListener<ApplicationPreparedEvent> log4jOtelAppenderInitializer( | ||
OpenTelemetry openTelemetry) { | ||
return event -> { | ||
io.opentelemetry.instrumentation.log4j.appender.v2_17.OpenTelemetryAppender.install( | ||
openTelemetry); | ||
}; | ||
} | ||
|
||
@Bean | ||
@ConditionalOnProperty( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not to enable the OpenTelemetry injection by default? Check on line 44 is not sufficient? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is enabled by default; in case the property is absent it still gets evaluated to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I was not rather explicit. My point is that I don't see the use case for which the user would like to disable the automatic injection of the OpenTelemetry instance into the OTel appender. I would prefer to remove the property if we don't have a use case in mind. |
||
prefix = "otel.springboot.logback-appender", | ||
name = "enabled", | ||
matchIfMissing = true) | ||
@ConditionalOnClass({ | ||
io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender.class | ||
}) | ||
ApplicationListener<ApplicationPreparedEvent> logbackOtelAppenderInitializer( | ||
OpenTelemetry openTelemetry) { | ||
return event -> { | ||
io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender.install( | ||
openTelemetry); | ||
}; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about pulling in the appender instrumentation by default, similar to the other library instrumentations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created #8925 to track/discuss further, will merge this PR as is for the upcoming 1.28.0 release