From 098678e465ed45cc538b440b0e06e0a3230e880d Mon Sep 17 00:00:00 2001 From: Keshav Manghat Date: Wed, 29 Jul 2020 18:57:11 +0000 Subject: [PATCH 1/4] Added a copy constructor for zpages recordable --- .../ext/zpages/threadsafe_span_data.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h b/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h index a8f596696c..6ee0864c66 100644 --- a/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h +++ b/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h @@ -168,6 +168,24 @@ class ThreadsafeSpanData final : public opentelemetry::sdk::trace::Recordable { events_.push_back(SpanDataEvent(std::string(name), timestamp)); // TODO: handle attributes } + + ThreadsafeSpanData (const ThreadsafeSpanData &threadsafe_span_data) + { + std::lock_guard lock(threadsafe_span_data.mutex_); + trace_id_ = threadsafe_span_data.trace_id_; + span_id_ = threadsafe_span_data.span_id_; + parent_span_id_ = threadsafe_span_data.parent_span_id_; + start_time_ = threadsafe_span_data.start_time_; + duration_ = threadsafe_span_data.duration_; + name_ = threadsafe_span_data.name_; + status_code_ = threadsafe_span_data.status_code_; + status_desc_ = threadsafe_span_data.status_desc_; + attributes_ = threadsafe_span_data.attributes_; + events_ = threadsafe_span_data.events_; + converter_ = threadsafe_span_data.converter_; + } + + ThreadsafeSpanData(){}; private: mutable std::mutex mutex_; From 96b9d8999d223abc5fda2aeb25e4441940d19f5b Mon Sep 17 00:00:00 2001 From: Keshav Manghat Date: Wed, 29 Jul 2020 21:26:38 +0000 Subject: [PATCH 2/4] Changed implementation detail of copy constructor --- .../ext/zpages/threadsafe_span_data.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h b/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h index 6ee0864c66..a6f24b1ebe 100644 --- a/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h +++ b/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h @@ -186,8 +186,24 @@ class ThreadsafeSpanData final : public opentelemetry::sdk::trace::Recordable { } ThreadsafeSpanData(){}; + ThreadsafeSpanData(const ThreadsafeSpanData &threadsafe_span_data) : ThreadsafeSpanData( + threadsafe_span_data, std::lock_guard(threadsafe_span_data.mutex_)) + {} private: + ThreadsafeSpanData(const ThreadsafeSpanData &threadsafe_span_data, const std::lock_guard &) + :trace_id_(threadsafe_span_data.trace_id_), + span_id_(threadsafe_span_data.span_id_), + parent_span_id_(threadsafe_span_data.parent_span_id_), + start_time_(threadsafe_span_data.start_time_), + duration_(threadsafe_span_data.duration_), + name_(threadsafe_span_data.name_), + status_code_(threadsafe_span_data.status_code_), + status_desc_(threadsafe_span_data.status_desc_), + attributes_(threadsafe_span_data.attributes_), + events_(threadsafe_span_data.events_), + converter_(threadsafe_span_data.converter_){} + mutable std::mutex mutex_; opentelemetry::trace::TraceId trace_id_; opentelemetry::trace::SpanId span_id_; From c0a13d212f9a7924db310d8deddb564662ace155 Mon Sep 17 00:00:00 2001 From: Keshav Manghat Date: Wed, 29 Jul 2020 21:29:11 +0000 Subject: [PATCH 3/4] Removed redundant code --- .../ext/zpages/threadsafe_span_data.h | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h b/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h index a6f24b1ebe..e7ede4b729 100644 --- a/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h +++ b/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h @@ -168,24 +168,8 @@ class ThreadsafeSpanData final : public opentelemetry::sdk::trace::Recordable { events_.push_back(SpanDataEvent(std::string(name), timestamp)); // TODO: handle attributes } - - ThreadsafeSpanData (const ThreadsafeSpanData &threadsafe_span_data) - { - std::lock_guard lock(threadsafe_span_data.mutex_); - trace_id_ = threadsafe_span_data.trace_id_; - span_id_ = threadsafe_span_data.span_id_; - parent_span_id_ = threadsafe_span_data.parent_span_id_; - start_time_ = threadsafe_span_data.start_time_; - duration_ = threadsafe_span_data.duration_; - name_ = threadsafe_span_data.name_; - status_code_ = threadsafe_span_data.status_code_; - status_desc_ = threadsafe_span_data.status_desc_; - attributes_ = threadsafe_span_data.attributes_; - events_ = threadsafe_span_data.events_; - converter_ = threadsafe_span_data.converter_; - } - - ThreadsafeSpanData(){}; + + ThreadsafeSpanData(){} ThreadsafeSpanData(const ThreadsafeSpanData &threadsafe_span_data) : ThreadsafeSpanData( threadsafe_span_data, std::lock_guard(threadsafe_span_data.mutex_)) {} From 45d23b73221cb43773b4cb1af4c88477f3e786ff Mon Sep 17 00:00:00 2001 From: Keshav Manghat Date: Tue, 4 Aug 2020 00:00:26 +0000 Subject: [PATCH 4/4] Format changes --- .../ext/zpages/threadsafe_span_data.h | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h b/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h index 53358a14d2..b6a455dff2 100644 --- a/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h +++ b/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h @@ -183,25 +183,28 @@ class ThreadsafeSpanData final : public opentelemetry::sdk::trace::Recordable // TODO: handle attributes } - ThreadsafeSpanData(){} - ThreadsafeSpanData(const ThreadsafeSpanData &threadsafe_span_data) : ThreadsafeSpanData( - threadsafe_span_data, std::lock_guard(threadsafe_span_data.mutex_)) + ThreadsafeSpanData() {} + ThreadsafeSpanData(const ThreadsafeSpanData &threadsafe_span_data) + : ThreadsafeSpanData(threadsafe_span_data, + std::lock_guard(threadsafe_span_data.mutex_)) + {} + +private: + ThreadsafeSpanData(const ThreadsafeSpanData &threadsafe_span_data, + const std::lock_guard &) + : trace_id_(threadsafe_span_data.trace_id_), + span_id_(threadsafe_span_data.span_id_), + parent_span_id_(threadsafe_span_data.parent_span_id_), + start_time_(threadsafe_span_data.start_time_), + duration_(threadsafe_span_data.duration_), + name_(threadsafe_span_data.name_), + status_code_(threadsafe_span_data.status_code_), + status_desc_(threadsafe_span_data.status_desc_), + attributes_(threadsafe_span_data.attributes_), + events_(threadsafe_span_data.events_), + converter_(threadsafe_span_data.converter_) {} - private: - ThreadsafeSpanData(const ThreadsafeSpanData &threadsafe_span_data, const std::lock_guard &) - :trace_id_(threadsafe_span_data.trace_id_), - span_id_(threadsafe_span_data.span_id_), - parent_span_id_(threadsafe_span_data.parent_span_id_), - start_time_(threadsafe_span_data.start_time_), - duration_(threadsafe_span_data.duration_), - name_(threadsafe_span_data.name_), - status_code_(threadsafe_span_data.status_code_), - status_desc_(threadsafe_span_data.status_desc_), - attributes_(threadsafe_span_data.attributes_), - events_(threadsafe_span_data.events_), - converter_(threadsafe_span_data.converter_){} - mutable std::mutex mutex_; opentelemetry::trace::TraceId trace_id_; opentelemetry::trace::SpanId span_id_;