diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/jaegertracing/opentracing-cpp/example/tutorial/text_map_carrier.h | |
parent | Initial commit. (diff) | |
download | ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/jaegertracing/opentracing-cpp/example/tutorial/text_map_carrier.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/jaegertracing/opentracing-cpp/example/tutorial/text_map_carrier.h b/src/jaegertracing/opentracing-cpp/example/tutorial/text_map_carrier.h new file mode 100644 index 000000000..2538324d4 --- /dev/null +++ b/src/jaegertracing/opentracing-cpp/example/tutorial/text_map_carrier.h @@ -0,0 +1,37 @@ +#ifndef LIGHTSTEP_TEXT_MAP_CARRIER +#define LIGHTSTEP_TEXT_MAP_CARRIER + +#include <opentracing/propagation.h> +#include <string> +#include <unordered_map> + +using opentracing::expected; +using opentracing::string_view; +using opentracing::TextMapReader; +using opentracing::TextMapWriter; + +class TextMapCarrier : public TextMapReader, public TextMapWriter { + public: + TextMapCarrier(std::unordered_map<std::string, std::string>& text_map) + : text_map_(text_map) {} + + expected<void> Set(string_view key, string_view value) const override { + text_map_[key] = value; + return {}; + } + + expected<void> ForeachKey( + std::function<expected<void>(string_view key, string_view value)> f) + const override { + for (const auto& key_value : text_map_) { + auto result = f(key_value.first, key_value.second); + if (!result) return result; + } + return {}; + } + + private: + std::unordered_map<std::string, std::string>& text_map_; +}; + +#endif // LIGHTSTEP_TEXT_MAP_CARRIER |