Skip to content

Commit 094a861

Browse files
committed
Merge branch '3.5.x'
Closes gh-46845
2 parents b2398cb + 16f25ec commit 094a861

File tree

2 files changed

+47
-22
lines changed

2 files changed

+47
-22
lines changed

module/spring-boot-tracing/src/main/java/org/springframework/boot/tracing/autoconfigure/CompositePropagationFactory.java

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.Collection;
2020
import java.util.Collections;
2121
import java.util.List;
22-
import java.util.function.Predicate;
2322
import java.util.stream.Stream;
2423

2524
import brave.propagation.B3Propagation;
@@ -77,11 +76,19 @@ public Propagation<String> get() {
7776

7877
@Override
7978
public TraceContext decorate(TraceContext context) {
80-
return Stream.concat(this.injectors.stream(), this.extractors.stream())
81-
.map((factory) -> factory.decorate(context))
82-
.filter((decorated) -> decorated != context)
83-
.findFirst()
84-
.orElse(context);
79+
for (Propagation.Factory factory : this.injectors.factories) {
80+
TraceContext decorated = factory.decorate(context);
81+
if (decorated != context) {
82+
return decorated;
83+
}
84+
}
85+
for (Propagation.Factory factory : this.extractors.factories) {
86+
TraceContext decorated = factory.decorate(context);
87+
if (decorated != context) {
88+
return decorated;
89+
}
90+
}
91+
return context;
8592
}
8693

8794
/**
@@ -180,11 +187,21 @@ private static class PropagationFactories {
180187
}
181188

182189
boolean requires128BitTraceId() {
183-
return stream().anyMatch(Propagation.Factory::requires128BitTraceId);
190+
for (Propagation.Factory factory : this.factories) {
191+
if (factory.requires128BitTraceId()) {
192+
return true;
193+
}
194+
}
195+
return false;
184196
}
185197

186198
boolean supportsJoin() {
187-
return stream().allMatch(Propagation.Factory::supportsJoin);
199+
for (Propagation.Factory factory : this.factories) {
200+
if (!factory.supportsJoin()) {
201+
return false;
202+
}
203+
}
204+
return true;
188205
}
189206

190207
List<Propagation<String>> get() {
@@ -225,19 +242,24 @@ public List<String> keys() {
225242

226243
@Override
227244
public <R> TraceContext.Injector<R> injector(Setter<R, String> setter) {
228-
return (traceContext, request) -> this.injectors.stream()
229-
.map((propagation) -> propagation.injector(setter))
230-
.forEach((injector) -> injector.inject(traceContext, request));
245+
return (traceContext, request) -> {
246+
for (Propagation<String> propagation : this.injectors) {
247+
propagation.injector(setter).inject(traceContext, request);
248+
}
249+
};
231250
}
232251

233252
@Override
234253
public <R> TraceContext.Extractor<R> extractor(Getter<R, String> getter) {
235-
return (request) -> this.extractors.stream()
236-
.map((propagation) -> propagation.extractor(getter))
237-
.map((extractor) -> extractor.extract(request))
238-
.filter(Predicate.not(TraceContextOrSamplingFlags.EMPTY::equals))
239-
.findFirst()
240-
.orElse(TraceContextOrSamplingFlags.EMPTY);
254+
return (request) -> {
255+
for (Propagation<String> propagation : this.extractors) {
256+
TraceContextOrSamplingFlags extracted = propagation.extractor(getter).extract(request);
257+
if (!TraceContextOrSamplingFlags.EMPTY.equals(extracted)) {
258+
return extracted;
259+
}
260+
}
261+
return TraceContextOrSamplingFlags.EMPTY;
262+
};
241263
}
242264

243265
}

module/spring-boot-tracing/src/main/java/org/springframework/boot/tracing/autoconfigure/CompositeTextMapPropagator.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,14 @@ public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C
107107
if (getter == null) {
108108
return context;
109109
}
110-
Context result = this.extractors.stream()
111-
.map((extractor) -> extractor.extract(context, carrier, getter))
112-
.filter((extracted) -> extracted != context)
113-
.findFirst()
114-
.orElse(context);
110+
Context result = context;
111+
for (TextMapPropagator extractor : this.extractors) {
112+
Context extracted = extractor.extract(context, carrier, getter);
113+
if (extracted != context) {
114+
result = extracted;
115+
break;
116+
}
117+
}
115118
if (this.baggagePropagator != null) {
116119
result = this.baggagePropagator.extract(result, carrier, getter);
117120
}

0 commit comments

Comments
 (0)