From 5bf06935e53321daf75ea6a7827bb9b1e367231c Mon Sep 17 00:00:00 2001 From: Tianlin Zhao Date: Thu, 13 Aug 2020 16:51:05 -0400 Subject: [PATCH] new PR: removed all TraceState references --- .../trace/propagation/http_trace_context.h | 125 ++---------------- .../opentelemetry/trace/span_context.h | 50 ++----- 2 files changed, 21 insertions(+), 154 deletions(-) diff --git a/api/include/opentelemetry/trace/propagation/http_trace_context.h b/api/include/opentelemetry/trace/propagation/http_trace_context.h index 2e102ba98e..2319bdd2eb 100644 --- a/api/include/opentelemetry/trace/propagation/http_trace_context.h +++ b/api/include/opentelemetry/trace/propagation/http_trace_context.h @@ -26,9 +26,7 @@ #include "opentelemetry/trace/propagation/http_text_format.h" #include "opentelemetry/trace/span.h" #include "opentelemetry/trace/span_context.h" -// 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" +// TODO: include trace_state.h back OPENTELEMETRY_BEGIN_NAMESPACE namespace trace @@ -182,22 +180,8 @@ class HttpTraceContext : public HTTPTextFormat } } - // The commented out code below are ones that are related to TraceState. Needs to be uncommented - // after TraceState is merged. - // 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); - // } + // TODO: + // static void InjectTraceState(TraceState trace_state, T &carrier, Setter setter) static void InjectTraceParent(const SpanContext &span_context, T &carrier, Setter setter) { @@ -229,11 +213,7 @@ class HttpTraceContext : public HTTPTextFormat static void InjectImpl(Setter setter, T &carrier, const SpanContext &span_context) { InjectTraceParent(span_context, carrier, setter); - // The commented out code below are ones that are related to TraceState. Needs to be - // uncommented after TraceState is merged. if (!span_context.trace_state().empty()) - // { - // InjectTraceState(span_context.trace_state(), carrier, setter); - // } + // TODO: inject Trace State } static SpanContext ExtractContextFromTraceParent(nostd::string_view trace_parent) @@ -314,9 +294,7 @@ class HttpTraceContext : public HTTPTextFormat SpanId span_id_obj = GenerateSpanIdFromString(span_id); TraceFlags trace_flags_obj = GenerateTraceFlagsFromString(trace_flags); return SpanContext(trace_id_obj, span_id_obj, trace_flags_obj, true); - // The commented out code below are ones that are related to TraceState. Needs to be - // uncommented after TraceState is merged. - // return SpanContext(trace_id_obj, span_id_obj, trace_flags_obj, TraceState(), true); + // TODO: Change to new Span Context constructor once TraceState is done } else { @@ -325,78 +303,8 @@ class HttpTraceContext : public HTTPTextFormat } } - // The commented out code below are ones that are related to TraceState. Needs to be uncommented - // after TraceState is merged. + // TODO: // 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) { @@ -406,25 +314,10 @@ class HttpTraceContext : public HTTPTextFormat return SpanContext(false, false); } SpanContext context_from_parent_header = ExtractContextFromTraceParent(trace_parent); - // The commented out code below are ones that are related to TraceState. Needs to be - // uncommented after TraceState is merged. if (!context_from_parent_header.IsValid()) - // { + // TODO: + // if (!context_from_parent_header.IsValid()) return context_from_parent_header; - // The commented out code below are ones that are related to TraceState. Needs to be - // uncommented after TraceState is merged. - // } - - // 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); + // TODO: extract from trace state } }; } // namespace propagation diff --git a/api/include/opentelemetry/trace/span_context.h b/api/include/opentelemetry/trace/span_context.h index 978e4bed89..d488c9a4a9 100644 --- a/api/include/opentelemetry/trace/span_context.h +++ b/api/include/opentelemetry/trace/span_context.h @@ -18,9 +18,7 @@ #include "opentelemetry/trace/span_id.h" #include "opentelemetry/trace/trace_flags.h" #include "opentelemetry/trace/trace_id.h" -// 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" +// TODO: include trace_state.h back OPENTELEMETRY_BEGIN_NAMESPACE namespace trace @@ -34,44 +32,32 @@ class SpanContext final // An invalid SpanContext. SpanContext() noexcept : trace_flags_(trace::TraceFlags((uint8_t) false)), - // The commented out code below are ones that are related to TraceState. Needs to be - // uncommented after TraceState is merged. - // trace_state_(new TraceState), + // TODO: add trace state as an argument remote_parent_(false){}; SpanContext(bool sampled_flag, bool has_remote_parent) noexcept : trace_flags_(trace::TraceFlags((uint8_t)sampled_flag)), - // The commented out code below are ones that are related to TraceState. Needs to be - // uncommented after TraceState is merged. - // trace_state_(new TraceState), + // TODO: add trace state as an argument remote_parent_(has_remote_parent){}; SpanContext(TraceId trace_id, SpanId span_id, TraceFlags trace_flags, - // The commented out code below are ones that are related to TraceState. Needs to be - // uncommented after TraceState is merged. - // TraceState trace_state, + // TODO: add trace state as an argument bool has_remote_parent) noexcept { trace_id_ = trace_id; span_id_ = span_id; trace_flags_ = trace_flags; - // The commented out code below are ones that are related to TraceState. Needs to be - // uncommented after TraceState is merged. - // trace_state_.reset(new TraceState(trace_state)); + // TODO: add trace state as an argument remote_parent_ = has_remote_parent; } SpanContext(SpanContext &&ctx) : trace_id_(ctx.trace_id()), span_id_(ctx.span_id()), trace_flags_(ctx.trace_flags()) - // The commented out code below are ones that are related to TraceState. Needs to be uncommented - // after TraceState is merged. - // trace_state_(std::move(ctx.trace_state_)) + // TODO: add trace state as an argument {} SpanContext(const SpanContext &ctx) : trace_id_(ctx.trace_id()), span_id_(ctx.span_id()), trace_flags_(ctx.trace_flags()) - // The commented out code below are ones that are related to TraceState. Needs to be uncommented - // after TraceState is merged. - // trace_state_(new TraceState(ctx.trace_state())) + // TODO: add trace state as an argument {} SpanContext &operator=(const SpanContext &ctx) @@ -79,9 +65,7 @@ class SpanContext final trace_id_ = ctx.trace_id_; span_id_ = ctx.span_id_; trace_flags_ = ctx.trace_flags_; - // The commented out code below are ones that are related to TraceState. Needs to be - // uncommented after TraceState is merged. - // trace_state_.reset(new TraceState(*(ctx.trace_state_.get()))); + // TODO: add trace state as an argument return *this; }; SpanContext &operator=(SpanContext &&ctx) @@ -89,22 +73,14 @@ class SpanContext final trace_id_ = ctx.trace_id_; span_id_ = ctx.span_id_; trace_flags_ = ctx.trace_flags_; - // The commented out code below are ones that are related to TraceState. Needs to be - // uncommented after TraceState is merged. - // trace_state_.reset(new TraceState(*(ctx.trace_state_.get()))); + // TODO: add trace state as an argument return *this; }; - // TODO - // - // static SpanContext Create(TraceId traceId, SpanId spanId, TraceFlags traceFlags, TraceState - // traceState); static SpanContext CreateFromRemoteParent(...); const TraceId &trace_id() const noexcept { return trace_id_; } const SpanId &span_id() const noexcept { return span_id_; } const TraceFlags &trace_flags() const noexcept { return trace_flags_; } - // The commented out code below are ones that are related to TraceState. Needs to be uncommented - // after TraceState is merged. - // const TraceState &trace_state() const noexcept { return *trace_state_; } + // TODO: add trace state getter bool IsValid() const noexcept { return trace_id_.IsValid() && span_id_.IsValid(); } @@ -118,11 +94,9 @@ class SpanContext final TraceId trace_id_; SpanId span_id_; TraceFlags trace_flags_; - // The commented out code below are ones that are related to TraceState. Needs to be uncommented - // after TraceState is merged. - // nostd::unique_ptr trace_state_; // Never nullptr. + // TODO: add the unique pointer of trace state as a field bool remote_parent_ = false; }; } // namespace trace -OPENTELEMETRY_END_NAMESPACE // namespace opentelemetry \ No newline at end of file +OPENTELEMETRY_END_NAMESPACE // namespace opentelemetry