|
16 | 16 |
|
17 | 17 | package org.springframework.cloud.sleuth.otel.propagation; |
18 | 18 |
|
19 | | -import java.util.ArrayList; |
20 | | -import java.util.Arrays; |
21 | 19 | import java.util.Collections; |
22 | 20 | import java.util.HashMap; |
23 | | -import java.util.LinkedHashSet; |
24 | 21 | import java.util.List; |
25 | 22 | import java.util.Map; |
26 | | -import java.util.Set; |
27 | 23 | import java.util.stream.Collectors; |
28 | 24 |
|
29 | 25 | import io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator; |
|
39 | 35 | import org.apache.commons.logging.LogFactory; |
40 | 36 |
|
41 | 37 | import org.springframework.beans.factory.BeanFactory; |
42 | | -import org.springframework.lang.Nullable; |
43 | 38 | import org.springframework.util.ClassUtils; |
44 | 39 |
|
45 | 40 | /** |
@@ -75,8 +70,8 @@ public CompositeTextMapPropagator(BeanFactory beanFactory, List<PropagationType> |
75 | 70 | this.mapping.put(PropagationType.OT_TRACER, beanFactory.getBeanProvider(OtTracerPropagator.class) |
76 | 71 | .getIfAvailable(OtTracerPropagator::getInstance)); |
77 | 72 | } |
78 | | - this.mapping.put(PropagationType.W3C, new MultiTextMapPropagator( |
79 | | - Arrays.asList(W3CTraceContextPropagator.getInstance(), W3CBaggagePropagator.getInstance()))); |
| 73 | + this.mapping.put(PropagationType.W3C, TextMapPropagator.composite(W3CTraceContextPropagator.getInstance(), |
| 74 | + W3CBaggagePropagator.getInstance())); |
80 | 75 | this.mapping.put(PropagationType.CUSTOM, NoopTextMapPropagator.INSTANCE); |
81 | 76 | log.info("Registered the following context propagation types " + this.mapping.keySet()); |
82 | 77 | } |
@@ -133,48 +128,4 @@ public <C> Context extract(Context context, C carrier, Getter<C> getter) { |
133 | 128 |
|
134 | 129 | } |
135 | 130 |
|
136 | | - // Taken from OTel |
137 | | - private static final class MultiTextMapPropagator implements TextMapPropagator { |
138 | | - |
139 | | - private final TextMapPropagator[] textPropagators; |
140 | | - |
141 | | - private final List<String> allFields; |
142 | | - |
143 | | - private MultiTextMapPropagator(List<TextMapPropagator> textPropagators) { |
144 | | - this.textPropagators = new TextMapPropagator[textPropagators.size()]; |
145 | | - textPropagators.toArray(this.textPropagators); |
146 | | - this.allFields = Collections.unmodifiableList(getAllFields(this.textPropagators)); |
147 | | - } |
148 | | - |
149 | | - private static List<String> getAllFields(TextMapPropagator[] textPropagators) { |
150 | | - Set<String> fields = new LinkedHashSet<>(); |
151 | | - for (int i = 0; i < textPropagators.length; i++) { |
152 | | - fields.addAll(textPropagators[i].fields()); |
153 | | - } |
154 | | - |
155 | | - return new ArrayList<>(fields); |
156 | | - } |
157 | | - |
158 | | - @Override |
159 | | - public List<String> fields() { |
160 | | - return allFields; |
161 | | - } |
162 | | - |
163 | | - @Override |
164 | | - public <C> void inject(Context context, @Nullable C carrier, Setter<C> setter) { |
165 | | - for (int i = 0; i < textPropagators.length; i++) { |
166 | | - textPropagators[i].inject(context, carrier, setter); |
167 | | - } |
168 | | - } |
169 | | - |
170 | | - @Override |
171 | | - public <C> Context extract(Context context, @Nullable C carrier, Getter<C> getter) { |
172 | | - for (int i = 0; i < textPropagators.length; i++) { |
173 | | - context = textPropagators[i].extract(context, carrier, getter); |
174 | | - } |
175 | | - return context; |
176 | | - } |
177 | | - |
178 | | - } |
179 | | - |
180 | 131 | } |
0 commit comments