Skip to content

Commit 391ca5d

Browse files
author
Bogdan Drutu
authored
Update CompositeTextMapPropagator to use the default MultiPropagator from otel (#8)
1 parent 896481c commit 391ca5d

File tree

1 file changed

+2
-51
lines changed

1 file changed

+2
-51
lines changed

spring-cloud-sleuth-otel/src/main/java/org/springframework/cloud/sleuth/otel/propagation/CompositeTextMapPropagator.java

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,10 @@
1616

1717
package org.springframework.cloud.sleuth.otel.propagation;
1818

19-
import java.util.ArrayList;
20-
import java.util.Arrays;
2119
import java.util.Collections;
2220
import java.util.HashMap;
23-
import java.util.LinkedHashSet;
2421
import java.util.List;
2522
import java.util.Map;
26-
import java.util.Set;
2723
import java.util.stream.Collectors;
2824

2925
import io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator;
@@ -39,7 +35,6 @@
3935
import org.apache.commons.logging.LogFactory;
4036

4137
import org.springframework.beans.factory.BeanFactory;
42-
import org.springframework.lang.Nullable;
4338
import org.springframework.util.ClassUtils;
4439

4540
/**
@@ -75,8 +70,8 @@ public CompositeTextMapPropagator(BeanFactory beanFactory, List<PropagationType>
7570
this.mapping.put(PropagationType.OT_TRACER, beanFactory.getBeanProvider(OtTracerPropagator.class)
7671
.getIfAvailable(OtTracerPropagator::getInstance));
7772
}
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()));
8075
this.mapping.put(PropagationType.CUSTOM, NoopTextMapPropagator.INSTANCE);
8176
log.info("Registered the following context propagation types " + this.mapping.keySet());
8277
}
@@ -133,48 +128,4 @@ public <C> Context extract(Context context, C carrier, Getter<C> getter) {
133128

134129
}
135130

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-
180131
}

0 commit comments

Comments
 (0)