Skip to content

Commit

Permalink
removed all TraceState references
Browse files Browse the repository at this point in the history
  • Loading branch information
Tianlin-Zhao committed Aug 13, 2020
1 parent 5bf0693 commit 544c0ee
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 140 deletions.
122 changes: 1 addition & 121 deletions api/test/trace/propagation/http_text_format_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,74 +61,6 @@ TEST(HTTPTextFormatTest, TraceFlagsBufferGeneration)
EXPECT_EQ(MapHttpTraceContext::GenerateTraceFlagsFromString("00"), trace::TraceFlags());
}

// The commented out code below are ones that are related to TraceState. Needs to be uncommented
// after TraceState is merged.
// TEST(HTTPTextFormatTest, HeadersWithTraceState)
//{
// const std::map<std::string, std::string> carrier = {
// {"traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"},
// {"tracestate", "congo=congosSecondPosition,rojo=rojosFirstPosition"}};
// context::Context ctx1 =
// context::Context("current-span", nostd::shared_ptr<trace::Span>(new trace::DefaultSpan()));
// context::Context ctx2 = format.Extract(Getter, carrier, ctx1);
// std::map<std::string, std::string> 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<std::string, std::string> carrier = {};
// context::Context ctx1 =
// context::Context("current-span", nostd::shared_ptr<trace::Span>(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<std::string, std::string> carrier = {
// {"traceparent", "00-00000000000000000000000000000000-1234567890123456-00"},
// {"tracestate", "foo=1,bar=2,foo=3"}};
// context::Context ctx1 =
// context::Context("current-span", nostd::shared_ptr<trace::Span>(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<std::string, std::string> carrier = {
// {"traceparent", "00-00000000000000000000000000000000-0000000000000000-00"},
// {"tracestate", "foo=1,bar=2,foo=3"}};
// context::Context ctx1 =
// context::Context("current-span", nostd::shared_ptr<trace::Span>(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)
{
// If the trace state is empty, do not set the header.
Expand All @@ -143,26 +75,6 @@ TEST(HTTPTextFormatTest, NoSendEmptyTraceState)
EXPECT_FALSE(carrier.count("tracestate") > 0);
}

// The commented out code below are ones that are related to TraceState. Needs to be uncommented
// after TraceState is merged.
// 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<std::string, std::string> carrier = {
// {"traceparent", "00-12345678901234567890123456789012-1234567890123456-00-residue"},
// {"tracestate", "foo=1,bar=2,foo=3"}};
// context::Context ctx1 =
// context::Context("current-span", nostd::shared_ptr<trace::Span>(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)
{
// Do not propagate invalid trace context.
Expand All @@ -174,36 +86,4 @@ TEST(HTTPTextFormatTest, PropagateInvalidContext)
EXPECT_TRUE(carrier.count("traceparent") == 0);
}

// The commented out code below are ones that are related to TraceState. Needs to be uncommented
// after TraceState is merged.
// TEST(HTTPTextFormatTest, TraceStateHeaderWithTrailingComma)
//{
// // Do not propagate invalid trace context.
// const std::map<std::string, std::string> carrier = {
// {"traceparent", "00-12345678901234567890123456789012-1234567890123456-00"},
// {"tracestate", "foo=1,"}};
// context::Context ctx1 =
// context::Context("current-span", nostd::shared_ptr<trace::Span>(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<std::string, std::string> carrier = {
// {"traceparent", "00-12345678901234567890123456789012-1234567890123456-00"},
// {"tracestate", trace_state_value}};
// context::Context ctx1 =
// context::Context("current-span", nostd::shared_ptr<trace::Span>(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"));
//}
// TODO: add trace state tests
20 changes: 1 addition & 19 deletions api/test/trace/trace_state_test.cc
Original file line number Diff line number Diff line change
@@ -1,19 +1 @@
// The commented out code below are ones that are related to TraceState. Needs to be uncommented
// after TraceState is merged.
//#include "opentelemetry/trace/trace_state.h"
//
//#include <gtest/gtest.h>
//
// namespace
//{
//
// using opentelemetry::trace::TraceState;
//
// TEST(TraceStateTest, DefaultConstruction)
//{
// TraceState s;
// EXPECT_FALSE(s.Get("missing_key", "value"));
// EXPECT_TRUE(s.Empty());
// EXPECT_EQ(0, s.Entries().size());
//}
//} // namespace
// TODO: add trace state tests

0 comments on commit 544c0ee

Please sign in to comment.