Skip to content

Commit

Permalink
Remove streams from B3Propagator (#5326)
Browse files Browse the repository at this point in the history
They are expensive in this context
  • Loading branch information
BrentDouglas authored Mar 29, 2023
1 parent ba06aa7 commit aad95f8
Showing 1 changed file with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import io.opentelemetry.context.propagation.TextMapSetter;
import java.util.Collection;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

Expand Down Expand Up @@ -113,15 +111,11 @@ public <C> void inject(Context context, @Nullable C carrier, TextMapSetter<C> se

@Override
public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C> getter) {
return Stream.<Supplier<Optional<Context>>>of(
() -> singleHeaderExtractor.extract(context, carrier, getter),
() -> multipleHeadersExtractor.extract(context, carrier, getter),
() -> Optional.of(context))
.map(Supplier::get)
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst()
.get();
Optional<Context> ctx = singleHeaderExtractor.extract(context, carrier, getter);
if (ctx.isPresent()) {
return ctx.get();
}
return multipleHeadersExtractor.extract(context, carrier, getter).orElse(context);
}

@Override
Expand Down

0 comments on commit aad95f8

Please sign in to comment.