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

Ability to disable the automatic Logback appender addition #10629

Merged

Conversation

jeanbisutti
Copy link
Member

No description provided.

@jeanbisutti jeanbisutti requested a review from a team February 21, 2024 20:15
addOpenTelemetryAppender(applicationEnvironmentPreparedEvent);
}
}
}

private static boolean isLogbackAppenderAddable(
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 use @Conditional(SdkEnabled.class) here instead?

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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:

Copy link
Member

@zeitlinger zeitlinger Feb 22, 2024

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);
      }
    }
  }

Copy link
Member Author

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");
Copy link
Contributor

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.

Copy link
Member Author

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

@jeanbisutti
Copy link
Member Author

Can this one be merged?

@laurit laurit merged commit edf64c5 into open-telemetry:main Feb 26, 2024
47 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.

3 participants