Skip to content

Commit

Permalink
Implementing ExtendedTextMapGetter in grpc-1.6 instrumentation (#13011
Browse files Browse the repository at this point in the history
)

Signed-off-by: xiepuhuan <[email protected]>
  • Loading branch information
xiepuhuan authored Jan 8, 2025
1 parent 324fdbd commit ae3f6ac
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<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();
}
}

0 comments on commit ae3f6ac

Please sign in to comment.