diff --git a/exporters/trace/gcp_exporter/internal/recordable.cc b/exporters/trace/gcp_exporter/internal/recordable.cc index e70d182..2b3dc13 100644 --- a/exporters/trace/gcp_exporter/internal/recordable.cc +++ b/exporters/trace/gcp_exporter/internal/recordable.cc @@ -1,5 +1,4 @@ #include "exporters/trace/gcp_exporter/recordable.h" -#include OPENTELEMETRY_BEGIN_NAMESPACE @@ -34,31 +33,60 @@ void Recordable::SetIds(trace::TraceId trace_id, void Recordable::SetAttribute(nostd::string_view key, - const common::AttributeValue &&value) noexcept + const common::AttributeValue &value) noexcept { // Get the protobuf span's map - auto map = span_.mutable_attributes()->mutable_attribute_map(); + auto* map = span_.mutable_attributes()->mutable_attribute_map(); if(nostd::holds_alternative(value)) { - (*map)[std::string(key)].set_bool_value(nostd::get(value)); + (*map)[key.data()].set_bool_value(nostd::get(value)); } + else if (nostd::holds_alternative(value)) + { + (*map)[key.data()].set_int_value(nostd::get(value)); + } else if (nostd::holds_alternative(value)) { - (*map)[std::string(key)].set_int_value(nostd::get(value)); + (*map)[key.data()].set_int_value(nostd::get(value)); + } + else if (nostd::holds_alternative(value)) + { + (*map)[key.data()].set_int_value(nostd::get(value)); + } + else if (nostd::holds_alternative(value)) + { + (*map)[key.data()].set_int_value(nostd::get(value)); + } + else if (nostd::holds_alternative(value)) + { + (*map)[key.data()].set_int_value(nostd::get(value)); } else if (nostd::holds_alternative(value)) { // TODO: Truncate string to 128 bytes std::string value_str = std::string(nostd::get(value)); - (*map)[std::string(key)].mutable_string_value()->set_value(value_str); + (*map)[key.data()].mutable_string_value()->set_value(value_str); } } -void Recordable::AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept +void Recordable::AddEvent(nostd::string_view name, + core::SystemTimestamp timestamp, + const opentelemetry::trace::KeyValueIterable &attributes) noexcept { (void)name; + (void)timestamp; + (void)attributes; +} + + +void Recordable::AddLink( + opentelemetry::trace::SpanContext span_context, + const opentelemetry::trace::KeyValueIterable &attributes) noexcept +{ + (void)span_context; + (void)attributes; } diff --git a/exporters/trace/gcp_exporter/internal/recordable_test.cc b/exporters/trace/gcp_exporter/internal/recordable_test.cc index 84eac54..597c581 100644 --- a/exporters/trace/gcp_exporter/internal/recordable_test.cc +++ b/exporters/trace/gcp_exporter/internal/recordable_test.cc @@ -7,7 +7,7 @@ namespace exporter namespace gcp { -TEST(Recordable, TestSetAttribute) +TEST(Recordable, TestSetNonIntAttribute) { Recordable rec; @@ -16,12 +16,6 @@ TEST(Recordable, TestSetAttribute) const common::AttributeValue bool_value = true; rec.SetAttribute(bool_key, std::move(bool_value)); - // Set 'integer' type - const nostd::string_view int_key = "int_key"; - const int64_t seven = 7; - const common::AttributeValue int_value = seven; - rec.SetAttribute(int_key, std::move(int_value)); - // Set 'string' type const nostd::string_view string_key = "string_key"; const common::AttributeValue string_value = "test"; @@ -30,10 +24,32 @@ TEST(Recordable, TestSetAttribute) auto attr_map = rec.span().attributes().attribute_map(); EXPECT_TRUE(attr_map["bool_key"].bool_value()); - EXPECT_EQ(seven, attr_map["int_key"].int_value()); EXPECT_EQ("test", attr_map["string_key"].string_value().value()); } +template +struct IntAttributeTest : public testing::Test +{ + using IntParamType = T; +}; + +using IntTypes = testing::Types; +TYPED_TEST_CASE(IntAttributeTest, IntTypes); + +TYPED_TEST(IntAttributeTest, SetIntSingleAttribute) +{ + using IntType = typename TestFixture::IntParamType; + IntType i = 2; + common::AttributeValue int_val(i); + + Recordable rec; + rec.SetAttribute("int_key", int_val); + + auto attr_map = rec.span().attributes().attribute_map(); + + EXPECT_EQ(nostd::get(int_val), attr_map["int_key"].int_value()); +} + TEST(Recordable, TestSetIds) { setenv("GOOGLE_CLOUD_PROJECT_ID", "test_project", 1); diff --git a/exporters/trace/gcp_exporter/recordable.h b/exporters/trace/gcp_exporter/recordable.h index 0b00c16..62954e0 100644 --- a/exporters/trace/gcp_exporter/recordable.h +++ b/exporters/trace/gcp_exporter/recordable.h @@ -22,16 +22,24 @@ class Recordable final : public sdk::trace::Recordable public: const google::devtools::cloudtrace::v2::Span &span() const noexcept { return span_; } - void SetIds(trace::TraceId trace_id, - trace::SpanId span_id, - trace::SpanId parent_span_id) noexcept override; + void SetIds(opentelemetry::trace::TraceId trace_id, + opentelemetry::trace::SpanId span_id, + opentelemetry::trace::SpanId parent_span_id) noexcept override; void SetAttribute(nostd::string_view key, - const opentelemetry::common::AttributeValue &&value) noexcept override; + const opentelemetry::common::AttributeValue &value) noexcept override; - void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept override; + void AddEvent( + nostd::string_view name, + core::SystemTimestamp timestamp, + const opentelemetry::trace::KeyValueIterable &attributes) noexcept override; - void SetStatus(trace::CanonicalCode code, nostd::string_view description) noexcept override; + void AddLink( + opentelemetry::trace::SpanContext span_context, + const opentelemetry::trace::KeyValueIterable &attributes) noexcept override; + + void SetStatus(opentelemetry::trace::CanonicalCode code, + nostd::string_view description) noexcept override; void SetName(nostd::string_view name) noexcept override;