From f02c1c95a6a6e64f688e9c7f0c76275f8ff3f2e0 Mon Sep 17 00:00:00 2001 From: Nadia Ciobanu Date: Sat, 18 Jul 2020 01:03:20 +0000 Subject: [PATCH 1/4] Add events to SpanData --- .../opentelemetry/sdk/trace/span_data.h | 26 +++++++++++++++++-- sdk/test/trace/span_data_test.cc | 2 ++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/span_data.h b/sdk/include/opentelemetry/sdk/trace/span_data.h index 2750ff8740..ac47c2968b 100644 --- a/sdk/include/opentelemetry/sdk/trace/span_data.h +++ b/sdk/include/opentelemetry/sdk/trace/span_data.h @@ -84,6 +84,22 @@ struct AttributeConverter } }; +/** + * Class for storing events in SpanData + */ +class SpanDataEvent +{ +public: + SpanDataEvent(nostd::string_view name, core::SystemTimestamp timestamp) + { + name_ = name; + timestamp_ = timestamp; + } + + nostd::string_view name_; + core::SystemTimestamp timestamp_; +}; + /** * SpanData is a representation of all data collected by a span. */ @@ -147,6 +163,12 @@ class SpanData final : public Recordable return attributes_; } + /** + * Get the events associated with this span + * @return the events associated with this span + */ + std::vector GetEvents() const noexcept { return events_; } + void SetIds(opentelemetry::trace::TraceId trace_id, opentelemetry::trace::SpanId span_id, opentelemetry::trace::SpanId parent_span_id) noexcept override @@ -163,8 +185,7 @@ class SpanData final : public Recordable void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept override { - (void)name; - (void)timestamp; + events_.push_back(SpanDataEvent(name, timestamp)); } void SetStatus(trace_api::CanonicalCode code, nostd::string_view description) noexcept override @@ -192,6 +213,7 @@ class SpanData final : public Recordable opentelemetry::trace::CanonicalCode status_code_{opentelemetry::trace::CanonicalCode::OK}; std::string status_desc_; std::unordered_map attributes_; + std::vector events_; AttributeConverter converter_; }; } // namespace trace diff --git a/sdk/test/trace/span_data_test.cc b/sdk/test/trace/span_data_test.cc index 1bc231d294..5e02b9ac49 100644 --- a/sdk/test/trace/span_data_test.cc +++ b/sdk/test/trace/span_data_test.cc @@ -49,4 +49,6 @@ TEST(SpanData, Set) ASSERT_EQ(data.GetStartTime().time_since_epoch(), now.time_since_epoch()); ASSERT_EQ(data.GetDuration(), std::chrono::nanoseconds(1000000)); ASSERT_EQ(opentelemetry::nostd::get(data.GetAttributes().at("attr1")), 314159); + ASSERT_EQ(data.GetEvents().at(0).name_, "event1"); + ASSERT_EQ(data.GetEvents().at(0).timestamp_, now); } From d8e4dd3286e9a98027f3c603a13a3156f72729be Mon Sep 17 00:00:00 2001 From: Nadia Ciobanu Date: Mon, 20 Jul 2020 21:47:57 +0000 Subject: [PATCH 2/4] Add getters for event members --- sdk/include/opentelemetry/sdk/trace/span_data.h | 15 ++++++++++++++- sdk/test/trace/span_data_test.cc | 5 +++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/span_data.h b/sdk/include/opentelemetry/sdk/trace/span_data.h index ac47c2968b..d007ef3b32 100644 --- a/sdk/include/opentelemetry/sdk/trace/span_data.h +++ b/sdk/include/opentelemetry/sdk/trace/span_data.h @@ -85,7 +85,7 @@ struct AttributeConverter }; /** - * Class for storing events in SpanData + * Class for storing events in SpanData. */ class SpanDataEvent { @@ -96,6 +96,19 @@ class SpanDataEvent timestamp_ = timestamp; } + /** + * Get the name for this event + * @return the name for this event + */ + nostd::string_view GetName() const noexcept { return name_; } + + /** + * Get the timestamp for this event + * @return the timestamp for this event + */ + core::SystemTimestamp GetTimestamp() const noexcept { return timestamp_; } + +private: nostd::string_view name_; core::SystemTimestamp timestamp_; }; diff --git a/sdk/test/trace/span_data_test.cc b/sdk/test/trace/span_data_test.cc index 5e02b9ac49..41d7b2c670 100644 --- a/sdk/test/trace/span_data_test.cc +++ b/sdk/test/trace/span_data_test.cc @@ -22,6 +22,7 @@ TEST(SpanData, DefaultValues) ASSERT_EQ(data.GetStartTime().time_since_epoch(), std::chrono::nanoseconds(0)); ASSERT_EQ(data.GetDuration(), std::chrono::nanoseconds(0)); ASSERT_EQ(data.GetAttributes().size(), 0); + ASSERT_EQ(data.GetEvents().size(), 0); } TEST(SpanData, Set) @@ -49,6 +50,6 @@ TEST(SpanData, Set) ASSERT_EQ(data.GetStartTime().time_since_epoch(), now.time_since_epoch()); ASSERT_EQ(data.GetDuration(), std::chrono::nanoseconds(1000000)); ASSERT_EQ(opentelemetry::nostd::get(data.GetAttributes().at("attr1")), 314159); - ASSERT_EQ(data.GetEvents().at(0).name_, "event1"); - ASSERT_EQ(data.GetEvents().at(0).timestamp_, now); + ASSERT_EQ(data.GetEvents().at(0).GetName(), "event1"); + ASSERT_EQ(data.GetEvents().at(0).GetTimestamp(), now); } From c16b3837c6e6a603a64abf5846ec27481261f160 Mon Sep 17 00:00:00 2001 From: Nadia Ciobanu Date: Mon, 20 Jul 2020 21:54:52 +0000 Subject: [PATCH 3/4] Update GetEvents --- sdk/include/opentelemetry/sdk/trace/span_data.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/trace/span_data.h b/sdk/include/opentelemetry/sdk/trace/span_data.h index d007ef3b32..6be8de2a3b 100644 --- a/sdk/include/opentelemetry/sdk/trace/span_data.h +++ b/sdk/include/opentelemetry/sdk/trace/span_data.h @@ -180,7 +180,7 @@ class SpanData final : public Recordable * Get the events associated with this span * @return the events associated with this span */ - std::vector GetEvents() const noexcept { return events_; } + const std::vector &GetEvents() const noexcept { return events_; } void SetIds(opentelemetry::trace::TraceId trace_id, opentelemetry::trace::SpanId span_id, From 46102c32ef9d1656beb52471780794bf01f7f9f8 Mon Sep 17 00:00:00 2001 From: Nadia Ciobanu Date: Mon, 20 Jul 2020 23:29:20 +0000 Subject: [PATCH 4/4] Address review comments --- sdk/include/opentelemetry/sdk/trace/span_data.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/span_data.h b/sdk/include/opentelemetry/sdk/trace/span_data.h index 6be8de2a3b..ffe1db1878 100644 --- a/sdk/include/opentelemetry/sdk/trace/span_data.h +++ b/sdk/include/opentelemetry/sdk/trace/span_data.h @@ -90,17 +90,15 @@ struct AttributeConverter class SpanDataEvent { public: - SpanDataEvent(nostd::string_view name, core::SystemTimestamp timestamp) - { - name_ = name; - timestamp_ = timestamp; - } + SpanDataEvent(std::string name, core::SystemTimestamp timestamp) + : name_(name), timestamp_(timestamp) + {} /** * Get the name for this event * @return the name for this event */ - nostd::string_view GetName() const noexcept { return name_; } + std::string GetName() const noexcept { return name_; } /** * Get the timestamp for this event @@ -109,7 +107,7 @@ class SpanDataEvent core::SystemTimestamp GetTimestamp() const noexcept { return timestamp_; } private: - nostd::string_view name_; + std::string name_; core::SystemTimestamp timestamp_; }; @@ -198,7 +196,7 @@ class SpanData final : public Recordable void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept override { - events_.push_back(SpanDataEvent(name, timestamp)); + events_.push_back(SpanDataEvent(std::string(name), timestamp)); } void SetStatus(trace_api::CanonicalCode code, nostd::string_view description) noexcept override