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

don't fail spring application startup if sdk is disabled #10602

Merged
merged 5 commits into from
Feb 22, 2024

Conversation

zeitlinger
Copy link
Member

Fixes #10600

@zeitlinger zeitlinger requested a review from a team as a code owner February 19, 2024 14:17
@zeitlinger zeitlinger self-assigned this Feb 19, 2024
@zeitlinger
Copy link
Member Author

@laurit here's the fix 😄

Copy link
Member

@jeanbisutti jeanbisutti left a comment

Choose a reason for hiding this comment

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

@jeanbisutti
Copy link
Member

LogbackAppenderApplicationListener should also be disabled if otel.sdk.disabled=true:

io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.logging.LogbackAppenderApplicationListener

I have created #10612 to do this.

@@ -19,6 +19,10 @@ private ExporterConfigEvaluator() {}
public static boolean isExporterEnabled(
Environment environment, String exportersKey, String wantExporter, boolean defaultValue) {

if (environment.getProperty("otel.sdk.disabled", Boolean.class, false)) {
Copy link
Member

Choose a reason for hiding this comment

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

I would add a comment, something like this: the method is used to enable some Spring autoconfigurations

Copy link
Member

Choose a reason for hiding this comment

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

putting this condition on each exporter's @Configuration could make it more visible and consistent (where we just throw the @SdkEnabled condition on everything)

Copy link
Member Author

Choose a reason for hiding this comment

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

great idea - done 😄

Copy link
Member

Choose a reason for hiding this comment

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

putting this condition on each exporter's @Configuration could make it more visible and consistent (where we just throw the @SdkEnabled condition on everything)

Should it not be another property configuration allowing to disable the export?

By setting otel.sdk.disabled=true, I understand disable the OpenTelemtry SDK, and so disable the instrumentation features and the export.

Copy link
Member Author

Choose a reason for hiding this comment

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

putting this condition on each exporter's @Configuration could make it more visible and consistent (where we just throw the @SdkEnabled condition on everything)

Should it not be another property configuration allowing to disable the export?

you still have otel.traces.exporter=none (similar for logs and metrics)

By setting otel.sdk.disabled=true, I understand disable the OpenTelemtry SDK, and so disable the instrumentation features and the export.

yes, otel.sdk.disabled=true disables everything at once.

@jeanbisutti
Copy link
Member

OpenTelemetryAutoConfiguration is already disabled if otel.sdk.disabled=true. An alternative implementation could be to autoconfigure the other autoconfigurations after OpenTelemetryAutoConfiguration. In this way, if OpenTelemetryAutoConfiguration is disabled, the other ones won't be enabled. This implementation woud require less code and avoid several otel.sdk.disabled property verifications.

@jeanbisutti
Copy link
Member

jeanbisutti commented Feb 21, 2024

OpenTelemetryAutoConfiguration is already disabled if otel.sdk.disabled=true. An alternative implementation could be to autoconfigure the other autoconfigurations after OpenTelemetryAutoConfiguration. In this way, if OpenTelemetryAutoConfiguration is disabled, the other ones won't be enabled. This implementation woud require less code and avoid several otel.sdk.disabled property verifications.

I am also fine with the current implementation if you think it is more explicit

@zeitlinger
Copy link
Member Author

OpenTelemetryAutoConfiguration is already disabled if otel.sdk.disabled=true. An alternative implementation could be to autoconfigure the other autoconfigurations after OpenTelemetryAutoConfiguration. In this way, if OpenTelemetryAutoConfiguration is disabled, the other ones won't be enabled. This implementation woud require less code and avoid several otel.sdk.disabled property verifications.

I am also fine with the current implementation if you think it is more explicit

this wouldn't work, because the exporter beans are required to create the OpenTelemetry instance in OpenTelemetryAutoConfiguration

@Configuration
public class InstrumentationAnnotationsAutoConfiguration {

static final class Condition extends AllNestedConditions {
Copy link
Contributor

@laurit laurit Feb 21, 2024

Choose a reason for hiding this comment

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

Just curious why you implemented it this way. Would having

@ConditionalOnProperty(name = "otel.instrumentation.annotations.enabled", matchIfMissing = true)
@Conditional(SdkEnabled.class)

where SdkEnabled is shared by all auto configuration classes also work? If it would work this way I'd guess it needs a lot less code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting idea! I hadn't considered that - I'll try.

Copy link
Member Author

Choose a reason for hiding this comment

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

worked!

@laurit laurit merged commit 4ed5ade into open-telemetry:main Feb 22, 2024
47 checks passed
@zeitlinger zeitlinger deleted the spring-starter-disabled branch March 12, 2024 09:11
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.

Disabling OTEL SDK causes autoconfiguration to fail due to missing ConfigProperties
4 participants