@@ -80,6 +80,15 @@ const std::error_code invalid_carrier_error(2, propagation_error_category());
8080const std::error_code span_context_corrupted_error (
8181 3 , propagation_error_category());
8282
83+ // `key_not_found_error` occurs when TextMapReader::LookupKey fails to find
84+ // an entry for the provided key.
85+ const std::error_code key_not_found_error (4 , propagation_error_category());
86+
87+ // `lookup_key_not_supported_error` occurs when TextMapReader::LookupKey is
88+ // not supported for the provided key.
89+ const std::error_code lookup_key_not_supported_error (
90+ 5 , propagation_error_category());
91+
8392// TextMapWriter is the Inject() carrier for the TextMap builtin format. With
8493// it, the caller can encode a SpanContext for propagation as entries in a map
8594// of unicode strings.
@@ -89,6 +98,18 @@ class TextMapReader {
8998 public:
9099 virtual ~TextMapReader () = default ;
91100
101+ // LookupKey returns the value for the specified `key` if available. If no
102+ // such key is present, it returns `key_not_found_error`.
103+ //
104+ // TextMapReaders are not required to implement this method. If not supported,
105+ // the function returns `lookup_key_not_supported_error`.
106+ //
107+ // Tracers may use this as an alternative to `ForeachKey` as a faster way to
108+ // extract span context.
109+ virtual expected<string_view> LookupKey (string_view /* key*/ ) const {
110+ return make_unexpected (lookup_key_not_supported_error);
111+ }
112+
92113 // ForeachKey returns TextMap contents via repeated calls to the `f`
93114 // function. If any call to `f` returns an error, ForeachKey terminates and
94115 // returns that error.
0 commit comments