diff --git a/api/include/opentelemetry/trace/propagation/http_trace_context.h b/api/include/opentelemetry/trace/propagation/http_trace_context.h index bd39ba2e38..4b38786eea 100644 --- a/api/include/opentelemetry/trace/propagation/http_trace_context.h +++ b/api/include/opentelemetry/trace/propagation/http_trace_context.h @@ -156,20 +156,20 @@ class HttpTraceContext : public HTTPTextFormat } } - static void InjectTraceState(TraceState trace_state, T &carrier, Setter setter) - { - std::string trace_state_string = ""; - nostd::span entries = trace_state.Entries(); - Entry *entry = entries.data(); - while (entry != entries.end()) - { - if (entry != entries.begin()) - trace_state_string += ","; - trace_state_string += std::string(entry->GetKey()) + "=" + std::string(entry->GetValue()); - entry++; - } - setter(carrier, kTraceState, trace_state_string); - } +// static void InjectTraceState(TraceState trace_state, T &carrier, Setter setter) +// { +// std::string trace_state_string = ""; +// nostd::span entries = trace_state.Entries(); +// TraceState::Entry *entry = entries.data(); +// while (entry != entries.end()) +// { +// if (entry != entries.begin()) +// trace_state_string += ","; +// trace_state_string += std::string(entry->GetKey()) + "=" + std::string(entry->GetValue()); +// entry++; +// } +// setter(carrier, kTraceState, trace_state_string); +// } static void InjectTraceParent(const SpanContext &span_context, T &carrier, Setter setter) { @@ -201,10 +201,10 @@ class HttpTraceContext : public HTTPTextFormat static void InjectImpl(Setter setter, T &carrier, const SpanContext &span_context) { InjectTraceParent(span_context, carrier, setter); - if (!span_context.trace_state().empty()) - { - InjectTraceState(span_context.trace_state(), carrier, setter); - } +// if (!span_context.trace_state().empty()) +// { +// InjectTraceState(span_context.trace_state(), carrier, setter); +// } } static SpanContext ExtractContextFromTraceParent(nostd::string_view trace_parent) @@ -293,76 +293,76 @@ class HttpTraceContext : public HTTPTextFormat } } - static TraceState ExtractTraceState(nostd::string_view &trace_state_header) - { - TraceState trace_state = TraceState(); - int start_pos = -1; - int end_pos = -1; - int ctr_pos = -1; - int element_num = 0; - nostd::string_view key; - nostd::string_view val; - for (int i = 0; i < int(trace_state_header.length()); i++) - { - if (trace_state_header[i] == '\t') - continue; - else if (trace_state_header[i] == ',') - { - if (start_pos == -1 && end_pos == -1) - continue; - element_num++; - if (ctr_pos != -1) - { - key = trace_state_header.substr(start_pos, ctr_pos - start_pos + 1); - val = trace_state_header.substr(ctr_pos + 1, end_pos - ctr_pos); - if (key != "") - trace_state.Set(key, val); - } - ctr_pos = -1; - end_pos = -1; - start_pos = -1; - } - else if (trace_state_header[i] == '=') - { - ctr_pos = i; - } - else - { - end_pos = i; - if (start_pos == -1) - start_pos = i; - } - } - if (start_pos != -1 && end_pos != -1) - { - if (ctr_pos != -1) - { - key = trace_state_header.substr(start_pos, ctr_pos - start_pos + 1); - val = trace_state_header.substr(ctr_pos + 1, end_pos - ctr_pos); - if (key != "") - trace_state.Set(key, val); - } - element_num++; - } - - if (element_num >= kTraceStateMaxMembers) - { - return TraceState(); // too many k-v pairs will result in an invalid trace state - } - return trace_state; - } - - static void AddNewMember(TraceState &trace_state, nostd::string_view member) - { - for (int i = 0; i < int(member.length()); i++) - { - if (member[i] == '=') - { - trace_state.Set(member.substr(0, i), member.substr(i + 1, member.length() - i - 1)); - return; - } - } - } +// static TraceState ExtractTraceState(nostd::string_view &trace_state_header) +// { +// TraceState trace_state = TraceState(); +// int start_pos = -1; +// int end_pos = -1; +// int ctr_pos = -1; +// int element_num = 0; +// nostd::string_view key; +// nostd::string_view val; +// for (int i = 0; i < int(trace_state_header.length()); i++) +// { +// if (trace_state_header[i] == '\t') +// continue; +// else if (trace_state_header[i] == ',') +// { +// if (start_pos == -1 && end_pos == -1) +// continue; +// element_num++; +// if (ctr_pos != -1) +// { +// key = trace_state_header.substr(start_pos, ctr_pos - start_pos + 1); +// val = trace_state_header.substr(ctr_pos + 1, end_pos - ctr_pos); +// if (key != "") +// trace_state.Set(key, val); +// } +// ctr_pos = -1; +// end_pos = -1; +// start_pos = -1; +// } +// else if (trace_state_header[i] == '=') +// { +// ctr_pos = i; +// } +// else +// { +// end_pos = i; +// if (start_pos == -1) +// start_pos = i; +// } +// } +// if (start_pos != -1 && end_pos != -1) +// { +// if (ctr_pos != -1) +// { +// key = trace_state_header.substr(start_pos, ctr_pos - start_pos + 1); +// val = trace_state_header.substr(ctr_pos + 1, end_pos - ctr_pos); +// if (key != "") +// trace_state.Set(key, val); +// } +// element_num++; +// } +// +// if (element_num >= kTraceStateMaxMembers) +// { +// return TraceState(); // too many k-v pairs will result in an invalid trace state +// } +// return trace_state; +// } +// +// static void AddNewMember(TraceState &trace_state, nostd::string_view member) +// { +// for (int i = 0; i < int(member.length()); i++) +// { +// if (member[i] == '=') +// { +// trace_state.Set(member.substr(0, i), member.substr(i + 1, member.length() - i - 1)); +// return; +// } +// } +// } static SpanContext ExtractImpl(Getter getter, const T &carrier) { @@ -372,21 +372,21 @@ class HttpTraceContext : public HTTPTextFormat return SpanContext(false, false); } SpanContext context_from_parent_header = ExtractContextFromTraceParent(trace_parent); - if (!context_from_parent_header.IsValid()) - { - return context_from_parent_header; - } - - nostd::string_view trace_state_header = getter(carrier, kTraceState); +// if (!context_from_parent_header.IsValid()) +// { + return context_from_parent_header; +// } - if (trace_state_header == "" || trace_state_header.empty()) - { - return context_from_parent_header; - } - - TraceState trace_state = ExtractTraceState(trace_state_header); - return SpanContext(context_from_parent_header.trace_id(), context_from_parent_header.span_id(), - context_from_parent_header.trace_flags(), trace_state, true); +// nostd::string_view trace_state_header = getter(carrier, kTraceState); +// +// if (trace_state_header == "" || trace_state_header.empty()) +// { +// return context_from_parent_header; +// } +// +// TraceState trace_state = ExtractTraceState(trace_state_header); +// return SpanContext(context_from_parent_header.trace_id(), context_from_parent_header.span_id(), +// context_from_parent_header.trace_flags(), trace_state, true); } }; } // namespace propagation diff --git a/api/include/opentelemetry/trace/trace_state.h b/api/include/opentelemetry/trace/trace_state.h index 9822d9751f..4c7e8fcd92 100644 --- a/api/include/opentelemetry/trace/trace_state.h +++ b/api/include/opentelemetry/trace/trace_state.h @@ -1,95 +1,95 @@ -// Copyright 2020, 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 - -#include "opentelemetry/nostd/span.h" -#include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/nostd/unique_ptr.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace trace -{ - -/** - * TraceState carries tracing-system specific context in a list of key-value pairs. TraceState - * allows different vendors to propagate additional information and inter-operate with their legacy - * id formats. - * - * For more information, see the W3C Trace Context specification: - * https://www.w3.org/TR/trace-context - */ -class TraceState -{ -public: - static constexpr int kKeyMaxSize = 256; - static constexpr int kValueMaxSize = 256; - static constexpr int kMaxKeyValuePairs = 32; - - // Class to store key-value pairs. - class Entry - { - public: - Entry() noexcept = default; - - // Copy constructor. - Entry(const Entry ©); - - // Creates an Entry for a given key-value pair. - Entry(nostd::string_view key, nostd::string_view value) noexcept; - - nostd::string_view GetKey(); - nostd::string_view GetValue(); - - private: - // Store key and value as raw char pointers to avoid using std::string. - nostd::unique_ptr key_; - nostd::unique_ptr value_; - }; - - // An empty TraceState. - TraceState() noexcept : num_entries_(0) {} - - // Returns false if no such key, otherwise returns true and populates value. - bool Get(nostd::string_view key, nostd::string_view value) const noexcept { return false; } - - // Creates an Entry for the key-value pair and adds it to entries. - // If value is null, this function is a no-op. - void Set(nostd::string_view key, nostd::string_view value) const noexcept; - - // Returns true if there are no keys, false otherwise. - bool Empty() const noexcept { return true; } - - // Returns a span of all the entries. The TraceState object must outlive the span. - nostd::span Entries() const noexcept { return {}; } - - // Returns whether key is a valid key. See https://www.w3.org/TR/trace-context/#key - static bool IsValidKey(nostd::string_view key); - - // Returns whether value is a valid value. See https://www.w3.org/TR/trace-context/#value - static bool IsValidValue(nostd::string_view value); - -private: - // Store entries in a C-style array to avoid using std::array or std::vector. - Entry entries_[kMaxKeyValuePairs]; - - // Maintain the number of entries in entries_. Must be in the range [0, kMaxKeyValuePairs]. - int num_entries_; -}; - -} // namespace trace -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +//// Copyright 2020, 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 +// +//#include "opentelemetry/nostd/span.h" +//#include "opentelemetry/nostd/string_view.h" +//#include "opentelemetry/nostd/unique_ptr.h" +// +//OPENTELEMETRY_BEGIN_NAMESPACE +//namespace trace +//{ +// +///** +// * TraceState carries tracing-system specific context in a list of key-value pairs. TraceState +// * allows different vendors to propagate additional information and inter-operate with their legacy +// * id formats. +// * +// * For more information, see the W3C Trace Context specification: +// * https://www.w3.org/TR/trace-context +// */ +//class TraceState +//{ +//public: +// static constexpr int kKeyMaxSize = 256; +// static constexpr int kValueMaxSize = 256; +// static constexpr int kMaxKeyValuePairs = 32; +// +// // Class to store key-value pairs. +// class Entry +// { +// public: +// Entry() noexcept = default; +// +// // Copy constructor. +// Entry(const Entry ©); +// +// // Creates an Entry for a given key-value pair. +// Entry(nostd::string_view key, nostd::string_view value) noexcept; +// +// nostd::string_view GetKey(); +// nostd::string_view GetValue(); +// +// private: +// // Store key and value as raw char pointers to avoid using std::string. +// nostd::unique_ptr key_; +// nostd::unique_ptr value_; +// }; +// +// // An empty TraceState. +// TraceState() noexcept : num_entries_(0) {} +// +// // Returns false if no such key, otherwise returns true and populates value. +// bool Get(nostd::string_view key, nostd::string_view value) const noexcept { return false; } +// +// // Creates an Entry for the key-value pair and adds it to entries. +// // If value is null, this function is a no-op. +// void Set(nostd::string_view key, nostd::string_view value) const noexcept; +// +// // Returns true if there are no keys, false otherwise. +// bool Empty() const noexcept { return true; } +// +// // Returns a span of all the entries. The TraceState object must outlive the span. +// nostd::span Entries() const noexcept { return {}; } +// +// // Returns whether key is a valid key. See https://www.w3.org/TR/trace-context/#key +// static bool IsValidKey(nostd::string_view key); +// +// // Returns whether value is a valid value. See https://www.w3.org/TR/trace-context/#value +// static bool IsValidValue(nostd::string_view value); +// +//private: +// // Store entries in a C-style array to avoid using std::array or std::vector. +// Entry entries_[kMaxKeyValuePairs]; +// +// // Maintain the number of entries in entries_. Must be in the range [0, kMaxKeyValuePairs]. +// int num_entries_; +//}; +// +//} // namespace trace +//OPENTELEMETRY_END_NAMESPACE \ No newline at end of file diff --git a/api/test/trace/propagation/http_text_format_test.cc b/api/test/trace/propagation/http_text_format_test.cc index b3abb8cde0..71c0dc4850 100644 --- a/api/test/trace/propagation/http_text_format_test.cc +++ b/api/test/trace/propagation/http_text_format_test.cc @@ -64,71 +64,71 @@ TEST(HTTPTextFormatTest, TraceFlagsBufferGeneration) EXPECT_EQ(MapHttpTraceContext::GenerateTraceFlagsFromString("00"), trace::TraceFlags()); } -TEST(HTTPTextFormatTest, HeadersWithTraceState) -{ - const std::map carrier = { - {"traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"}, - {"tracestate", "congo=congosSecondPosition,rojo=rojosFirstPosition"}}; - context::Context ctx1 = - context::Context("current-span", nostd::shared_ptr(new trace::DefaultSpan())); - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); - std::map c2 = {}; - format.Inject(Setter, c2, ctx2); - EXPECT_EQ(c2["traceparent"], "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"); - EXPECT_EQ(c2["tracestate"], "congo=congosSecondPosition,rojo=rojosFirstPosition"); - EXPECT_EQ(carrier.size(), c2.size()); -} - -TEST(HTTPTextFormatTest, NoTraceParentHeader) -{ - // When trace context headers are not present, a new SpanContext - // should be created. - const std::map carrier = {}; - context::Context ctx1 = - context::Context("current-span", nostd::shared_ptr(new trace::DefaultSpan())); - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); - trace::Span *span = MapHttpTraceContext::GetCurrentSpan(ctx2); - EXPECT_EQ(span->GetContext().trace_id(), trace::SpanContext(false, false).trace_id()); - EXPECT_EQ(span->GetContext().span_id(), trace::SpanContext(false, false).span_id()); - EXPECT_EQ(span->GetContext().trace_flags(), trace::SpanContext(false, false).trace_flags()); - EXPECT_EQ(span->GetContext().trace_state(), trace::SpanContext(false, false).trace_state()); -} - -TEST(HTTPTextFormatTest, InvalidTraceId) -{ - // If the trace id is invalid, we must ignore the full trace parent header, - // and return a random, valid trace. - // Also ignore any trace state. - const std::map carrier = { - {"traceparent", "00-00000000000000000000000000000000-1234567890123456-00"}, - {"tracestate", "foo=1,bar=2,foo=3"}}; - context::Context ctx1 = - context::Context("current-span", nostd::shared_ptr(new trace::DefaultSpan())); - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); - trace::Span *span = MapHttpTraceContext::GetCurrentSpan(ctx2); - EXPECT_EQ(span->GetContext().trace_id(), trace::SpanContext(false, false).trace_id()); - EXPECT_EQ(span->GetContext().span_id(), trace::SpanContext(false, false).span_id()); - EXPECT_EQ(span->GetContext().trace_flags(), trace::SpanContext(false, false).trace_flags()); - EXPECT_EQ(span->GetContext().trace_state(), trace::SpanContext(false, false).trace_state()); -} - -TEST(HTTPTextFormatTest, InvalidParentId) -{ - // If the parent id is invalid, we must ignore the full trace parent - // header. - // Also ignore any trace state. - const std::map carrier = { - {"traceparent", "00-00000000000000000000000000000000-0000000000000000-00"}, - {"tracestate", "foo=1,bar=2,foo=3"}}; - context::Context ctx1 = - context::Context("current-span", nostd::shared_ptr(new trace::DefaultSpan())); - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); - trace::Span *span = MapHttpTraceContext::GetCurrentSpan(ctx2); - EXPECT_EQ(span->GetContext().trace_id(), trace::SpanContext(false, false).trace_id()); - EXPECT_EQ(span->GetContext().span_id(), trace::SpanContext(false, false).span_id()); - EXPECT_EQ(span->GetContext().trace_flags(), trace::SpanContext(false, false).trace_flags()); - EXPECT_EQ(span->GetContext().trace_state(), trace::SpanContext(false, false).trace_state()); -} +//TEST(HTTPTextFormatTest, HeadersWithTraceState) +//{ +// const std::map carrier = { +// {"traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"}, +// {"tracestate", "congo=congosSecondPosition,rojo=rojosFirstPosition"}}; +// context::Context ctx1 = +// context::Context("current-span", nostd::shared_ptr(new trace::DefaultSpan())); +// context::Context ctx2 = format.Extract(Getter, carrier, ctx1); +// std::map c2 = {}; +// format.Inject(Setter, c2, ctx2); +// EXPECT_EQ(c2["traceparent"], "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"); +// EXPECT_EQ(c2["tracestate"], "congo=congosSecondPosition,rojo=rojosFirstPosition"); +// EXPECT_EQ(carrier.size(), c2.size()); +//} +// +//TEST(HTTPTextFormatTest, NoTraceParentHeader) +//{ +// // When trace context headers are not present, a new SpanContext +// // should be created. +// const std::map carrier = {}; +// context::Context ctx1 = +// context::Context("current-span", nostd::shared_ptr(new trace::DefaultSpan())); +// context::Context ctx2 = format.Extract(Getter, carrier, ctx1); +// trace::Span *span = MapHttpTraceContext::GetCurrentSpan(ctx2); +// EXPECT_EQ(span->GetContext().trace_id(), trace::SpanContext(false, false).trace_id()); +// EXPECT_EQ(span->GetContext().span_id(), trace::SpanContext(false, false).span_id()); +// EXPECT_EQ(span->GetContext().trace_flags(), trace::SpanContext(false, false).trace_flags()); +// EXPECT_EQ(span->GetContext().trace_state(), trace::SpanContext(false, false).trace_state()); +//} +// +//TEST(HTTPTextFormatTest, InvalidTraceId) +//{ +// // If the trace id is invalid, we must ignore the full trace parent header, +// // and return a random, valid trace. +// // Also ignore any trace state. +// const std::map carrier = { +// {"traceparent", "00-00000000000000000000000000000000-1234567890123456-00"}, +// {"tracestate", "foo=1,bar=2,foo=3"}}; +// context::Context ctx1 = +// context::Context("current-span", nostd::shared_ptr(new trace::DefaultSpan())); +// context::Context ctx2 = format.Extract(Getter, carrier, ctx1); +// trace::Span *span = MapHttpTraceContext::GetCurrentSpan(ctx2); +// EXPECT_EQ(span->GetContext().trace_id(), trace::SpanContext(false, false).trace_id()); +// EXPECT_EQ(span->GetContext().span_id(), trace::SpanContext(false, false).span_id()); +// EXPECT_EQ(span->GetContext().trace_flags(), trace::SpanContext(false, false).trace_flags()); +// EXPECT_EQ(span->GetContext().trace_state(), trace::SpanContext(false, false).trace_state()); +//} +// +//TEST(HTTPTextFormatTest, InvalidParentId) +//{ +// // If the parent id is invalid, we must ignore the full trace parent +// // header. +// // Also ignore any trace state. +// const std::map carrier = { +// {"traceparent", "00-00000000000000000000000000000000-0000000000000000-00"}, +// {"tracestate", "foo=1,bar=2,foo=3"}}; +// context::Context ctx1 = +// context::Context("current-span", nostd::shared_ptr(new trace::DefaultSpan())); +// context::Context ctx2 = format.Extract(Getter, carrier, ctx1); +// trace::Span *span = MapHttpTraceContext::GetCurrentSpan(ctx2); +// EXPECT_EQ(span->GetContext().trace_id(), trace::SpanContext(false, false).trace_id()); +// EXPECT_EQ(span->GetContext().span_id(), trace::SpanContext(false, false).span_id()); +// EXPECT_EQ(span->GetContext().trace_flags(), trace::SpanContext(false, false).trace_flags()); +// EXPECT_EQ(span->GetContext().trace_state(), trace::SpanContext(false, false).trace_state()); +//} TEST(HTTPTextFormatTest, NoSendEmptyTraceState) { @@ -144,23 +144,23 @@ TEST(HTTPTextFormatTest, NoSendEmptyTraceState) EXPECT_FALSE(carrier.count("tracestate") > 0); } -TEST(HTTPTextFormatTest, FormatNotSupported) -{ - // If the trace parent does not adhere to the supported format, discard it and - // create a new trace context. - const std::map carrier = { - {"traceparent", "00-12345678901234567890123456789012-1234567890123456-00-residue"}, - {"tracestate", "foo=1,bar=2,foo=3"}}; - context::Context ctx1 = - context::Context("current-span", nostd::shared_ptr(new trace::DefaultSpan())); - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); - trace::Span *span = MapHttpTraceContext::GetCurrentSpan(ctx2); - EXPECT_FALSE(span->GetContext().IsValid()); - EXPECT_EQ(span->GetContext().trace_id(), trace::SpanContext(false, false).trace_id()); - EXPECT_EQ(span->GetContext().span_id(), trace::SpanContext(false, false).span_id()); - EXPECT_EQ(span->GetContext().trace_flags(), trace::SpanContext(false, false).trace_flags()); - EXPECT_EQ(span->GetContext().trace_state(), trace::SpanContext(false, false).trace_state()); -} +//TEST(HTTPTextFormatTest, FormatNotSupported) +//{ +// // If the trace parent does not adhere to the supported format, discard it and +// // create a new trace context. +// const std::map carrier = { +// {"traceparent", "00-12345678901234567890123456789012-1234567890123456-00-residue"}, +// {"tracestate", "foo=1,bar=2,foo=3"}}; +// context::Context ctx1 = +// context::Context("current-span", nostd::shared_ptr(new trace::DefaultSpan())); +// context::Context ctx2 = format.Extract(Getter, carrier, ctx1); +// trace::Span *span = MapHttpTraceContext::GetCurrentSpan(ctx2); +// EXPECT_FALSE(span->GetContext().IsValid()); +// EXPECT_EQ(span->GetContext().trace_id(), trace::SpanContext(false, false).trace_id()); +// EXPECT_EQ(span->GetContext().span_id(), trace::SpanContext(false, false).span_id()); +// EXPECT_EQ(span->GetContext().trace_flags(), trace::SpanContext(false, false).trace_flags()); +// EXPECT_EQ(span->GetContext().trace_state(), trace::SpanContext(false, false).trace_state()); +//} TEST(HTTPTextFormatTest, PropagateInvalidContext) { @@ -173,34 +173,34 @@ TEST(HTTPTextFormatTest, PropagateInvalidContext) EXPECT_TRUE(carrier.count("traceparent") == 0); } -TEST(HTTPTextFormatTest, TraceStateHeaderWithTrailingComma) -{ - // Do not propagate invalid trace context. - const std::map carrier = { - {"traceparent", "00-12345678901234567890123456789012-1234567890123456-00"}, - {"tracestate", "foo=1,"}}; - context::Context ctx1 = - context::Context("current-span", nostd::shared_ptr(new trace::DefaultSpan())); - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); - trace::Span *span = MapHttpTraceContext::GetCurrentSpan(ctx2); - trace::TraceState trace_state = span->GetContext().trace_state(); - EXPECT_TRUE(trace_state.Get("foo", "1")); -} - -TEST(HTTPTextFormatTest, TraceStateKeys) -{ - // Test for valid key patterns in the tracestate - std::string trace_state_value = "1a-2f@foo=bar1,1a-_*/2b@foo=bar2,foo=bar3,foo-_*/bar=bar4"; - const std::map carrier = { - {"traceparent", "00-12345678901234567890123456789012-1234567890123456-00"}, - {"tracestate", trace_state_value}}; - context::Context ctx1 = - context::Context("current-span", nostd::shared_ptr(new trace::DefaultSpan())); - context::Context ctx2 = format.Extract(Getter, carrier, ctx1); - trace::Span *span = MapHttpTraceContext::GetCurrentSpan(ctx2); - trace::TraceState trace_state = span->GetContext().trace_state(); - EXPECT_TRUE(trace_state.Get("1a-2f@foo", "bar1")); - EXPECT_TRUE(trace_state.Get("1a-_*/2b@foo", "bar2")); - EXPECT_TRUE(trace_state.Get("foo", "bar3")); - EXPECT_TRUE(trace_state.Get("foo-_*/bar", "bar4")); -} +//TEST(HTTPTextFormatTest, TraceStateHeaderWithTrailingComma) +//{ +// // Do not propagate invalid trace context. +// const std::map carrier = { +// {"traceparent", "00-12345678901234567890123456789012-1234567890123456-00"}, +// {"tracestate", "foo=1,"}}; +// context::Context ctx1 = +// context::Context("current-span", nostd::shared_ptr(new trace::DefaultSpan())); +// context::Context ctx2 = format.Extract(Getter, carrier, ctx1); +// trace::Span *span = MapHttpTraceContext::GetCurrentSpan(ctx2); +// trace::TraceState trace_state = span->GetContext().trace_state(); +// EXPECT_TRUE(trace_state.Get("foo", "1")); +//} + +//TEST(HTTPTextFormatTest, TraceStateKeys) +//{ +// // Test for valid key patterns in the tracestate +// std::string trace_state_value = "1a-2f@foo=bar1,1a-_*/2b@foo=bar2,foo=bar3,foo-_*/bar=bar4"; +// const std::map carrier = { +// {"traceparent", "00-12345678901234567890123456789012-1234567890123456-00"}, +// {"tracestate", trace_state_value}}; +// context::Context ctx1 = +// context::Context("current-span", nostd::shared_ptr(new trace::DefaultSpan())); +// context::Context ctx2 = format.Extract(Getter, carrier, ctx1); +// trace::Span *span = MapHttpTraceContext::GetCurrentSpan(ctx2); +// trace::TraceState trace_state = span->GetContext().trace_state(); +// EXPECT_TRUE(trace_state.Get("1a-2f@foo", "bar1")); +// EXPECT_TRUE(trace_state.Get("1a-_*/2b@foo", "bar2")); +// EXPECT_TRUE(trace_state.Get("foo", "bar3")); +// EXPECT_TRUE(trace_state.Get("foo-_*/bar", "bar4")); +//}