-
Notifications
You must be signed in to change notification settings - Fork 559
Add events in SpanData #194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f02c1c9
d8e4dd3
c16b383
46102c3
2d8f2f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,33 @@ struct AttributeConverter | |
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Class for storing events in SpanData. | ||
| */ | ||
| class SpanDataEvent | ||
| { | ||
| public: | ||
| SpanDataEvent(std::string name, core::SystemTimestamp timestamp) | ||
| : name_(name), timestamp_(timestamp) | ||
| {} | ||
|
|
||
| /** | ||
| * Get the name for this event | ||
| * @return the name for this event | ||
| */ | ||
| std::string GetName() const noexcept { return name_; } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. std::string -> -> opentelemetry::nostd::string_view (for consistency with how SpanData returns string members, and it also should avoid copy). |
||
|
|
||
| /** | ||
| * Get the timestamp for this event | ||
| * @return the timestamp for this event | ||
| */ | ||
| core::SystemTimestamp GetTimestamp() const noexcept { return timestamp_; } | ||
|
|
||
| private: | ||
| std::string name_; | ||
| core::SystemTimestamp timestamp_; | ||
|
Comment on lines
+110
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both name_ and timestamp_ can be const membes since they are only set in ctor. |
||
| }; | ||
|
|
||
| /** | ||
| * SpanData is a representation of all data collected by a span. | ||
| */ | ||
|
|
@@ -147,6 +174,12 @@ class SpanData final : public Recordable | |
| return attributes_; | ||
| } | ||
|
|
||
| /** | ||
| * Get the events associated with this span | ||
| * @return the events associated with this span | ||
| */ | ||
| const std::vector<SpanDataEvent> &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 +196,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(std::string(name), timestamp)); | ||
| } | ||
|
|
||
| void SetStatus(trace_api::CanonicalCode code, nostd::string_view description) noexcept override | ||
|
|
@@ -192,6 +224,7 @@ class SpanData final : public Recordable | |
| opentelemetry::trace::CanonicalCode status_code_{opentelemetry::trace::CanonicalCode::OK}; | ||
| std::string status_desc_; | ||
| std::unordered_map<std::string, SpanDataAttributeValue> attributes_; | ||
| std::vector<SpanDataEvent> events_; | ||
| AttributeConverter converter_; | ||
| }; | ||
| } // namespace trace | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,4 +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<int64_t>(data.GetAttributes().at("attr1")), 314159); | ||
| ASSERT_EQ(data.GetEvents().at(0).GetName(), "event1"); | ||
| ASSERT_EQ(data.GetEvents().at(0).GetTimestamp(), now); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think ASSERT_EQ can be replaced by EXPECT_EQ throughout this file. |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string -> opentelemetry::nostd::string_view (for consistency with how SpanData sets string members).