Skip to content

Commit 35af206

Browse files
committed
adds getList() method to TextMapGetter, with default method
1 parent 1566984 commit 35af206

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

context/src/main/java/io/opentelemetry/context/propagation/TextMapGetter.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package io.opentelemetry.context.propagation;
77

8+
import java.util.Collections;
9+
import java.util.List;
810
import javax.annotation.Nullable;
911

1012
/**
@@ -33,4 +35,20 @@ public interface TextMapGetter<C> {
3335
*/
3436
@Nullable
3537
String get(@Nullable C carrier, String key);
38+
39+
/**
40+
* If implemented, returns all values for a given {@code key}, in order.
41+
*
42+
* <p>The default method returns the first value of the given propagation {@code key} as a
43+
* singleton list, or returns an empty list.
44+
*
45+
* @param carrier carrier of propagation fields, such as an http request.
46+
* @param key the key of the field.
47+
* @return the first value of the given propagation {@code key} as a singleton list, or returns an
48+
* empty list.
49+
*/
50+
default List<String> getList(@Nullable C carrier, String key) {
51+
String first = get(carrier, key);
52+
return first == null ? Collections.emptyList() : Collections.singletonList(first);
53+
}
3654
}

0 commit comments

Comments
 (0)