Skip to content

Micrometer "enable" annotations property does not cover observed aspect #45601

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,12 +39,15 @@
import org.springframework.boot.actuate.autoconfigure.tracing.MicrometerTracingAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

Expand Down Expand Up @@ -159,6 +162,7 @@ TracingAwareMeterObservationHandler<Observation.Context> tracingAwareMeterObserv

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(Advice.class)
@Conditional(ObservationAnnotationsEnabledCondition.class)
static class ObservedAspectConfiguration {

@Bean
Expand All @@ -169,4 +173,22 @@ ObservedAspect observedAspect(ObservationRegistry observationRegistry) {

}

static final class ObservationAnnotationsEnabledCondition extends AnyNestedCondition {

ObservationAnnotationsEnabledCondition() {
super(ConfigurationPhase.PARSE_CONFIGURATION);
}

@ConditionalOnProperty(prefix = "micrometer.observations.annotations", name = "enabled", havingValue = "true")
static class MicrometerObservationsEnabledCondition {

}

@ConditionalOnProperty(prefix = "management.observations.annotations", name = "enabled", havingValue = "true")
static class ManagementObservationsEnabledCondition {

}

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -66,11 +66,13 @@
class ObservationAutoConfigurationTests {

private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().with(MetricsRun.simple())
.withPropertyValues("management.observations.annotations.enabled=true")
.withClassLoader(new FilteredClassLoader("io.micrometer.tracing"))
.withConfiguration(AutoConfigurations.of(ObservationAutoConfiguration.class));

private final ApplicationContextRunner tracingContextRunner = new ApplicationContextRunner()
.with(MetricsRun.simple())
.withPropertyValues("management.observations.annotations.enabled=true")
.withUserConfiguration(TracerConfiguration.class)
.withConfiguration(AutoConfigurations.of(ObservationAutoConfiguration.class));

Expand Down Expand Up @@ -141,6 +143,7 @@ void supplyMeterHandlerAndGroupingWhenMicrometerCoreAndTracingAreOnClassPath() {
@Test
void supplyMeterHandlerAndGroupingWhenMicrometerCoreAndTracingAreOnClassPathButThereIsNoTracer() {
new ApplicationContextRunner().with(MetricsRun.simple())
.withPropertyValues("management.observations.annotations.enabled=true")
.withConfiguration(AutoConfigurations.of(ObservationAutoConfiguration.class))
.run((context) -> {
ObservationRegistry observationRegistry = context.getBean(ObservationRegistry.class);
Expand Down Expand Up @@ -181,6 +184,20 @@ void allowsObservedAspectToBeDisabled() {
.run((context) -> assertThat(context).doesNotHaveBean(ObservedAspect.class));
}

@Test
void allowsObservedAspectToBeEnabledWithDeprecatedProperty() {
this.contextRunner
.withPropertyValues("management.observations.annotations.enabled=false",
"micrometer.observations.annotations.enabled=true")
.run((context) -> assertThat(context).hasSingleBean(ObservedAspect.class));
}

@Test
void allowsObservedAspectToBeDisabledWithProperty() {
this.contextRunner.withPropertyValues("management.observations.annotations.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(ObservedAspect.class));
}

@Test
void allowsObservedAspectToBeCustomized() {
this.contextRunner.withUserConfiguration(CustomObservedAspectConfiguration.class)
Expand Down