From ae3f6ac481de5af1859d28791bfb210421e2fea9 Mon Sep 17 00:00:00 2001 From: xiepuhuan Date: Wed, 8 Jan 2025 23:28:14 +0800 Subject: [PATCH] Implementing `ExtendedTextMapGetter` in grpc-1.6 instrumentation (#13011) Signed-off-by: xiepuhuan --- .../grpc/v1_6/GrpcRequestGetter.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcRequestGetter.java b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcRequestGetter.java index 0d7cfe5e4837..6ef3210579e9 100644 --- a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcRequestGetter.java +++ b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcRequestGetter.java @@ -5,11 +5,14 @@ package io.opentelemetry.instrumentation.grpc.v1_6; +import static java.util.Collections.emptyIterator; + import io.grpc.Metadata; -import io.opentelemetry.context.propagation.TextMapGetter; +import io.opentelemetry.context.propagation.internal.ExtendedTextMapGetter; +import java.util.Iterator; import javax.annotation.Nullable; -enum GrpcRequestGetter implements TextMapGetter { +enum GrpcRequestGetter implements ExtendedTextMapGetter { INSTANCE; @Override @@ -25,4 +28,19 @@ public String get(@Nullable GrpcRequest request, String key) { } return request.getMetadata().get(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER)); } + + @Override + public Iterator getAll(@Nullable GrpcRequest request, String key) { + if (request == null) { + return emptyIterator(); + } + + Iterable values = + request.getMetadata().getAll(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER)); + + if (values == null) { + return emptyIterator(); + } + return values.iterator(); + } }