commit
47508b8338
|
@ -40,6 +40,7 @@ import org.springframework.boot.actuate.autoconfigure.tracing.TracingProperties.
|
|||
* configure different formats for injecting and for extracting.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class CompositeTextMapPropagator implements TextMapPropagator {
|
||||
|
||||
|
@ -81,6 +82,10 @@ class CompositeTextMapPropagator implements TextMapPropagator {
|
|||
return this.injectors;
|
||||
}
|
||||
|
||||
Collection<TextMapPropagator> getExtractors() {
|
||||
return this.extractors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> fields() {
|
||||
return this.fields;
|
||||
|
@ -113,8 +118,7 @@ class CompositeTextMapPropagator implements TextMapPropagator {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
|
@ -128,7 +132,7 @@ class CompositeTextMapPropagator implements TextMapPropagator {
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,22 +22,28 @@ import java.util.HashMap;
|
|||
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 {
|
||||
|
||||
|
@ -91,6 +97,17 @@ class CompositeTextMapPropagatorTests {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.util.Map;
|
|||
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;
|
||||
|
@ -235,8 +234,8 @@ class OpenTelemetryAutoConfigurationTests {
|
|||
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);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -246,8 +245,8 @@ class OpenTelemetryAutoConfigurationTests {
|
|||
.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);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -268,8 +267,8 @@ class OpenTelemetryAutoConfigurationTests {
|
|||
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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue