Implementing `ExtendedTextMapGetter` in grpc-1.6 instrumentation (#13011)

Signed-off-by: xiepuhuan <puhuanxie@gmail.com>
This commit is contained in:
xiepuhuan 2025-01-08 23:28:14 +08:00 committed by GitHub
parent 324fdbdd45
commit ae3f6ac481
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 2 deletions

View File

@ -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<GrpcRequest> {
enum GrpcRequestGetter implements ExtendedTextMapGetter<GrpcRequest> {
INSTANCE;
@Override
@ -25,4 +28,19 @@ enum GrpcRequestGetter implements TextMapGetter<GrpcRequest> {
}
return request.getMetadata().get(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER));
}
@Override
public Iterator<String> getAll(@Nullable GrpcRequest request, String key) {
if (request == null) {
return emptyIterator();
}
Iterable<String> values =
request.getMetadata().getAll(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER));
if (values == null) {
return emptyIterator();
}
return values.iterator();
}
}