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

Initialize appenders in the spring boot starter #8888

Merged
merged 4 commits into from
Jul 11, 2023

Conversation

mateuszrzeszutek
Copy link
Member

By coincidence I've started working on the same thing as @jeanbisutti in #8887

Still no tests though, I've been hoping to utilize the gradle test suites for that

@jeanbisutti
Copy link
Member

@mateuszrzeszutek You could continue from your PR? I can help in the review for example.

@mateuszrzeszutek
Copy link
Member Author

@mateuszrzeszutek You could continue from your PR? I can help in the review for example.

Sure! That'd be very helpful, thanks.

I'll just add more tests to make sure it works, and I think this should be ready for review.

@jeanbisutti
Copy link
Member

@mateuszrzeszutek You could continue from your PR? I can help in the review for example.

Sure! That'd be very helpful, thanks.

I'll just add more tests to make sure it works, and I think this should be ready for review.

It would be interesting to have JVM + Spring native tests for this type of use case: OTel starter + logging instrumentation libraries. Related issues: #8773, #8776

}

@Bean
@ConditionalOnProperty(
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The 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 true. I added it to make it possible to disable the appender auto configuration.

Copy link
Member

Choose a reason for hiding this comment

The 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.

@@ -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());
Copy link
Member

Choose a reason for hiding this comment

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

An OpenTelemtry instance is built twice: on line 145 and just after

@trask trask added this to the v1.28.0 milestone Jul 6, 2023
@mateuszrzeszutek mateuszrzeszutek marked this pull request as ready for review July 7, 2023 07:49
@mateuszrzeszutek mateuszrzeszutek requested a review from a team July 7, 2023 07:49
Comment on lines +44 to +47
compileOnly(project(":instrumentation:log4j:log4j-appender-2.17:library"))
compileOnly("org.apache.logging.log4j:log4j-core:2.17.0")
compileOnly(project(":instrumentation:logback:logback-appender-1.0:library"))
compileOnly("ch.qos.logback:logback-classic:1.0.0")
Copy link
Member

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?

Copy link
Member

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

Copy link
Member

@zeitlinger zeitlinger left a comment

Choose a reason for hiding this comment

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

I tested a similar feature by creating a new module that includes log4j but excludes logback: https://github.com/grafana/grafana-opentelemetry-starter/tree/main/integrationTests/log4j

ApplicationListener<ApplicationReadyEvent> log4jOtelAppenderInitializer(
OpenTelemetry openTelemetry) {
return event -> {
io.opentelemetry.instrumentation.log4j.appender.v2_17.OpenTelemetryAppender.install(
Copy link
Member

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 adding the otel appender if it doesn't exist? One thing less for the user to do.

Here's how I did it: https://github.com/grafana/grafana-opentelemetry-starter/blob/main/src/main/java/com/grafana/opentelemetry/Log4jConfig.java

Copy link
Member

Choose a reason for hiding this comment

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

It would be great. We would have to provide a way to customize the OTel automatically added. Today, users can do this with an XML configuration in their Spring Boot projects. It could be done for example by providing a Spring bean of the OTel appender automatically added. The user could then customize this bean with a Spring post-processor.
The automatic addition of the OTel appenders could perhaps be discussed in an issue and not be implemented in this PR?

Copy link
Member

Choose a reason for hiding this comment

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

We would have to provide a way to customize the OTel automatically added

Users can still add the appender (using XML) if they want to have some special settings.
My proposal is to add the appender only if no otel appender is found.

separate issue

sure, I don't mind 😄

Copy link
Member

Choose a reason for hiding this comment

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

I have created an issue for tracking and discussions: #8920

@laurit
Copy link
Contributor

laurit commented Jul 11, 2023

Considering that @mateuszrzeszutek is unavailable until Thursday can we merge this as is?

@mateuszrzeszutek
Copy link
Member Author

I tested a similar feature by creating a new module that includes log4j but excludes logback: https://github.com/grafana/grafana-opentelemetry-starter/tree/main/integrationTests/log4j

I tried to do that in this PR as well -- but since testing-common introduces extra logback + slf4j bridges I gave up on it.

1 similar comment
@mateuszrzeszutek
Copy link
Member Author

I tested a similar feature by creating a new module that includes log4j but excludes logback: https://github.com/grafana/grafana-opentelemetry-starter/tree/main/integrationTests/log4j

I tried to do that in this PR as well -- but since testing-common introduces extra logback + slf4j bridges I gave up on it.

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.

5 participants