-
Notifications
You must be signed in to change notification settings - Fork 871
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
Ability to disable the automatic Logback appender addition #10629
Ability to disable the automatic Logback appender addition #10629
Conversation
addOpenTelemetryAppender(applicationEnvironmentPreparedEvent); | ||
} | ||
} | ||
} | ||
|
||
private static boolean isLogbackAppenderAddable( |
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.
why not use @Conditional(SdkEnabled.class)
here instead?
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.
The application listener is executed very early at the application startup. @Conditional(SdkEnabled.class)
can't work. The property has to be retrieved from an application event.
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.
Could you add the underlying @ConditionalOnProperty
to the configuration?
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.
why not use
@Conditional(SdkEnabled.class)
here instead?
I did not read your question correctly . The link you gave is related to application listeners allowing to inject an OpenTelemetry instance into the OpenTelemetry appenders. This PR has a different goal. It aims to be able to disable the automatic addition of the Logback OpenTelemetry appender. You have already added @Conditional(SdkEnabled.class)
to the autoconfiguration creating the listeners allowing the injection of the OpenTelemetry instance into the OpenTelemetry appenders in #10602:
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.
Right - next try: check for sdk disabled at the start of the method to make it very clear:
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ApplicationEnvironmentPreparedEvent // Event for which
// org.springframework.boot.context.logging.LoggingApplicationListener
// initializes logging
) {
ApplicationEnvironmentPreparedEvent applicationEnvironmentPreparedEvent =
(ApplicationEnvironmentPreparedEvent) event;
Boolean otelSdkDisableProperty =
evaluateBooleanProperty(applicationEnvironmentPreparedEvent, "otel.sdk.disabled");
if (otelSdkDisableProperty != null && otelSdkDisableProperty) {
return;
}
Optional<OpenTelemetryAppender> existingOpenTelemetryAppender = findOpenTelemetryAppender();
if (existingOpenTelemetryAppender.isPresent()) {
reInitializeOpenTelemetryAppender(
existingOpenTelemetryAppender, applicationEnvironmentPreparedEvent);
} else if (isLogbackAppenderAddable(applicationEnvironmentPreparedEvent)) {
addOpenTelemetryAppender(applicationEnvironmentPreparedEvent);
}
}
}
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.
Right - next try: check for sdk disabled at the start of the method to make it very clear:
public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ApplicationEnvironmentPreparedEvent // Event for which // org.springframework.boot.context.logging.LoggingApplicationListener // initializes logging ) { ApplicationEnvironmentPreparedEvent applicationEnvironmentPreparedEvent = (ApplicationEnvironmentPreparedEvent) event; Boolean otelSdkDisableProperty = evaluateBooleanProperty(applicationEnvironmentPreparedEvent, "otel.sdk.disabled"); if (otelSdkDisableProperty != null && otelSdkDisableProperty) { return; } Optional<OpenTelemetryAppender> existingOpenTelemetryAppender = findOpenTelemetryAppender(); if (existingOpenTelemetryAppender.isPresent()) { reInitializeOpenTelemetryAppender( existingOpenTelemetryAppender, applicationEnvironmentPreparedEvent); } else if (isLogbackAppenderAddable(applicationEnvironmentPreparedEvent)) { addOpenTelemetryAppender(applicationEnvironmentPreparedEvent); } } }
It would remove the ability to reconfigure an OpenTelemetry Logback appender defined in an XML file from system properties.
Imagine a user having configured the capture of code attributes from an OTel Logback appender in an XML file. The user has packaged his application and is using it in production. The capture of code attributes is expensive and can cause performance penalty. It would not be possible to disable the capture of log attributes without repacking the application and redeliver it in production.
private static boolean isLogbackAppenderAddable( | ||
ApplicationEnvironmentPreparedEvent applicationEnvironmentPreparedEvent) { | ||
Boolean otelSdkDisableProperty = | ||
evaluateBooleanProperty(applicationEnvironmentPreparedEvent, "otel.sdk.disabled"); |
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.
Perhaps it would make sense to add a variant of evaluateBooleanProperty
that returns boolean
and accepts the default value as an argument.
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.
For me it seems a little early to add this method today because (if I understand correctly):
- The method would be called at only two places
- The default value as an argument would be true in both cases
Can this one be merged? |
No description provided.