Skip to content

Commit

Permalink
Merge branch '3.1.x'
Browse files Browse the repository at this point in the history
Closes gh-37179
  • Loading branch information
scottfrederick committed Sep 1, 2023
2 parents f45a32d + 03dcf8b commit 47508b8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
* configure different formats for injecting and for extracting.
*
* @author Moritz Halbritter
* @author Scott Frederick
*/
class CompositeTextMapPropagator implements TextMapPropagator {

Expand Down Expand Up @@ -81,6 +82,10 @@ Collection<TextMapPropagator> getInjectors() {
return this.injectors;
}

Collection<TextMapPropagator> getExtractors() {
return this.extractors;
}

@Override
public Collection<String> fields() {
return this.fields;
Expand Down Expand Up @@ -113,8 +118,7 @@ public <C> Context extract(Context context, C carrier, TextMapGetter<C> getter)
}

/**
* Creates a new {@link CompositeTextMapPropagator}, which uses the given
* {@code injectionTypes} for injection and {@code extractionTypes} for extraction.
* Creates a new {@link CompositeTextMapPropagator}.
* @param properties the tracing properties
* @param baggagePropagator the baggage propagator to use, or {@code null}
* @return the {@link CompositeTextMapPropagator}
Expand All @@ -128,7 +132,7 @@ static TextMapPropagator create(TracingProperties.Propagation properties, TextMa
if (baggagePropagator != null) {
injectors.add(baggagePropagator);
}
List<TextMapPropagator> extractors = properties.getEffectiveProducedTypes().stream().map(mapper::map).toList();
List<TextMapPropagator> extractors = properties.getEffectiveConsumedTypes().stream().map(mapper::map).toList();
return new CompositeTextMapPropagator(injectors, extractors, baggagePropagator);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,28 @@
import java.util.List;
import java.util.Map;

import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.ContextKey;
import io.opentelemetry.context.propagation.TextMapGetter;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.context.propagation.TextMapSetter;
import io.opentelemetry.extension.trace.propagation.B3Propagator;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InOrder;
import org.mockito.Mockito;

import org.springframework.boot.actuate.autoconfigure.tracing.TracingProperties.Propagation;
import org.springframework.boot.actuate.autoconfigure.tracing.TracingProperties.Propagation.PropagationType;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link CompositeTextMapPropagator}.
*
* @author Moritz Halbritter
* @author Scott Frederick
*/
class CompositeTextMapPropagatorTests {

Expand Down Expand Up @@ -91,6 +97,17 @@ void extractWithBaggagePropagator() {
assertThat(c).isEqualTo("c-value");
}

@Test
void createMapsInjectorsAndExtractors() {
Propagation properties = new Propagation();
properties.setProduce(List.of(PropagationType.W3C));
properties.setConsume(List.of(PropagationType.B3));
CompositeTextMapPropagator propagator = (CompositeTextMapPropagator) CompositeTextMapPropagator
.create(properties, null);
assertThat(propagator.getInjectors()).hasExactlyElementsOfTypes(W3CTraceContextPropagator.class);
assertThat(propagator.getExtractors()).hasExactlyElementsOfTypes(B3Propagator.class);
}

private DummyTextMapPropagator field(String field) {
return new DummyTextMapPropagator(field, this.contextKeyRegistry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Stream;

import io.micrometer.tracing.SpanCustomizer;
import io.micrometer.tracing.otel.bridge.OtelCurrentTraceContext;
Expand Down Expand Up @@ -235,8 +234,8 @@ void shouldNotSupplySlf4JBaggageEventListenerWhenBaggageDisabled() {
void shouldSupplyB3PropagationIfPropagationPropertySet() {
this.contextRunner.withPropertyValues("management.tracing.propagation.type=B3").run((context) -> {
TextMapPropagator propagator = context.getBean(TextMapPropagator.class);
Stream<Class<?>> injectors = getInjectors(propagator).stream().map(Object::getClass);
assertThat(injectors).containsExactly(B3Propagator.class, BaggageTextMapPropagator.class);
List<TextMapPropagator> injectors = getInjectors(propagator);
assertThat(injectors).hasExactlyElementsOfTypes(B3Propagator.class, BaggageTextMapPropagator.class);
});
}

Expand All @@ -246,8 +245,8 @@ void shouldSupplyB3PropagationIfPropagationPropertySetAndBaggageDisabled() {
.withPropertyValues("management.tracing.propagation.type=B3", "management.tracing.baggage.enabled=false")
.run((context) -> {
TextMapPropagator propagator = context.getBean(TextMapPropagator.class);
Stream<Class<?>> injectors = getInjectors(propagator).stream().map(Object::getClass);
assertThat(injectors).containsExactly(B3Propagator.class);
List<TextMapPropagator> injectors = getInjectors(propagator);
assertThat(injectors).hasExactlyElementsOfTypes(B3Propagator.class);
});
}

Expand All @@ -268,8 +267,8 @@ void shouldSupplyW3CPropagationWithBaggageByDefault() {
void shouldSupplyW3CPropagationWithoutBaggageWhenDisabled() {
this.contextRunner.withPropertyValues("management.tracing.baggage.enabled=false").run((context) -> {
TextMapPropagator propagator = context.getBean(TextMapPropagator.class);
Stream<Class<?>> injectors = getInjectors(propagator).stream().map(Object::getClass);
assertThat(injectors).containsExactly(W3CTraceContextPropagator.class);
List<TextMapPropagator> injectors = getInjectors(propagator);
assertThat(injectors).hasExactlyElementsOfTypes(W3CTraceContextPropagator.class);
});
}

Expand Down

0 comments on commit 47508b8

Please sign in to comment.