diff --git a/api/include/opentelemetry/trace/propagation/b3_propagator.h b/api/include/opentelemetry/trace/propagation/b3_propagator.h index f3063be157..93bf6556f4 100644 --- a/api/include/opentelemetry/trace/propagation/b3_propagator.h +++ b/api/include/opentelemetry/trace/propagation/b3_propagator.h @@ -37,19 +37,15 @@ static const int kSpanIdHexStrLength = 16; // headers of HTTP requests. HTTP frameworks and clients can integrate with B3Propagator by // providing the object containing the headers, and a getter function for the extraction. Based on: // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/api-propagators.md#b3-extract -template -class B3PropagatorExtractor : public TextMapPropagator + +class B3PropagatorExtractor : public TextMapPropagator { public: - // Rules that manages how context will be extracted from carrier. - using Getter = nostd::string_view (*)(const T &carrier, nostd::string_view trace_type); - - // Returns the context that is stored in the HTTP header carrier with the getter as extractor. - context::Context Extract(Getter getter, - const T &carrier, + // Returns the context that is stored in the HTTP header carrier. + context::Context Extract(const TextMapCarrier &carrier, context::Context &context) noexcept override { - SpanContext span_context = ExtractImpl(getter, carrier); + SpanContext span_context = ExtractImpl(carrier); nostd::shared_ptr sp{new DefaultSpan(span_context)}; return context.SetValue(kSpanKey, sp); } @@ -78,14 +74,14 @@ class B3PropagatorExtractor : public TextMapPropagator } private: - static SpanContext ExtractImpl(Getter getter, const T &carrier) + static SpanContext ExtractImpl(const TextMapCarrier &carrier) { nostd::string_view trace_id_hex; nostd::string_view span_id_hex; nostd::string_view trace_flags_hex; // first let's try a single-header variant - auto singleB3Header = getter(carrier, kB3CombinedHeader); + auto singleB3Header = carrier.Get(kB3CombinedHeader); if (!singleB3Header.empty()) { std::array fields{}; @@ -101,9 +97,9 @@ class B3PropagatorExtractor : public TextMapPropagator } else { - trace_id_hex = getter(carrier, kB3TraceIdHeader); - span_id_hex = getter(carrier, kB3SpanIdHeader); - trace_flags_hex = getter(carrier, kB3SampledHeader); + trace_id_hex = carrier.Get(kB3TraceIdHeader); + span_id_hex = carrier.Get(kB3SpanIdHeader); + trace_flags_hex = carrier.Get(kB3SampledHeader); } if (!detail::IsValidHex(trace_id_hex) || !detail::IsValidHex(span_id_hex)) @@ -125,16 +121,11 @@ class B3PropagatorExtractor : public TextMapPropagator // The B3Propagator class provides interface that enables extracting and injecting context into // single header of HTTP Request. -template -class B3Propagator : public B3PropagatorExtractor +class B3Propagator : public B3PropagatorExtractor { public: - // Rules that manages how context will be injected to carrier. - using Setter = void (*)(T &carrier, - nostd::string_view trace_type, - nostd::string_view trace_description); // Sets the context for a HTTP header carrier with self defined rules. - void Inject(Setter setter, T &carrier, const context::Context &context) noexcept override + void Inject(TextMapCarrier &carrier, const context::Context &context) noexcept override { SpanContext span_context = detail::GetCurrentSpan(context); if (!span_context.IsValid()) @@ -152,19 +143,14 @@ class B3Propagator : public B3PropagatorExtractor trace_identity[kTraceIdHexStrLength + kSpanIdHexStrLength + 2] = span_context.trace_flags().IsSampled() ? '1' : '0'; - setter(carrier, kB3CombinedHeader, nostd::string_view(trace_identity, sizeof(trace_identity))); + carrier.Set(kB3CombinedHeader, nostd::string_view(trace_identity, sizeof(trace_identity))); } }; -template -class B3PropagatorMultiHeader : public B3PropagatorExtractor +class B3PropagatorMultiHeader : public B3PropagatorExtractor { public: - // Rules that manages how context will be injected to carrier. - using Setter = void (*)(T &carrier, - nostd::string_view trace_type, - nostd::string_view trace_description); - void Inject(Setter setter, T &carrier, const context::Context &context) noexcept override + void Inject(TextMapCarrier &carrier, const context::Context &context) noexcept override { SpanContext span_context = detail::GetCurrentSpan(context); if (!span_context.IsValid()) @@ -177,9 +163,9 @@ class B3PropagatorMultiHeader : public B3PropagatorExtractor SpanId(span_context.span_id()).ToLowerBase16(span_id); char trace_flags[2]; TraceFlags(span_context.trace_flags()).ToLowerBase16(trace_flags); - setter(carrier, kB3TraceIdHeader, nostd::string_view(trace_id, sizeof(trace_id))); - setter(carrier, kB3SpanIdHeader, nostd::string_view(span_id, sizeof(span_id))); - setter(carrier, kB3SampledHeader, nostd::string_view(trace_flags + 1, 1)); + carrier.Set(kB3TraceIdHeader, nostd::string_view(trace_id, sizeof(trace_id))); + carrier.Set(kB3SpanIdHeader, nostd::string_view(span_id, sizeof(span_id))); + carrier.Set(kB3SampledHeader, nostd::string_view(trace_flags + 1, 1)); } }; diff --git a/api/include/opentelemetry/trace/propagation/composite_propagator.h b/api/include/opentelemetry/trace/propagation/composite_propagator.h index 7d9d9adfa0..b29e00e9b7 100644 --- a/api/include/opentelemetry/trace/propagation/composite_propagator.h +++ b/api/include/opentelemetry/trace/propagation/composite_propagator.h @@ -9,20 +9,12 @@ namespace trace namespace propagation { -template -class CompositePropagator : public TextMapPropagator +class CompositePropagator : public TextMapPropagator { public: - CompositePropagator(std::vector>> propagators) + CompositePropagator(std::vector> propagators) : propagators_(std::move(propagators)) {} - // Rules that manages how context will be extracted from carrier. - using Getter = nostd::string_view (*)(const T &carrier, nostd::string_view trace_type); - - // Rules that manages how context will be injected to carrier. - using Setter = void (*)(T &carrier, - nostd::string_view trace_type, - nostd::string_view trace_description); /** * Run each of the configured propagators with the given context and carrier. @@ -30,17 +22,16 @@ class CompositePropagator : public TextMapPropagator * propagators write the same carrier key, the propagator later in the list * will "win". * - * @param setter Rules that manages how context will be injected to carrier. * @param carrier Carrier into which context will be injected * @param context Context to inject * */ - void Inject(Setter setter, T &carrier, const context::Context &context) noexcept override + void Inject(TextMapCarrier &carrier, const context::Context &context) noexcept override { for (auto &p : propagators_) { - p->Inject(setter, carrier, context); + p->Inject(carrier, context); } } @@ -50,12 +41,10 @@ class CompositePropagator : public TextMapPropagator * propagators write the same context key, the propagator later in the list * will "win". * - * @param setter Rules that manages how context will be extracte from carrier. - * @param context Context to add values to * @param carrier Carrier from which to extract context + * @param context Context to add values to */ - context::Context Extract(Getter getter, - const T &carrier, + context::Context Extract(const TextMapCarrier &carrier, context::Context &context) noexcept override { auto first = true; @@ -64,19 +53,19 @@ class CompositePropagator : public TextMapPropagator { if (first) { - tmp_context = p->Extract(getter, carrier, context); + tmp_context = p->Extract(carrier, context); first = false; } else { - tmp_context = p->Extract(getter, carrier, tmp_context); + tmp_context = p->Extract(carrier, tmp_context); } } return propagators_.size() ? tmp_context : context; } private: - std::vector>> propagators_; + std::vector> propagators_; }; } // namespace propagation } // namespace trace diff --git a/api/include/opentelemetry/trace/propagation/global_propagator.h b/api/include/opentelemetry/trace/propagation/global_propagator.h new file mode 100644 index 0000000000..1c1dcc8071 --- /dev/null +++ b/api/include/opentelemetry/trace/propagation/global_propagator.h @@ -0,0 +1,66 @@ +// Copyright 2021, OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +#include "opentelemetry/trace/propagation/noop_propagator.h" +#include "opentelemetry/trace/propagation/text_map_propagator.h" + +#include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/nostd/shared_ptr.h" + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace trace +{ +namespace propagation +{ + +/* Stores the singleton TextMapPropagator */ + +class GlobalTextMapPropagator +{ +public: + static nostd::shared_ptr GetGlobalPropagator() noexcept + { + std::lock_guard guard(GetLock()); + return nostd::shared_ptr(GetPropagator()); + } + + static void SetGlobalPropagator(nostd::shared_ptr prop) noexcept + { + std::lock_guard guard(GetLock()); + GetPropagator() = prop; + } + +private: + static nostd::shared_ptr &GetPropagator() noexcept + { + static nostd::shared_ptr propagator(new NoOpPropagator()); + return propagator; + } + + static common::SpinLockMutex &GetLock() noexcept + { + static common::SpinLockMutex lock; + return lock; + } +}; + +} // namespace propagation +} // namespace trace +OPENTELEMETRY_END_NAMESPACE \ No newline at end of file diff --git a/api/include/opentelemetry/trace/propagation/http_trace_context.h b/api/include/opentelemetry/trace/propagation/http_trace_context.h index b1cc53d215..f0ca885a64 100644 --- a/api/include/opentelemetry/trace/propagation/http_trace_context.h +++ b/api/include/opentelemetry/trace/propagation/http_trace_context.h @@ -36,33 +36,24 @@ static const size_t kTraceParentSize = 55; // Example: // HttpTraceContext().inject(setter, carrier, context); // HttpTraceContext().extract(getter, carrier, context); -template -class HttpTraceContext : public TextMapPropagator + +class HttpTraceContext : public TextMapPropagator { public: - // Rules that manages how context will be extracted from carrier. - using Getter = nostd::string_view (*)(const T &carrier, nostd::string_view trace_type); - - // Rules that manages how context will be injected to carrier. - using Setter = void (*)(T &carrier, - nostd::string_view trace_type, - nostd::string_view trace_description); - - void Inject(Setter setter, T &carrier, const context::Context &context) noexcept override + void Inject(TextMapCarrier &carrier, const context::Context &context) noexcept override { SpanContext span_context = detail::GetCurrentSpan(context); if (!span_context.IsValid()) { return; } - InjectImpl(setter, carrier, span_context); + InjectImpl(carrier, span_context); } - context::Context Extract(Getter getter, - const T &carrier, + context::Context Extract(const TextMapCarrier &carrier, context::Context &context) noexcept override { - SpanContext span_context = ExtractImpl(getter, carrier); + SpanContext span_context = ExtractImpl(carrier); nostd::shared_ptr sp{new DefaultSpan(span_context)}; return context.SetValue(kSpanKey, sp); } @@ -98,7 +89,7 @@ class HttpTraceContext : public TextMapPropagator return version != kInvalidVersion; } - static void InjectImpl(Setter setter, T &carrier, const SpanContext &span_context) + static void InjectImpl(TextMapCarrier &carrier, const SpanContext &span_context) { char trace_parent[kTraceParentSize]; trace_parent[0] = '0'; @@ -110,8 +101,8 @@ class HttpTraceContext : public TextMapPropagator trace_parent[kTraceIdSize + kSpanIdSize + 4] = '-'; span_context.trace_flags().ToLowerBase16({&trace_parent[kTraceIdSize + kSpanIdSize + 5], 2}); - setter(carrier, kTraceParent, nostd::string_view(trace_parent, sizeof(trace_parent))); - setter(carrier, kTraceState, span_context.trace_state()->ToHeader()); + carrier.Set(kTraceParent, nostd::string_view(trace_parent, sizeof(trace_parent))); + carrier.Set(kTraceState, span_context.trace_state()->ToHeader()); } static SpanContext ExtractContextFromTraceHeaders(nostd::string_view trace_parent, @@ -162,10 +153,10 @@ class HttpTraceContext : public TextMapPropagator opentelemetry::trace::TraceState::FromHeader(trace_state)); } - static SpanContext ExtractImpl(Getter getter, const T &carrier) + static SpanContext ExtractImpl(const TextMapCarrier &carrier) { - nostd::string_view trace_parent = getter(carrier, kTraceParent); - nostd::string_view trace_state = getter(carrier, kTraceState); + nostd::string_view trace_parent = carrier.Get(kTraceParent); + nostd::string_view trace_state = carrier.Get(kTraceState); if (trace_parent == "") { return SpanContext::GetInvalid(); diff --git a/api/include/opentelemetry/trace/propagation/jaeger.h b/api/include/opentelemetry/trace/propagation/jaeger.h index 6d242accf8..1f961de5d9 100644 --- a/api/include/opentelemetry/trace/propagation/jaeger.h +++ b/api/include/opentelemetry/trace/propagation/jaeger.h @@ -28,17 +28,10 @@ namespace propagation static const nostd::string_view kTraceHeader = "uber-trace-id"; -template -class JaegerPropagator : public TextMapPropagator +class JaegerPropagator : public TextMapPropagator { public: - using Getter = nostd::string_view (*)(const T &carrier, nostd::string_view trace_type); - - using Setter = void (*)(T &carrier, - nostd::string_view trace_type, - nostd::string_view trace_description); - - void Inject(Setter setter, T &carrier, const context::Context &context) noexcept override + void Inject(TextMapCarrier &carrier, const context::Context &context) noexcept override { SpanContext span_context = detail::GetCurrentSpan(context); if (!span_context.IsValid()) @@ -60,14 +53,13 @@ class JaegerPropagator : public TextMapPropagator trace_identity[trace_id_length + span_id_length + 4] = '0'; trace_identity[trace_id_length + span_id_length + 5] = span_context.IsSampled() ? '1' : '0'; - setter(carrier, kTraceHeader, nostd::string_view(trace_identity, sizeof(trace_identity))); + carrier.Set(kTraceHeader, nostd::string_view(trace_identity, sizeof(trace_identity))); } - context::Context Extract(Getter getter, - const T &carrier, + context::Context Extract(const TextMapCarrier &carrier, context::Context &context) noexcept override { - SpanContext span_context = ExtractImpl(getter, carrier); + SpanContext span_context = ExtractImpl(carrier); nostd::shared_ptr sp{new DefaultSpan(span_context)}; return context.SetValue(kSpanKey, sp); } @@ -81,9 +73,9 @@ class JaegerPropagator : public TextMapPropagator return TraceFlags(sampled); } - static SpanContext ExtractImpl(Getter getter, const T &carrier) + static SpanContext ExtractImpl(const TextMapCarrier &carrier) { - nostd::string_view trace_identity = getter(carrier, kTraceHeader); + nostd::string_view trace_identity = carrier.Get(kTraceHeader); const size_t trace_field_count = 4; nostd::string_view trace_fields[trace_field_count]; diff --git a/api/include/opentelemetry/trace/propagation/noop_propagator.h b/api/include/opentelemetry/trace/propagation/noop_propagator.h new file mode 100644 index 0000000000..391621e88f --- /dev/null +++ b/api/include/opentelemetry/trace/propagation/noop_propagator.h @@ -0,0 +1,30 @@ +#pragma once + +#include "opentelemetry/trace/propagation/text_map_propagator.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace trace +{ +namespace propagation +{ + +/** + * No-op implementation TextMapPropagator + */ +class NoOpPropagator : public TextMapPropagator +{ +public: + /** Noop extract function does nothing and returns the input context */ + context::Context Extract(const TextMapCarrier & /*carrier*/, + context::Context &context) noexcept override + { + return context; + } + + /** Noop inject function does nothing */ + void Inject(TextMapCarrier & /*carrier*/, const context::Context &context) noexcept override {} +}; +} // namespace propagation +} // namespace trace +OPENTELEMETRY_END_NAMESPACE \ No newline at end of file diff --git a/api/include/opentelemetry/trace/propagation/text_map_propagator.h b/api/include/opentelemetry/trace/propagation/text_map_propagator.h index 263e3a1d6f..c336fe89e1 100644 --- a/api/include/opentelemetry/trace/propagation/text_map_propagator.h +++ b/api/include/opentelemetry/trace/propagation/text_map_propagator.h @@ -11,32 +11,32 @@ namespace trace namespace propagation { +// TextMapCarrier is the storage medium used by TextMapPropagator. +class TextMapCarrier +{ +public: + /*returns the value associated with the passed key.*/ + virtual nostd::string_view Get(nostd::string_view key) const noexcept = 0; + + /*stores the key-value pair.*/ + virtual void Set(nostd::string_view key, nostd::string_view value) noexcept = 0; +}; + // The TextMapPropagator class provides an interface that enables extracting and injecting // context into carriers that travel in-band across process boundaries. HTTP frameworks and clients // can integrate with TextMapPropagator by providing the object containing the // headers, and a getter and setter function for the extraction and // injection of values, respectively. -template + class TextMapPropagator { public: - // Rules that manages how context will be extracted from carrier. - using Getter = nostd::string_view (*)(const T &carrier, nostd::string_view trace_type); - - // Rules that manages how context will be injected to carrier. - using Setter = void (*)(T &carrier, - nostd::string_view trace_type, - nostd::string_view trace_description); - - // Returns the context that is stored in the carrier with the getter as extractor. - virtual context::Context Extract(Getter get_from_carrier, - const T &carrier, + // Returns the context that is stored in the carrier with the TextMapCarrier as extractor. + virtual context::Context Extract(const TextMapCarrier &carrier, context::Context &context) noexcept = 0; // Sets the context for carrier with self defined rules. - virtual void Inject(Setter set_from_carrier, - T &carrier, - const context::Context &context) noexcept = 0; + virtual void Inject(TextMapCarrier &carrier, const context::Context &context) noexcept = 0; }; } // namespace propagation } // namespace trace diff --git a/api/test/trace/propagation/b3_propagation_test.cc b/api/test/trace/propagation/b3_propagation_test.cc index d1bacaec8c..6c02fe9f42 100644 --- a/api/test/trace/propagation/b3_propagation_test.cc +++ b/api/test/trace/propagation/b3_propagation_test.cc @@ -9,30 +9,31 @@ using namespace opentelemetry; -static nostd::string_view Getter(const std::map &carrier, - nostd::string_view key) +class TextMapCarrierTest : public trace::propagation::TextMapCarrier { - auto it = carrier.find(std::string(key)); - if (it != carrier.end()) +public: + virtual nostd::string_view Get(nostd::string_view key) const noexcept override { - return nostd::string_view(it->second); + auto it = headers_.find(std::string(key)); + if (it != headers_.end()) + { + return nostd::string_view(it->second); + } + return ""; + } + virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + { + headers_[std::string(key)] = std::string(value); } - return ""; -} -static void Setter(std::map &carrier, - nostd::string_view key, - nostd::string_view value = "") -{ - carrier[std::string(key)] = std::string(value); -} + std::map headers_; +}; -using MapB3Context = trace::propagation::B3Propagator>; +using MapB3Context = trace::propagation::B3Propagator; static MapB3Context format = MapB3Context(); -using MapB3ContextMultiHeader = - trace::propagation::B3PropagatorMultiHeader>; +using MapB3ContextMultiHeader = trace::propagation::B3PropagatorMultiHeader; static MapB3ContextMultiHeader formatMultiHeader = MapB3ContextMultiHeader(); @@ -45,20 +46,20 @@ TEST(B3PropagationTest, TraceFlagsBufferGeneration) TEST(B3PropagationTest, PropagateInvalidContext) { // Do not propagate invalid trace context. - std::map carrier = {}; + TextMapCarrierTest carrier; context::Context ctx{ "current-span", nostd::shared_ptr(new trace::DefaultSpan(trace::SpanContext::GetInvalid()))}; - format.Inject(Setter, carrier, ctx); - EXPECT_TRUE(carrier.count("b3") == 0); + format.Inject(carrier, ctx); + EXPECT_TRUE(carrier.headers_.count("b3") == 0); } TEST(B3PropagationTest, ExtractInvalidContext) { - const std::map carrier = { - {"b3", "00000000000000000000000000000000-0000000000000000-0"}}; + TextMapCarrierTest carrier; + carrier.headers_ = {{"b3", "00000000000000000000000000000000-0000000000000000-0"}}; context::Context ctx1 = context::Context{}; - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); + context::Context ctx2 = format.Extract(carrier, ctx1); auto ctx2_span = ctx2.GetValue(trace::kSpanKey); auto span = nostd::get>(ctx2_span); EXPECT_EQ(span->GetContext().IsRemote(), false); @@ -66,10 +67,10 @@ TEST(B3PropagationTest, ExtractInvalidContext) TEST(B3PropagationTest, DoNotExtractWithInvalidHex) { - const std::map carrier = { - {"b3", "0000000zzz0000000000000000000000-0000000zzz000000-1"}}; + TextMapCarrierTest carrier; + carrier.headers_ = {{"b3", "0000000zzz0000000000000000000000-0000000zzz000000-1"}}; context::Context ctx1 = context::Context{}; - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); + context::Context ctx2 = format.Extract(carrier, ctx1); auto ctx2_span = ctx2.GetValue(trace::kSpanKey); auto span = nostd::get>(ctx2_span); EXPECT_EQ(span->GetContext().IsRemote(), false); @@ -77,10 +78,11 @@ TEST(B3PropagationTest, DoNotExtractWithInvalidHex) TEST(B3PropagationTest, SetRemoteSpan) { - const std::map carrier = { + TextMapCarrierTest carrier; + carrier.headers_ = { {"b3", "80f198ee56343ba864fe8b2a57d3eff7-e457b5a2e4d86bd1-1-05e3ac9a4f6e3b90"}}; context::Context ctx1 = context::Context{}; - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); + context::Context ctx2 = format.Extract(carrier, ctx1); auto ctx2_span = ctx2.GetValue(trace::kSpanKey); EXPECT_TRUE(nostd::holds_alternative>(ctx2_span)); @@ -95,10 +97,10 @@ TEST(B3PropagationTest, SetRemoteSpan) TEST(B3PropagationTest, SetRemoteSpan_TraceIdShort) { - const std::map carrier = { - {"b3", "80f198ee56343ba8-e457b5a2e4d86bd1-1-05e3ac9a4f6e3b90"}}; + TextMapCarrierTest carrier; + carrier.headers_ = {{"b3", "80f198ee56343ba8-e457b5a2e4d86bd1-1-05e3ac9a4f6e3b90"}}; context::Context ctx1 = context::Context{}; - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); + context::Context ctx2 = format.Extract(carrier, ctx1); auto ctx2_span = ctx2.GetValue(trace::kSpanKey); EXPECT_TRUE(nostd::holds_alternative>(ctx2_span)); @@ -113,10 +115,10 @@ TEST(B3PropagationTest, SetRemoteSpan_TraceIdShort) TEST(B3PropagationTest, SetRemoteSpan_SingleHeaderNoFlags) { - const std::map carrier = { - {"b3", "80f198ee56343ba864fe8b2a57d3eff7-e457b5a2e4d86bd1"}}; + TextMapCarrierTest carrier; + carrier.headers_ = {{"b3", "80f198ee56343ba864fe8b2a57d3eff7-e457b5a2e4d86bd1"}}; context::Context ctx1 = context::Context{}; - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); + context::Context ctx2 = format.Extract(carrier, ctx1); auto ctx2_span = ctx2.GetValue(trace::kSpanKey); EXPECT_TRUE(nostd::holds_alternative>(ctx2_span)); @@ -131,12 +133,12 @@ TEST(B3PropagationTest, SetRemoteSpan_SingleHeaderNoFlags) TEST(B3PropagationTest, SetRemoteSpanMultiHeader) { - const std::map carrier = { - {"X-B3-TraceId", "80f198ee56343ba864fe8b2a57d3eff7"}, - {"X-B3-SpanId", "e457b5a2e4d86bd1"}, - {"X-B3-Sampled", "1"}}; + TextMapCarrierTest carrier; + carrier.headers_ = {{"X-B3-TraceId", "80f198ee56343ba864fe8b2a57d3eff7"}, + {"X-B3-SpanId", "e457b5a2e4d86bd1"}, + {"X-B3-Sampled", "1"}}; context::Context ctx1 = context::Context{}; - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); + context::Context ctx2 = format.Extract(carrier, ctx1); auto ctx2_span = ctx2.GetValue(trace::kSpanKey); EXPECT_TRUE(nostd::holds_alternative>(ctx2_span)); @@ -151,6 +153,7 @@ TEST(B3PropagationTest, SetRemoteSpanMultiHeader) TEST(B3PropagationTest, GetCurrentSpan) { + TextMapCarrierTest carrier; constexpr uint8_t buf_span[] = {1, 2, 3, 4, 5, 6, 7, 8}; constexpr uint8_t buf_trace[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; trace::SpanContext span_context{trace::TraceId{buf_trace}, trace::SpanId{buf_span}, @@ -160,13 +163,13 @@ TEST(B3PropagationTest, GetCurrentSpan) // Set `sp` as the currently active span, which must be used by `Inject`. trace::Scope scoped_span{sp}; - std::map headers = {}; - format.Inject(Setter, headers, context::RuntimeContext::GetCurrent()); - EXPECT_EQ(headers["b3"], "0102030405060708090a0b0c0d0e0f10-0102030405060708-1"); + format.Inject(carrier, context::RuntimeContext::GetCurrent()); + EXPECT_EQ(carrier.headers_["b3"], "0102030405060708090a0b0c0d0e0f10-0102030405060708-1"); } TEST(B3PropagationTest, GetCurrentSpanMultiHeader) { + TextMapCarrierTest carrier; constexpr uint8_t buf_span[] = {1, 2, 3, 4, 5, 6, 7, 8}; constexpr uint8_t buf_trace[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; trace::SpanContext span_context{trace::TraceId{buf_trace}, trace::SpanId{buf_span}, @@ -176,9 +179,8 @@ TEST(B3PropagationTest, GetCurrentSpanMultiHeader) // Set `sp` as the currently active span, which must be used by `Inject`. trace::Scope scoped_span{sp}; - std::map headers = {}; - formatMultiHeader.Inject(Setter, headers, context::RuntimeContext::GetCurrent()); - EXPECT_EQ(headers["X-B3-TraceId"], "0102030405060708090a0b0c0d0e0f10"); - EXPECT_EQ(headers["X-B3-SpanId"], "0102030405060708"); - EXPECT_EQ(headers["X-B3-Sampled"], "1"); + formatMultiHeader.Inject(carrier, context::RuntimeContext::GetCurrent()); + EXPECT_EQ(carrier.headers_["X-B3-TraceId"], "0102030405060708090a0b0c0d0e0f10"); + EXPECT_EQ(carrier.headers_["X-B3-SpanId"], "0102030405060708"); + EXPECT_EQ(carrier.headers_["X-B3-Sampled"], "1"); } diff --git a/api/test/trace/propagation/composite_propagator_test.cc b/api/test/trace/propagation/composite_propagator_test.cc index ab038bd229..0339f1fd66 100644 --- a/api/test/trace/propagation/composite_propagator_test.cc +++ b/api/test/trace/propagation/composite_propagator_test.cc @@ -25,68 +25,58 @@ static std::string Hex(const T &id_item) return std::string(buf, sizeof(buf)); } -static nostd::string_view Getter(const std::map &carrier, - nostd::string_view trace_type) +class TextMapCarrierTest : public trace::propagation::TextMapCarrier { - auto it = carrier.find(std::string(trace_type)); - if (it != carrier.end()) +public: + virtual nostd::string_view Get(nostd::string_view key) const noexcept override { - return nostd::string_view(it->second); + auto it = headers_.find(std::string(key)); + if (it != headers_.end()) + { + return nostd::string_view(it->second); + } + return ""; + } + virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + { + headers_[std::string(key)] = std::string(value); } - return ""; -} - -static void Setter(std::map &carrier, - nostd::string_view trace_type, - nostd::string_view trace_description = "") -{ - carrier[std::string(trace_type)] = std::string(trace_description); -} -using MapHttpTraceContext = - trace::propagation::HttpTraceContext>; -using MapB3Context = trace::propagation::B3Propagator>; -using MapCompositePropagator = - trace::propagation::CompositePropagator>; + std::map headers_; +}; class CompositePropagatorTest : public ::testing::Test { - using MapHttpTraceContext = - trace::propagation::HttpTraceContext>; - - using MapB3Context = trace::propagation::B3Propagator>; - using MapCompositePropagator = - trace::propagation::CompositePropagator>; public: CompositePropagatorTest() { - std::vector< - std::unique_ptr>>> - propogator_list = {}; - std::unique_ptr tc_propogator(new MapHttpTraceContext()); - std::unique_ptr b3_propogator(new MapB3Context()); - propogator_list.push_back(std::move(tc_propogator)); + std::vector> propogator_list = {}; + std::unique_ptr w3c_propogator( + new trace::propagation::HttpTraceContext()); + std::unique_ptr b3_propogator( + new trace::propagation::B3Propagator()); + propogator_list.push_back(std::move(w3c_propogator)); propogator_list.push_back(std::move(b3_propogator)); - composite_propagator_ = new MapCompositePropagator(std::move(propogator_list)); + composite_propagator_ = new trace::propagation::CompositePropagator(std::move(propogator_list)); } ~CompositePropagatorTest() { delete composite_propagator_; } protected: - MapCompositePropagator *composite_propagator_; + trace::propagation::CompositePropagator *composite_propagator_; }; TEST_F(CompositePropagatorTest, Extract) { - - const std::map carrier = { + TextMapCarrierTest carrier; + carrier.headers_ = { {"traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"}, {"b3", "80f198ee56343ba864fe8b2a57d3eff7-e457b5a2e4d86bd1-1-05e3ac9a4f6e3b90"}}; context::Context ctx1 = context::Context{}; - context::Context ctx2 = composite_propagator_->Extract(Getter, carrier, ctx1); + context::Context ctx2 = composite_propagator_->Extract(carrier, ctx1); auto ctx2_span = ctx2.GetValue(trace::kSpanKey); EXPECT_TRUE(nostd::holds_alternative>(ctx2_span)); @@ -103,7 +93,7 @@ TEST_F(CompositePropagatorTest, Extract) TEST_F(CompositePropagatorTest, Inject) { - + TextMapCarrierTest carrier; constexpr uint8_t buf_span[] = {1, 2, 3, 4, 5, 6, 7, 8}; constexpr uint8_t buf_trace[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; trace::SpanContext span_context{trace::TraceId{buf_trace}, trace::SpanId{buf_span}, @@ -113,8 +103,8 @@ TEST_F(CompositePropagatorTest, Inject) // Set `sp` as the currently active span, which must be used by `Inject`. trace::Scope scoped_span{sp}; - std::map headers = {}; - composite_propagator_->Inject(Setter, headers, context::RuntimeContext::GetCurrent()); - EXPECT_EQ(headers["traceparent"], "00-0102030405060708090a0b0c0d0e0f10-0102030405060708-01"); - EXPECT_EQ(headers["b3"], "0102030405060708090a0b0c0d0e0f10-0102030405060708-1"); + composite_propagator_->Inject(carrier, context::RuntimeContext::GetCurrent()); + EXPECT_EQ(carrier.headers_["traceparent"], + "00-0102030405060708090a0b0c0d0e0f10-0102030405060708-01"); + EXPECT_EQ(carrier.headers_["b3"], "0102030405060708090a0b0c0d0e0f10-0102030405060708-1"); } diff --git a/api/test/trace/propagation/http_text_format_test.cc b/api/test/trace/propagation/http_text_format_test.cc index c0dff1c17f..e7d873117d 100644 --- a/api/test/trace/propagation/http_text_format_test.cc +++ b/api/test/trace/propagation/http_text_format_test.cc @@ -1,34 +1,37 @@ #include "opentelemetry/context/runtime_context.h" +#include "opentelemetry/trace/propagation/global_propagator.h" #include "opentelemetry/trace/propagation/http_trace_context.h" #include "opentelemetry/trace/scope.h" #include "util.h" #include +#include #include using namespace opentelemetry; -static nostd::string_view Getter(const std::map &carrier, - nostd::string_view trace_type = "traceparent") +class TextMapCarrierTest : public trace::propagation::TextMapCarrier { - auto it = carrier.find(std::string(trace_type)); - if (it != carrier.end()) +public: + virtual nostd::string_view Get(nostd::string_view key) const noexcept override { - return nostd::string_view(it->second); + auto it = headers_.find(std::string(key)); + if (it != headers_.end()) + { + return nostd::string_view(it->second); + } + return ""; + } + virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + { + headers_[std::string(key)] = std::string(value); } - return ""; -} -static void Setter(std::map &carrier, - nostd::string_view trace_type = "traceparent", - nostd::string_view trace_description = "") -{ - carrier[std::string(trace_type)] = std::string(trace_description); -} + std::map headers_; +}; -using MapHttpTraceContext = - trace::propagation::HttpTraceContext>; +using MapHttpTraceContext = trace::propagation::HttpTraceContext; static MapHttpTraceContext format = MapHttpTraceContext(); @@ -40,53 +43,54 @@ TEST(TextMapPropagatorTest, TraceFlagsBufferGeneration) TEST(TextMapPropagatorTest, NoSendEmptyTraceState) { // If the trace state is empty, do not set the header. - const std::map carrier = { - {"traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"}}; + TextMapCarrierTest carrier; + carrier.headers_ = {{"traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"}}; context::Context ctx1 = context::Context{ "current-span", nostd::shared_ptr(new trace::DefaultSpan(trace::SpanContext::GetInvalid()))}; - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); - std::map c2 = {}; - format.Inject(Setter, c2, ctx2); - EXPECT_TRUE(carrier.count("traceparent") > 0); - EXPECT_FALSE(carrier.count("tracestate") > 0); + context::Context ctx2 = format.Extract(carrier, ctx1); + TextMapCarrierTest carrier2; + format.Inject(carrier2, ctx2); + EXPECT_TRUE(carrier.headers_.count("traceparent") > 0); + EXPECT_FALSE(carrier.headers_.count("tracestate") > 0); } TEST(TextMapPropagatorTest, PropogateTraceState) { - const std::map carrier = { - {"traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"}, - {"tracestate", "congo=t61rcWkgMzE"}}; + TextMapCarrierTest carrier; + carrier.headers_ = {{"traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"}, + {"tracestate", "congo=t61rcWkgMzE"}}; context::Context ctx1 = context::Context{ "current-span", nostd::shared_ptr(new trace::DefaultSpan(trace::SpanContext::GetInvalid()))}; - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); - std::map c2 = {}; - format.Inject(Setter, c2, ctx2); + context::Context ctx2 = format.Extract(carrier, ctx1); + + TextMapCarrierTest carrier2; + format.Inject(carrier2, ctx2); - EXPECT_TRUE(carrier.count("traceparent") > 0); - EXPECT_TRUE(carrier.count("tracestate") > 0); - EXPECT_EQ(c2["tracestate"], "congo=t61rcWkgMzE"); + EXPECT_TRUE(carrier.headers_.count("traceparent") > 0); + EXPECT_TRUE(carrier.headers_.count("tracestate") > 0); + EXPECT_EQ(carrier2.headers_["tracestate"], "congo=t61rcWkgMzE"); } TEST(TextMapPropagatorTest, PropagateInvalidContext) { // Do not propagate invalid trace context. - std::map carrier = {}; + TextMapCarrierTest carrier; context::Context ctx{ "current-span", nostd::shared_ptr(new trace::DefaultSpan(trace::SpanContext::GetInvalid()))}; - format.Inject(Setter, carrier, ctx); - EXPECT_TRUE(carrier.count("traceparent") == 0); - EXPECT_TRUE(carrier.count("tracestate") == 0); + format.Inject(carrier, ctx); + EXPECT_TRUE(carrier.headers_.count("traceparent") == 0); + EXPECT_TRUE(carrier.headers_.count("tracestate") == 0); } TEST(TextMapPropagatorTest, SetRemoteSpan) { - const std::map carrier = { - {"traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"}}; + TextMapCarrierTest carrier; + carrier.headers_ = {{"traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"}}; context::Context ctx1 = context::Context{}; - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); + context::Context ctx2 = format.Extract(carrier, ctx1); auto ctx2_span = ctx2.GetValue(trace::kSpanKey); EXPECT_TRUE(nostd::holds_alternative>(ctx2_span)); @@ -101,6 +105,7 @@ TEST(TextMapPropagatorTest, SetRemoteSpan) TEST(TextMapPropagatorTest, GetCurrentSpan) { + TextMapCarrierTest carrier; constexpr uint8_t buf_span[] = {1, 2, 3, 4, 5, 6, 7, 8}; constexpr uint8_t buf_trace[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; @@ -112,14 +117,15 @@ TEST(TextMapPropagatorTest, GetCurrentSpan) // Set `sp` as the currently active span, which must be used by `Inject`. trace::Scope scoped_span{sp}; - std::map headers = {}; - format.Inject(Setter, headers, context::RuntimeContext::GetCurrent()); - EXPECT_EQ(headers["traceparent"], "00-0102030405060708090a0b0c0d0e0f10-0102030405060708-01"); - EXPECT_EQ(headers["tracestate"], "congo=t61rcWkgMzE"); + format.Inject(carrier, context::RuntimeContext::GetCurrent()); + EXPECT_EQ(carrier.headers_["traceparent"], + "00-0102030405060708090a0b0c0d0e0f10-0102030405060708-01"); + EXPECT_EQ(carrier.headers_["tracestate"], "congo=t61rcWkgMzE"); } TEST(TextMapPropagatorTest, InvalidIdentitiesAreNotExtracted) { + TextMapCarrierTest carrier; std::vector traces = { "ff-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01", "00-0af7651916cd43dd8448eb211c80319c1-b9c7c989f97918e1-01", @@ -137,11 +143,56 @@ TEST(TextMapPropagatorTest, InvalidIdentitiesAreNotExtracted) for (auto &trace : traces) { - const std::map carrier = {{"traceparent", trace}}; - context::Context ctx1 = context::Context{}; - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); + carrier.headers_ = {{"traceparent", trace}}; + context::Context ctx1 = context::Context{}; + context::Context ctx2 = format.Extract(carrier, ctx1); auto span = trace::propagation::detail::GetCurrentSpan(ctx2); EXPECT_FALSE(span.IsValid()); } } + +TEST(GlobalTextMapPropagator, NoOpPropagator) +{ + + auto propagator = trace::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); + TextMapCarrierTest carrier; + + carrier.headers_ = {{"traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"}, + {"tracestate", "congo=t61rcWkgMzE"}}; + context::Context ctx1 = context::Context{ + "current-span", + nostd::shared_ptr(new trace::DefaultSpan(trace::SpanContext::GetInvalid()))}; + context::Context ctx2 = propagator->Extract(carrier, ctx1); + + TextMapCarrierTest carrier2; + propagator->Inject(carrier2, ctx2); + + EXPECT_TRUE(carrier2.headers_.count("tracestate") == 0); + EXPECT_TRUE(carrier2.headers_.count("traceparent") == 0); +} + +TEST(GlobalPropagator, SetAndGet) +{ + + auto trace_state_value = "congo=t61rcWkgMzE"; + trace::propagation::GlobalTextMapPropagator::SetGlobalPropagator( + nostd::shared_ptr(new MapHttpTraceContext())); + + auto propagator = trace::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); + + TextMapCarrierTest carrier; + carrier.headers_ = {{"traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"}, + {"tracestate", trace_state_value}}; + context::Context ctx1 = context::Context{ + "current-span", + nostd::shared_ptr(new trace::DefaultSpan(trace::SpanContext::GetInvalid()))}; + context::Context ctx2 = propagator->Extract(carrier, ctx1); + + TextMapCarrierTest carrier2; + propagator->Inject(carrier2, ctx2); + + EXPECT_TRUE(carrier.headers_.count("traceparent") > 0); + EXPECT_TRUE(carrier.headers_.count("tracestate") > 0); + EXPECT_EQ(carrier.headers_["tracestate"], trace_state_value); +} diff --git a/api/test/trace/propagation/jaeger_propagation_test.cc b/api/test/trace/propagation/jaeger_propagation_test.cc index c7125a84f1..0f8b604c7b 100644 --- a/api/test/trace/propagation/jaeger_propagation_test.cc +++ b/api/test/trace/propagation/jaeger_propagation_test.cc @@ -8,25 +8,27 @@ using namespace opentelemetry; -static nostd::string_view Getter(const std::map &carrier, - nostd::string_view trace_type = "uber-trace-id") +class TextMapCarrierTest : public trace::propagation::TextMapCarrier { - auto it = carrier.find(std::string(trace_type)); - if (it != carrier.end()) +public: + virtual nostd::string_view Get(nostd::string_view key) const noexcept override { - return nostd::string_view(it->second); + auto it = headers_.find(std::string(key)); + if (it != headers_.end()) + { + return nostd::string_view(it->second); + } + return ""; + } + virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + { + headers_[std::string(key)] = std::string(value); } - return ""; -} -static void Setter(std::map &carrier, - nostd::string_view trace_type = "uber-trace-id", - nostd::string_view trace_description = "") -{ - carrier[std::string(trace_type)] = std::string(trace_description); -} + std::map headers_; +}; -using Propagator = trace::propagation::JaegerPropagator>; +using Propagator = trace::propagation::JaegerPropagator; static Propagator format = Propagator(); @@ -88,9 +90,10 @@ TEST(JaegerPropagatorTest, ExtractValidSpans) for (TestTrace &test_trace : traces) { - const std::map carrier = {{"uber-trace-id", test_trace.trace_state}}; - context::Context ctx1 = context::Context{}; - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); + TextMapCarrierTest carrier; + carrier.headers_ = {{"uber-trace-id", test_trace.trace_state}}; + context::Context ctx1 = context::Context{}; + context::Context ctx2 = format.Extract(carrier, ctx1); auto span = trace::propagation::detail::GetCurrentSpan(ctx2); EXPECT_TRUE(span.IsValid()); @@ -104,6 +107,7 @@ TEST(JaegerPropagatorTest, ExtractValidSpans) TEST(JaegerPropagatorTest, ExctractInvalidSpans) { + TextMapCarrierTest carrier; std::vector traces = { "4bf92f3577b34da6a3ce929d0e0e47344:0102030405060708:0:00", // too long trace id "4bf92f3577b34da6a3ce929d0e0e4734:01020304050607089:0:00", // too long span id @@ -118,9 +122,9 @@ TEST(JaegerPropagatorTest, ExctractInvalidSpans) for (auto &trace : traces) { - const std::map carrier = {{"uber-trace-id", trace}}; - context::Context ctx1 = context::Context{}; - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); + carrier.headers_ = {{"uber-trace-id", trace}}; + context::Context ctx1 = context::Context{}; + context::Context ctx2 = format.Extract(carrier, ctx1); auto span = trace::propagation::detail::GetCurrentSpan(ctx2); EXPECT_FALSE(span.IsValid()); @@ -129,6 +133,7 @@ TEST(JaegerPropagatorTest, ExctractInvalidSpans) TEST(JaegerPropagatorTest, InjectsContext) { + TextMapCarrierTest carrier; constexpr uint8_t buf_span[] = {1, 2, 3, 4, 5, 6, 7, 8}; constexpr uint8_t buf_trace[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; trace::SpanContext span_context{trace::TraceId{buf_trace}, trace::SpanId{buf_span}, @@ -136,17 +141,17 @@ TEST(JaegerPropagatorTest, InjectsContext) nostd::shared_ptr sp{new trace::DefaultSpan{span_context}}; trace::Scope scoped_span{sp}; - std::map headers = {}; - format.Inject(Setter, headers, context::RuntimeContext::GetCurrent()); - EXPECT_EQ(headers["uber-trace-id"], "0102030405060708090a0b0c0d0e0f10:0102030405060708:0:01"); + format.Inject(carrier, context::RuntimeContext::GetCurrent()); + EXPECT_EQ(carrier.headers_["uber-trace-id"], + "0102030405060708090a0b0c0d0e0f10:0102030405060708:0:01"); } TEST(JaegerPropagatorTest, DoNotInjectInvalidContext) { - std::map carrier = {}; + TextMapCarrierTest carrier; context::Context ctx{ "current-span", nostd::shared_ptr(new trace::DefaultSpan(trace::SpanContext::GetInvalid()))}; - format.Inject(Setter, carrier, ctx); - EXPECT_TRUE(carrier.count("uber-trace-id") == 0); + format.Inject(carrier, ctx); + EXPECT_TRUE(carrier.headers_.count("uber-trace-id") == 0); } diff --git a/ext/test/w3c_tracecontext_test/main.cc b/ext/test/w3c_tracecontext_test/main.cc index fc26801079..d82ad401e4 100644 --- a/ext/test/w3c_tracecontext_test/main.cc +++ b/ext/test/w3c_tracecontext_test/main.cc @@ -13,26 +13,28 @@ namespace { -static opentelemetry::trace::propagation::HttpTraceContext> - propagator_format; +static opentelemetry::trace::propagation::HttpTraceContext propagator_format; -void Setter(std::map &carrier, - nostd::string_view trace_type = "traceparent", - nostd::string_view trace_description = "") +class TextMapCarrierTest : public opentelemetry::trace::propagation::TextMapCarrier { - carrier[std::string(trace_type)] = std::string(trace_description); -} - -nostd::string_view Getter(const std::map &carrier, - nostd::string_view trace_type = "traceparent") -{ - auto it = carrier.find(std::string(trace_type)); - if (it != carrier.end()) +public: + TextMapCarrierTest(std::map &headers) : headers_(headers) {} + virtual nostd::string_view Get(nostd::string_view key) const noexcept override { - return nostd::string_view(it->second); + auto it = headers_.find(std::string(key)); + if (it != headers_.end()) + { + return nostd::string_view(it->second); + } + return ""; } - return ""; -} + virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + { + headers_[std::string(key)] = std::string(value); + } + + std::map &headers_; +}; void initTracer() { @@ -109,7 +111,8 @@ void send_request(opentelemetry::ext::http::client::curl::HttpClient &client, request->AddHeader("Content-Length", std::to_string(body.size())); std::map headers; - propagator_format.Inject(Setter, headers, opentelemetry::context::RuntimeContext::GetCurrent()); + TextMapCarrierTest carrier(headers); + propagator_format.Inject(carrier, opentelemetry::context::RuntimeContext::GetCurrent()); for (auto const &hdr : headers) { @@ -155,8 +158,9 @@ int main(int argc, char *argv[]) for (auto &part : body) { + const TextMapCarrierTest carrier((std::map &)req.headers); auto current_ctx = opentelemetry::context::RuntimeContext::GetCurrent(); - auto ctx = propagator_format.Extract(Getter, req.headers, current_ctx); + auto ctx = propagator_format.Extract(carrier, current_ctx); auto token = opentelemetry::context::RuntimeContext::Attach(ctx); auto url = part["url"].get();