Skip to content

Commit

Permalink
Remove explicit order, depend on enum ordering instead
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed Jun 5, 2023
1 parent a13f167 commit a3da5b1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure.tracing;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -176,7 +177,7 @@ static class BraveNoBaggageConfiguration {
Factory propagationFactory(TracingProperties properties) {
List<Factory> injectorFactories = PropagationFactoryFactory
.factoriesFor(properties.getPropagation().getType());
List<Factory> extractorFactories = PropagationFactoryFactory.factoriesFor(PropagationType.orderedValues());
List<Factory> extractorFactories = PropagationFactoryFactory.factoriesFor(PropagationType.values());
return new CompositePropagationFactory(injectorFactories, extractorFactories);
}

Expand All @@ -199,7 +200,7 @@ BaggagePropagation.FactoryBuilder propagationFactoryBuilder(
List<Factory> injectorFactories = PropagationFactoryFactory.factoriesFor(BRAVE_BAGGAGE_MANAGER,
this.tracingProperties.getPropagation().getType());
List<Factory> extractorFactories = PropagationFactoryFactory.factoriesFor(BRAVE_BAGGAGE_MANAGER,
PropagationType.orderedValues());
PropagationType.values());
Factory delegate = new CompositePropagationFactory(injectorFactories, extractorFactories);
FactoryBuilder builder = BaggagePropagation.newFactoryBuilder(delegate);
baggagePropagationCustomizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
Expand Down Expand Up @@ -309,6 +310,14 @@ private static List<Factory> factoriesFor(BaggageManager baggageManager, Collect
return result;
}

private static List<Factory> factoriesFor(PropagationType[] types) {
return factoriesFor(null, Arrays.stream(types).toList());
}

private static List<Factory> factoriesFor(BaggageManager baggageManager, PropagationType[] types) {
return factoriesFor(baggageManager, Arrays.stream(types).toList());
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure.tracing;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -196,8 +197,7 @@ TextMapPropagator textMapPropagatorWithBaggage(OtelCurrentTraceContext otelCurre
List<TextMapPropagator> injectors = new ArrayList<>(
TextMapPropagatorFactory.forTypes(this.tracingProperties.getPropagation().getType(), true));
injectors.add(baggagePropagator);
List<TextMapPropagator> extractors = TextMapPropagatorFactory.forTypes(PropagationType.orderedValues(),
true);
List<TextMapPropagator> extractors = TextMapPropagatorFactory.forTypes(PropagationType.values(), true);
return new CompositeTextMapPropagator(injectors, extractors, List.of(baggagePropagator));
}

Expand All @@ -219,8 +219,7 @@ static class NoBaggageConfiguration {
TextMapPropagator textMapPropagator(TracingProperties properties) {
List<TextMapPropagator> injectors = TextMapPropagatorFactory.forTypes(properties.getPropagation().getType(),
false);
List<TextMapPropagator> extractors = TextMapPropagatorFactory.forTypes(PropagationType.orderedValues(),
false);
List<TextMapPropagator> extractors = TextMapPropagatorFactory.forTypes(PropagationType.values(), false);
return new CompositeTextMapPropagator(injectors, extractors);
}

Expand Down Expand Up @@ -296,6 +295,10 @@ private static List<TextMapPropagator> forTypes(Collection<PropagationType> type
return result;
}

private static List<TextMapPropagator> forTypes(PropagationType[] types, boolean baggage) {
return forTypes(Arrays.stream(types).toList(), baggage);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package org.springframework.boot.actuate.autoconfigure.tracing;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

import org.springframework.boot.context.properties.ConfigurationProperties;
Expand Down Expand Up @@ -180,42 +178,27 @@ public void setType(List<PropagationType> type) {
this.type = type;
}

/**
* Supported propagation types. The declared order of the values matter.
*/
enum PropagationType {

/**
* <a href="https://www.w3.org/TR/trace-context/">W3C propagation.</a>
*/
W3C,

/**
* <a href="https://github.com/openzipkin/b3-propagation#single-header">B3
* single header</a> propagation.
*/
B3(1),
B3,

/**
* <a href="https://github.com/openzipkin/b3-propagation#multiple-headers">B3
* multiple headers</a> propagation.
*/
B3_MULTI(2),

/**
* W3C propagation.
*/
W3C(0);

/**
* Order of the enum value. The {@link #orderedValues()} method returns the
* enum values in ascending order.
*/
private final int order;

PropagationType(int order) {
this.order = order;
}

/**
* Returns the ordered values.
* @return the ordered values
*/
static List<PropagationType> orderedValues() {
return Arrays.stream(values()).sorted(Comparator.comparing((value) -> value.order)).toList();
}
B3_MULTI;

}

Expand Down

0 comments on commit a3da5b1

Please sign in to comment.