Implementing `ExtendedTextMapGetter` in grpc-1.6 instrumentation (#13011)
Signed-off-by: xiepuhuan <puhuanxie@gmail.com>
This commit is contained in:
parent
324fdbdd45
commit
ae3f6ac481
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue