Skip to content
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
Expand Up @@ -233,7 +233,7 @@ Regardless of your classpath, tracing components which are reporting data are no

If you need those components as part of an integration test, annotate the test with javadoc:org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability[format=annotation].

If you have created your own reporting components (e.g. a custom javadoc:io.opentelemetry.sdk.trace.export.SpanExporter[] or `brave.handler.SpanHandler`) and you don't want them to be active in tests, you can use the javadoc:org.springframework.boot.micrometer.tracing.autoconfigure.ConditionalOnEnabledTracing[format=annotation] annotation to disable them.
If you have created your own reporting components (e.g. a custom javadoc:io.opentelemetry.sdk.trace.export.SpanExporter[] or `brave.handler.SpanHandler`) and you don't want them to be active in tests, you can use the javadoc:org.springframework.boot.micrometer.tracing.autoconfigure.ConditionalOnEnabledTracingExport[format=annotation] annotation to disable them.

If you annotate xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.autoconfigured-tests[a sliced test] with javadoc:org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability[format=annotation], it auto-configures a no-op javadoc:io.micrometer.tracing.Tracer[].
Data exporting in sliced tests is not supported with the javadoc:org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability[format=annotation] annotation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static class PropagationWithoutBaggage {

@Bean
@ConditionalOnMissingBean(Factory.class)
@ConditionalOnEnabledTracing
@ConditionalOnEnabledTracingExport
CompositePropagationFactory propagationFactory(TracingProperties properties) {
return CompositePropagationFactory.create(properties.getPropagation());
}
Expand Down Expand Up @@ -127,7 +127,7 @@ BaggagePropagationCustomizer remoteFieldsBaggagePropagationCustomizer() {

@Bean
@ConditionalOnMissingBean
@ConditionalOnEnabledTracing
@ConditionalOnEnabledTracingExport
Factory propagationFactory(BaggagePropagation.FactoryBuilder factoryBuilder) {
return factoryBuilder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

/**
* {@link Conditional @Conditional} that checks whether tracing is enabled. It matches if
* the value of the {@code management.tracing.enabled} property is {@code true} or if it
* is not configured. If the {@link #value() tracing exporter name} is set, the
* the value of the {@code management.tracing.export.enabled} property is {@code true} or
* if it is not configured. If the {@link #value() tracing exporter name} is set, the
* {@code management.<name>.tracing.export.enabled} property can be used to control the
* behavior for the specific tracing exporter. In that case, the exporter specific
* property takes precedence over the global property.
Expand All @@ -38,8 +38,8 @@
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD })
@Documented
@Conditional(OnEnabledTracingCondition.class)
public @interface ConditionalOnEnabledTracing {
@Conditional(OnEnabledTracingExportCondition.class)
public @interface ConditionalOnEnabledTracingExport {

/**
* Name of the tracing exporter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* {@link EnvironmentPostProcessor} to add a {@link PropertySource} to support log
* correlation IDs when Micrometer Tracing is present. Adds support for the
* {@value LoggingSystem#EXPECT_CORRELATION_ID_PROPERTY} property by delegating to
* {@code management.tracing.enabled}.
* {@code management.tracing.export.enabled}.
*
* @author Jonatan Ivanov
* @author Phillip Webb
Expand Down Expand Up @@ -67,7 +67,7 @@ public String[] getPropertyNames() {
@Override
public @Nullable Object getProperty(String name) {
if (name.equals(LoggingSystem.EXPECT_CORRELATION_ID_PROPERTY)) {
return this.environment.getProperty("management.tracing.enabled", Boolean.class, Boolean.TRUE);
return this.environment.getProperty("management.tracing.export.enabled", Boolean.class, Boolean.TRUE);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
* {@link SpringBootCondition} to check whether tracing is enabled.
*
* @author Moritz Halbritter
* @see ConditionalOnEnabledTracing
* @see ConditionalOnEnabledTracingExport
*/
class OnEnabledTracingCondition extends SpringBootCondition {
class OnEnabledTracingExportCondition extends SpringBootCondition {

private static final String GLOBAL_PROPERTY = "management.tracing.enabled";
private static final String GLOBAL_PROPERTY = "management.tracing.export.enabled";

private static final String EXPORTER_PROPERTY = "management.%s.tracing.export.enabled";

Expand All @@ -47,23 +47,23 @@ public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeM
.getProperty(EXPORTER_PROPERTY.formatted(tracingExporter), Boolean.class);
if (exporterTracingEnabled != null) {
return new ConditionOutcome(exporterTracingEnabled,
ConditionMessage.forCondition(ConditionalOnEnabledTracing.class)
ConditionMessage.forCondition(ConditionalOnEnabledTracingExport.class)
.because(EXPORTER_PROPERTY.formatted(tracingExporter) + " is " + exporterTracingEnabled));
}
}
Boolean globalTracingEnabled = context.getEnvironment().getProperty(GLOBAL_PROPERTY, Boolean.class);
if (globalTracingEnabled != null) {
return new ConditionOutcome(globalTracingEnabled,
ConditionMessage.forCondition(ConditionalOnEnabledTracing.class)
ConditionMessage.forCondition(ConditionalOnEnabledTracingExport.class)
.because(GLOBAL_PROPERTY + " is " + globalTracingEnabled));
}
return ConditionOutcome.match(ConditionMessage.forCondition(ConditionalOnEnabledTracing.class)
return ConditionOutcome.match(ConditionMessage.forCondition(ConditionalOnEnabledTracingExport.class)
.because("tracing is enabled by default"));
}

private static @Nullable String getExporterName(AnnotatedTypeMetadata metadata) {
Map<String, @Nullable Object> attributes = metadata
.getAnnotationAttributes(ConditionalOnEnabledTracing.class.getName());
.getAnnotationAttributes(ConditionalOnEnabledTracingExport.class.getName());
if (attributes == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class OpenTelemetryPropagationConfigurations {
static class PropagationWithoutBaggage {

@Bean
@ConditionalOnEnabledTracing
@ConditionalOnEnabledTracingExport
TextMapPropagator textMapPropagator(TracingProperties properties) {
return CompositeTextMapPropagator.create(properties.getPropagation(), null);
}
Expand All @@ -69,7 +69,7 @@ static class PropagationWithBaggage {
}

@Bean
@ConditionalOnEnabledTracing
@ConditionalOnEnabledTracingExport
TextMapPropagator textMapPropagatorWithBaggage(OtelCurrentTraceContext otelCurrentTraceContext) {
List<String> remoteFields = this.tracingProperties.getBaggage().getRemoteFields();
List<String> tagFields = this.tracingProperties.getBaggage().getTagFields();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.micrometer.tracing.autoconfigure.ConditionalOnEnabledTracing;
import org.springframework.boot.micrometer.tracing.autoconfigure.ConditionalOnEnabledTracingExport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -79,7 +79,7 @@ public String getUrl(Transport transport) {
@Configuration(proxyBeanMethods = false)
@ConditionalOnMissingBean({ OtlpGrpcSpanExporter.class, OtlpHttpSpanExporter.class })
@ConditionalOnBean(OtlpTracingConnectionDetails.class)
@ConditionalOnEnabledTracing("otlp")
@ConditionalOnEnabledTracingExport("otlp")
static class Exporters {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
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.micrometer.tracing.autoconfigure.ConditionalOnEnabledTracing;
import org.springframework.boot.micrometer.tracing.autoconfigure.ConditionalOnEnabledTracingExport;
import org.springframework.boot.micrometer.tracing.autoconfigure.zipkin.ZipkinTracingAutoConfiguration.BraveConfiguration;
import org.springframework.boot.micrometer.tracing.autoconfigure.zipkin.ZipkinTracingAutoConfiguration.OpenTelemetryConfiguration;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -71,7 +71,7 @@ BytesEncoder<MutableSpan> mutableSpanBytesEncoder(Encoding encoding,
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(BytesMessageSender.class)
@ConditionalOnEnabledTracing("zipkin")
@ConditionalOnEnabledTracingExport("zipkin")
AsyncZipkinSpanHandler asyncZipkinSpanHandler(BytesMessageSender sender,
BytesEncoder<MutableSpan> mutableSpanBytesEncoder) {
return AsyncZipkinSpanHandler.newBuilder(sender).build(mutableSpanBytesEncoder);
Expand All @@ -93,7 +93,7 @@ BytesEncoder<Span> spanBytesEncoder(Encoding encoding) {
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(BytesMessageSender.class)
@ConditionalOnEnabledTracing("zipkin")
@ConditionalOnEnabledTracingExport("zipkin")
ZipkinSpanExporter zipkinSpanExporter(BytesMessageSender sender, BytesEncoder<Span> spanBytesEncoder) {
return ZipkinSpanExporter.builder().setSender(sender).setEncoder(spanBytesEncoder).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"description": "Whether auto-configuration of tracing is enabled to export OTLP traces."
},
{
"name": "management.tracing.enabled",
"name": "management.tracing.export.enabled",
"type": "java.lang.Boolean",
"description": "Whether auto-configuration of tracing is enabled to export and propagate traces.",
"defaultValue": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ void compositeSpanHandlerUsesFilterPredicateAndReportersInOrder() {

@Test
void shouldDisablePropagationIfTracingIsDisabled() {
this.contextRunner.withPropertyValues("management.tracing.enabled=false").run((context) -> {
this.contextRunner.withPropertyValues("management.tracing.export.enabled=false").run((context) -> {
assertThat(context).hasSingleBean(Factory.class);
Factory factory = context.getBean(Factory.class);
Propagation<String> propagation = factory.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void getExpectCorrelationIdPropertyWhenMicrometerTracingMissingReturnsFalse() {

@Test
void getExpectCorrelationIdPropertyWhenTracingDisabledReturnsFalse() {
TestPropertyValues.of("management.tracing.enabled=false").applyTo(this.environment);
TestPropertyValues.of("management.tracing.export.enabled=false").applyTo(this.environment);
this.postProcessor.postProcessEnvironment(this.environment, this.application);
assertThat(this.environment.getProperty(LoggingSystem.EXPECT_CORRELATION_ID_PROPERTY, Boolean.class, false))
.isFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,80 +31,82 @@
import static org.mockito.Mockito.mock;

/**
* Tests for {@link OnEnabledTracingCondition}.
* Tests for {@link OnEnabledTracingExportCondition}.
*
* @author Moritz Halbritter
*/
class OnEnabledTracingConditionTests {
class OnEnabledTracingExportConditionTests {

@Test
void shouldMatchIfNoPropertyIsSet() {
OnEnabledTracingCondition condition = new OnEnabledTracingCondition();
OnEnabledTracingExportCondition condition = new OnEnabledTracingExportCondition();
ConditionOutcome outcome = condition.getMatchOutcome(mockConditionContext(), mockMetadata(""));
assertThat(outcome.isMatch()).isTrue();
assertThat(outcome.getMessage()).isEqualTo("@ConditionalOnEnabledTracing tracing is enabled by default");
assertThat(outcome.getMessage()).isEqualTo("@ConditionalOnEnabledTracingExport tracing is enabled by default");
}

@Test
void shouldNotMatchIfGlobalPropertyIsFalse() {
OnEnabledTracingCondition condition = new OnEnabledTracingCondition();
ConditionOutcome outcome = condition
.getMatchOutcome(mockConditionContext(Map.of("management.tracing.enabled", "false")), mockMetadata(""));
OnEnabledTracingExportCondition condition = new OnEnabledTracingExportCondition();
ConditionOutcome outcome = condition.getMatchOutcome(
mockConditionContext(Map.of("management.tracing.export.enabled", "false")), mockMetadata(""));
assertThat(outcome.isMatch()).isFalse();
assertThat(outcome.getMessage()).isEqualTo("@ConditionalOnEnabledTracing management.tracing.enabled is false");
assertThat(outcome.getMessage())
.isEqualTo("@ConditionalOnEnabledTracingExport management.tracing.export.enabled is false");
}

@Test
void shouldMatchIfGlobalPropertyIsTrue() {
OnEnabledTracingCondition condition = new OnEnabledTracingCondition();
ConditionOutcome outcome = condition
.getMatchOutcome(mockConditionContext(Map.of("management.tracing.enabled", "true")), mockMetadata(""));
OnEnabledTracingExportCondition condition = new OnEnabledTracingExportCondition();
ConditionOutcome outcome = condition.getMatchOutcome(
mockConditionContext(Map.of("management.tracing.export.enabled", "true")), mockMetadata(""));
assertThat(outcome.isMatch()).isTrue();
assertThat(outcome.getMessage()).isEqualTo("@ConditionalOnEnabledTracing management.tracing.enabled is true");
assertThat(outcome.getMessage())
.isEqualTo("@ConditionalOnEnabledTracingExport management.tracing.export.enabled is true");
}

@Test
void shouldNotMatchIfExporterPropertyIsFalse() {
OnEnabledTracingCondition condition = new OnEnabledTracingCondition();
OnEnabledTracingExportCondition condition = new OnEnabledTracingExportCondition();
ConditionOutcome outcome = condition.getMatchOutcome(
mockConditionContext(Map.of("management.zipkin.tracing.export.enabled", "false")),
mockMetadata("zipkin"));
assertThat(outcome.isMatch()).isFalse();
assertThat(outcome.getMessage())
.isEqualTo("@ConditionalOnEnabledTracing management.zipkin.tracing.export.enabled is false");
.isEqualTo("@ConditionalOnEnabledTracingExport management.zipkin.tracing.export.enabled is false");
}

@Test
void shouldMatchIfExporterPropertyIsTrue() {
OnEnabledTracingCondition condition = new OnEnabledTracingCondition();
OnEnabledTracingExportCondition condition = new OnEnabledTracingExportCondition();
ConditionOutcome outcome = condition.getMatchOutcome(
mockConditionContext(Map.of("management.zipkin.tracing.export.enabled", "true")),
mockMetadata("zipkin"));
assertThat(outcome.isMatch()).isTrue();
assertThat(outcome.getMessage())
.isEqualTo("@ConditionalOnEnabledTracing management.zipkin.tracing.export.enabled is true");
.isEqualTo("@ConditionalOnEnabledTracingExport management.zipkin.tracing.export.enabled is true");
}

@Test
void exporterPropertyShouldOverrideGlobalPropertyIfTrue() {
OnEnabledTracingCondition condition = new OnEnabledTracingCondition();
ConditionOutcome outcome = condition.getMatchOutcome(mockConditionContext(
Map.of("management.tracing.enabled", "false", "management.zipkin.tracing.export.enabled", "true")),
OnEnabledTracingExportCondition condition = new OnEnabledTracingExportCondition();
ConditionOutcome outcome = condition.getMatchOutcome(mockConditionContext(Map
.of("management.tracing.export.enabled", "false", "management.zipkin.tracing.export.enabled", "true")),
mockMetadata("zipkin"));
assertThat(outcome.isMatch()).isTrue();
assertThat(outcome.getMessage())
.isEqualTo("@ConditionalOnEnabledTracing management.zipkin.tracing.export.enabled is true");
.isEqualTo("@ConditionalOnEnabledTracingExport management.zipkin.tracing.export.enabled is true");
}

@Test
void exporterPropertyShouldOverrideGlobalPropertyIfFalse() {
OnEnabledTracingCondition condition = new OnEnabledTracingCondition();
ConditionOutcome outcome = condition.getMatchOutcome(mockConditionContext(
Map.of("management.tracing.enabled", "true", "management.zipkin.tracing.export.enabled", "false")),
OnEnabledTracingExportCondition condition = new OnEnabledTracingExportCondition();
ConditionOutcome outcome = condition.getMatchOutcome(mockConditionContext(Map
.of("management.tracing.export.enabled", "true", "management.zipkin.tracing.export.enabled", "false")),
mockMetadata("zipkin"));
assertThat(outcome.isMatch()).isFalse();
assertThat(outcome.getMessage())
.isEqualTo("@ConditionalOnEnabledTracing management.zipkin.tracing.export.enabled is false");
.isEqualTo("@ConditionalOnEnabledTracingExport management.zipkin.tracing.export.enabled is false");
}

private ConditionContext mockConditionContext() {
Expand All @@ -121,7 +123,7 @@ private ConditionContext mockConditionContext(Map<String, String> properties) {

private AnnotatedTypeMetadata mockMetadata(String exporter) {
AnnotatedTypeMetadata metadata = mock(AnnotatedTypeMetadata.class);
given(metadata.getAnnotationAttributes(ConditionalOnEnabledTracing.class.getName()))
given(metadata.getAnnotationAttributes(ConditionalOnEnabledTracingExport.class.getName()))
.willReturn(Map.of("value", exporter));
return metadata;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ void defaultSpanProcessorShouldUseMeterProviderIfAvailable() {

@Test
void shouldDisablePropagationIfTracingIsDisabled() {
this.contextRunner.withPropertyValues("management.tracing.enabled=false").run((context) -> {
this.contextRunner.withPropertyValues("management.tracing.export.enabled=false").run((context) -> {
assertThat(context).hasSingleBean(TextMapPropagator.class);
TextMapPropagator propagator = context.getBean(TextMapPropagator.class);
assertThat(propagator.fields()).isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class OtlpTracingAutoConfigurationTests {
.withConfiguration(AutoConfigurations.of(OtlpTracingAutoConfiguration.class));

private final ApplicationContextRunner tracingDisabledContextRunner = this.contextRunner
.withPropertyValues("management.tracing.enabled=false");
.withPropertyValues("management.tracing.export.enabled=false");

@Test
void shouldNotSupplyBeansIfPropertyIsNotSet() {
Expand Down Expand Up @@ -125,7 +125,7 @@ void shouldCustomizeGrpcTransportWithProperties() {

@Test
void shouldNotSupplyBeansIfGlobalTracingIsDisabled() {
this.contextRunner.withPropertyValues("management.tracing.enabled=false")
this.contextRunner.withPropertyValues("management.tracing.export.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(SpanExporter.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void shouldSupplyAsyncZipkinSpanHandlerWithCustomSpanHandler() {

@Test
void shouldNotSupplyAsyncZipkinSpanHandlerIfGlobalTracingIsDisabled() {
this.contextRunner.withPropertyValues("management.tracing.enabled=false")
this.contextRunner.withPropertyValues("management.tracing.export.enabled=false")
.withUserConfiguration(SenderConfiguration.class)
.run((context) -> assertThat(context).doesNotHaveBean(AsyncZipkinSpanHandler.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void shouldBackOffOnCustomBeans() {

@Test
void shouldNotSupplyZipkinSpanExporterIfGlobalTracingIsDisabled() {
this.contextRunner.withPropertyValues("management.tracing.enabled=false")
this.contextRunner.withPropertyValues("management.tracing.export.enabled=false")
.withUserConfiguration(SenderConfiguration.class)
.run((context) -> assertThat(context).doesNotHaveBean(ZipkinSpanExporter.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void shouldSupplyBeansIfInfrastructureIsAvailable() {

@Test
void shouldNotSupplyBeansIfTracingIsDisabled() {
this.contextRunner.withPropertyValues("management.tracing.enabled=false")
this.contextRunner.withPropertyValues("management.tracing.export.enabled=false")
.withConfiguration(AutoConfigurations.of(ZipkinAutoConfiguration.class))
.run((context) -> {
assertThat(context).doesNotHaveBean(SpanExporter.class);
Expand Down
Loading