Skip to content

Commit

Permalink
Polish Micrometer tracing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye authored and wilkinsona committed Oct 12, 2022
1 parent e4544c1 commit 1032f8c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ Factory propagationFactory(BaggagePropagation.FactoryBuilder factoryBuilder) {
CorrelationScopeDecorator.Builder mdcCorrelationScopeDecoratorBuilder(
ObjectProvider<CorrelationScopeCustomizer> correlationScopeCustomizers) {
CorrelationScopeDecorator.Builder builder = MDCScopeDecorator.newBuilder();
correlationScopeCustomizers.forEach((customizer) -> customizer.customize(builder));
correlationScopeCustomizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void setFields(List<String> fields) {
public static class Propagation {

/**
* Tracing context propagation types.
* Tracing context propagation type.
*/
private PropagationType type = PropagationType.W3C;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void shouldRemoveEntriesFromMdcForNullSpan(AutoConfig autoConfig) {

try (Tracer.SpanInScope scope2 = tracer.withSpan(null)) {
assertThatMdcContainsUnsetTraceId();
assertThat(MDC.get(COUNTRY_CODE)).isNullOrEmpty();
assertThat(MDC.get(COUNTRY_CODE)).isNull();
}

assertThat(MDC.get("traceId")).isEqualTo(span.context().traceId());
Expand All @@ -103,7 +103,7 @@ void shouldRemoveEntriesFromMdcForNullSpan(AutoConfig autoConfig) {
span.end();
}
assertThatMdcContainsUnsetTraceId();
assertThat(MDC.get(COUNTRY_CODE)).isNullOrEmpty();
assertThat(MDC.get(COUNTRY_CODE)).isNull();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,11 @@ void shouldNotSupplyCorrelationScopeDecoratorIfBaggageDisabled() {

@Test
void shouldSupplyW3CWithoutBaggageByDefaultIfBaggageDisabled() {
this.contextRunner.withPropertyValues("management.tracing.baggage.enabled=false")
.run((context) -> assertThat(context).hasSingleBean(W3CPropagation.class));
this.contextRunner.withPropertyValues("management.tracing.baggage.enabled=false").run((context) -> {
assertThat(context).hasBean("propagationFactory");
assertThat(context).hasSingleBean(W3CPropagation.class);
assertThat(context).doesNotHaveBean(BaggagePropagation.FactoryBuilder.class);
});
}

@Test
Expand All @@ -181,6 +184,7 @@ void shouldSupplyB3WithoutBaggageIfBaggageDisabledAndB3Picked() {
"management.tracing.propagation.type=B3").run((context) -> {
assertThat(context).hasBean("propagationFactory");
assertThat(context.getBean(Factory.class).toString()).isEqualTo("B3Propagation");
assertThat(context).doesNotHaveBean(BaggagePropagation.FactoryBuilder.class);
});
}

Expand All @@ -196,7 +200,7 @@ void shouldNotApplyCorrelationFieldsIfBaggageCorrelationDisabled() {
}

@Test
void shouldNotApplyCorrelationFieldsIfBaggageCorrelationEnabled() {
void shouldApplyCorrelationFieldsIfBaggageCorrelationEnabled() {
this.contextRunner.withPropertyValues("management.tracing.baggage.correlation.enabled=true",
"management.tracing.baggage.correlation.fields=alpha,bravo").run((context) -> {
ScopeDecorator scopeDecorator = context.getBean(ScopeDecorator.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Answers;

import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.FilteredClassLoader;
Expand Down Expand Up @@ -152,7 +151,7 @@ void shouldAllowMultipleTextMapPropagators() {
}

@Test
void shouldNotSupplySlf4jBaggageEventListenerBaggageCorrelationDisabled() {
void shouldNotSupplySlf4jBaggageEventListenerWhenBaggageCorrelationDisabled() {
this.contextRunner.withPropertyValues("management.tracing.baggage.correlation.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(Slf4JBaggageEventListener.class));
}
Expand Down Expand Up @@ -192,16 +191,6 @@ void shouldSupplyW3CPropagationWithoutBaggageWhenDisabled() {
.run((context) -> assertThat(context).hasBean("w3cTextMapPropagatorWithoutBaggage"));
}

@Test
void shouldSupplyB3PropagationWithoutBaggageWhenBaggageDisabledAndB3PropagationEnabled() {
this.contextRunner.withPropertyValues("management.tracing.baggage.enabled=false",
"management.tracing.propagation.type=B3").run((context) -> {
assertThat(context).hasBean("b3TextMapPropagator");
assertThat(context).hasSingleBean(B3Propagator.class);
assertThat(context).doesNotHaveBean("w3cTextMapPropagatorWithoutBaggage");
});
}

@Configuration(proxyBeanMethods = false)
private static class CustomConfiguration {

Expand Down Expand Up @@ -282,34 +271,4 @@ TextMapPropagator customTextMapPropagator() {

}

@Configuration(proxyBeanMethods = false)
private static class OpenTelemetryConfiguration {

@Bean
OpenTelemetry openTelemetry() {
return mock(OpenTelemetry.class, Answers.RETURNS_MOCKS);
}

}

@Configuration(proxyBeanMethods = false)
private static class ContextPropagatorsConfiguration {

@Bean
ContextPropagators contextPropagators() {
return mock(ContextPropagators.class, Answers.RETURNS_MOCKS);
}

}

@Configuration(proxyBeanMethods = false)
private static class CustomFactoryConfiguration {

@Bean
TextMapPropagator customPropagationFactory() {
return mock(TextMapPropagator.class);
}

}

}

0 comments on commit 1032f8c

Please sign in to comment.