-
Notifications
You must be signed in to change notification settings - Fork 559
Add Resources to Recordable interface. #570
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
d33a53a
5719f7b
8bfc4c3
1b39b45
e0793e5
9b14130
fa99d28
87d1a6a
9e5d94c
e78c7b4
4a3c170
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 |
|---|---|---|
|
|
@@ -117,6 +117,101 @@ void PopulateAttribute(opentelemetry::proto::common::v1::KeyValue *attribute, | |
| } | ||
| } | ||
|
|
||
| void PopulateResourceAttribute(opentelemetry::proto::common::v1::KeyValue *attribute, | ||
| const std::string &key, | ||
| const opentelemetry::sdk::common::OwnedAttributeValue &value) | ||
| { | ||
|
|
||
| attribute->set_key(key.data(), key.size()); | ||
|
|
||
| if (nostd::holds_alternative<bool>(value)) | ||
| { | ||
| attribute->mutable_value()->set_bool_value(nostd::get<bool>(value)); | ||
| } | ||
|
|
||
|
Contributor
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. nit: remove blank line. |
||
| else if (nostd::holds_alternative<int>(value)) | ||
| { | ||
| attribute->mutable_value()->set_int_value(nostd::get<int>(value)); | ||
| } | ||
| else if (nostd::holds_alternative<int64_t>(value)) | ||
| { | ||
| attribute->mutable_value()->set_int_value(nostd::get<int64_t>(value)); | ||
| } | ||
| else if (nostd::holds_alternative<unsigned int>(value)) | ||
| { | ||
| attribute->mutable_value()->set_int_value(nostd::get<unsigned int>(value)); | ||
| } | ||
| else if (nostd::holds_alternative<uint64_t>(value)) | ||
| { | ||
| attribute->mutable_value()->set_int_value(nostd::get<uint64_t>(value)); | ||
| } | ||
| else if (nostd::holds_alternative<double>(value)) | ||
| { | ||
| attribute->mutable_value()->set_double_value(nostd::get<double>(value)); | ||
| } | ||
| else if (nostd::holds_alternative<std::string>(value)) | ||
| { | ||
| attribute->mutable_value()->set_string_value(nostd::get<std::string>(value).data(), | ||
| nostd::get<std::string>(value).size()); | ||
| } | ||
| #ifdef HAVE_SPAN_BYTE | ||
| else if (nostd::holds_alternative<uint8_t>(value)) | ||
| { | ||
| attribute->mutable_value()->set_string_value(nostd::get<uint8_t>(value)); | ||
| } | ||
| #endif | ||
| else if (nostd::holds_alternative<std::vector<bool>>(value)) | ||
| { | ||
| for (const auto &val : nostd::get<std::vector<bool>>(value)) | ||
| { | ||
| attribute->mutable_value()->mutable_array_value()->add_values()->set_bool_value(val); | ||
| } | ||
| } | ||
| else if (nostd::holds_alternative<std::vector<int32_t>>(value)) | ||
| { | ||
| for (const auto &val : nostd::get<std::vector<int32_t>>(value)) | ||
| { | ||
| attribute->mutable_value()->mutable_array_value()->add_values()->set_int_value(val); | ||
| } | ||
| } | ||
| else if (nostd::holds_alternative<std::vector<uint32_t>>(value)) | ||
| { | ||
| for (const auto &val : nostd::get<std::vector<uint32_t>>(value)) | ||
| { | ||
| attribute->mutable_value()->mutable_array_value()->add_values()->set_int_value(val); | ||
| } | ||
| } | ||
| else if (nostd::holds_alternative<std::vector<int64_t>>(value)) | ||
| { | ||
| for (const auto &val : nostd::get<std::vector<int64_t>>(value)) | ||
| { | ||
| attribute->mutable_value()->mutable_array_value()->add_values()->set_int_value(val); | ||
| } | ||
| } | ||
| else if (nostd::holds_alternative<std::vector<uint64_t>>(value)) | ||
| { | ||
| for (const auto &val : nostd::get<std::vector<uint64_t>>(value)) | ||
| { | ||
| attribute->mutable_value()->mutable_array_value()->add_values()->set_int_value(val); | ||
| } | ||
| } | ||
| else if (nostd::holds_alternative<std::vector<double>>(value)) | ||
| { | ||
| for (const auto &val : nostd::get<std::vector<double>>(value)) | ||
| { | ||
| attribute->mutable_value()->mutable_array_value()->add_values()->set_double_value(val); | ||
| } | ||
| } | ||
| else if (nostd::holds_alternative<std::vector<std::string>>(value)) | ||
| { | ||
| for (const auto &val : nostd::get<std::vector<std::string>>(value)) | ||
| { | ||
| attribute->mutable_value()->mutable_array_value()->add_values()->set_string_value(val.data(), | ||
| val.size()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void Recordable::SetAttribute(nostd::string_view key, | ||
| const opentelemetry::common::AttributeValue &value) noexcept | ||
| { | ||
|
|
@@ -207,6 +302,14 @@ void Recordable::SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept | |
| span_.set_kind(proto_span_kind); | ||
| } | ||
|
|
||
| void Recordable::SetResourceAttribute( | ||
| std::string key, | ||
| const opentelemetry::sdk::common::OwnedAttributeValue &value) noexcept | ||
| { | ||
| auto attribute = resource_.add_attributes(); | ||
| PopulateResourceAttribute(attribute, key, value); | ||
| } | ||
|
|
||
| void Recordable::SetStartTime(opentelemetry::core::SystemTimestamp start_time) noexcept | ||
| { | ||
| span_.set_start_time_unix_nano(start_time.time_since_epoch().count()); | ||
|
|
@@ -217,6 +320,11 @@ void Recordable::SetDuration(std::chrono::nanoseconds duration) noexcept | |
| const uint64_t unix_end_time = span_.start_time_unix_nano() + duration.count(); | ||
| span_.set_end_time_unix_nano(unix_end_time); | ||
| } | ||
|
|
||
| proto::resource::v1::Resource &Recordable::GetResources() noexcept | ||
| { | ||
| return resource_; | ||
| } | ||
| } // namespace otlp | ||
| } // namespace exporter | ||
| OPENTELEMETRY_END_NAMESPACE | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,6 +121,16 @@ class SpanData final : public Recordable | |
| */ | ||
| opentelemetry::trace::SpanKind GetSpanKind() const noexcept { return span_kind_; } | ||
|
|
||
| /** | ||
| * Get Resources. | ||
| * @return the resource of this span | ||
| */ | ||
| const std::unordered_map<std::string, opentelemetry::sdk::common::OwnedAttributeValue> | ||
| &GetResources() const noexcept | ||
|
Contributor
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. Why doesn't this return a |
||
| { | ||
| return resources_; | ||
| } | ||
|
|
||
| /** | ||
| * Get the status for this span | ||
| * @return the status for this span | ||
|
|
@@ -213,6 +223,14 @@ class SpanData final : public Recordable | |
| span_kind_ = span_kind; | ||
| } | ||
|
|
||
| void SetResourceAttribute( | ||
|
Contributor
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'm trying to understand what this method is intended to do and where it is in the spec. Fro what I gather, this is basically copying all the resource-attributes onto the span. Can we instead just grab a reference to the resource? |
||
| std::string key, | ||
| const opentelemetry::sdk::common::OwnedAttributeValue &value) noexcept override | ||
| { | ||
| resources_.insert(std::pair<std::string, opentelemetry::sdk::common::OwnedAttributeValue>( | ||
| std::string(key.data()), value)); | ||
| } | ||
|
|
||
| void SetStartTime(opentelemetry::core::SystemTimestamp start_time) noexcept override | ||
| { | ||
| start_time_ = start_time; | ||
|
|
@@ -233,6 +251,7 @@ class SpanData final : public Recordable | |
| std::vector<SpanDataEvent> events_; | ||
| std::vector<SpanDataLink> links_; | ||
| opentelemetry::trace::SpanKind span_kind_{opentelemetry::trace::SpanKind::kInternal}; | ||
| std::unordered_map<std::string, opentelemetry::sdk::common::OwnedAttributeValue> resources_; | ||
| }; | ||
| } // namespace trace | ||
| } // namespace sdk | ||
|
|
||
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.
Is this ready for review?