From bd5348ebb5e207f603820189c5cdaf40faf7d852 Mon Sep 17 00:00:00 2001 From: erichsueh3 Date: Tue, 25 Aug 2020 14:56:35 -0700 Subject: [PATCH 1/2] modified instrument.h KvToString() to remove double quote characters, allows for Prometheus to Collect() on records correctly --- sdk/include/opentelemetry/sdk/metrics/instrument.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/metrics/instrument.h b/sdk/include/opentelemetry/sdk/metrics/instrument.h index 85de5ee701..802e201bc6 100644 --- a/sdk/include/opentelemetry/sdk/metrics/instrument.h +++ b/sdk/include/opentelemetry/sdk/metrics/instrument.h @@ -244,11 +244,9 @@ inline void print_value(std::stringstream &ss, switch (value.index()) { case common::AttributeType::TYPE_STRING: - if (jsonTypes) - ss << '"'; + ss << nostd::get(value); - if (jsonTypes) - ss << '"'; + break; default: #if __EXCEPTIONS @@ -282,7 +280,7 @@ inline std::string KvToString(const trace::KeyValueIterable &kv) noexcept { size_t i = 1; kv.ForEachKeyValue([&](nostd::string_view key, common::AttributeValue value) noexcept { - ss << "\"" << key << "\":"; + ss << key << ":"; print_value(ss, value, true); if (size != i) { From d1ead8b63cab01bb68b03348f1f734781485cd39 Mon Sep 17 00:00:00 2001 From: erichsueh3 Date: Wed, 26 Aug 2020 12:00:59 -0700 Subject: [PATCH 2/2] fixed tests to reflect removal of double quote characters --- sdk/test/metrics/metric_instrument_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/test/metrics/metric_instrument_test.cc b/sdk/test/metrics/metric_instrument_test.cc index 3518c54604..2849d1b19c 100644 --- a/sdk/test/metrics/metric_instrument_test.cc +++ b/sdk/test/metrics/metric_instrument_test.cc @@ -35,7 +35,7 @@ TEST(ApiSdkConversion, async) alpha->observe(123456, labelkv); EXPECT_EQ(dynamic_cast *>(alpha.get())->GetRecords()[0].GetLabels(), - "{\"key587\":\"value264\"}"); + "{key587:value264}"); alpha->observe(123456, labelkv); AggregatorVariant canCollect = @@ -257,7 +257,7 @@ TEST(Counter, getAggsandnewupdate) EXPECT_EQ(theta.size(), 1); EXPECT_EQ(theta[0].GetName(), "test"); EXPECT_EQ(theta[0].GetDescription(), "none"); - EXPECT_EQ(theta[0].GetLabels(), "{\"key2\":\"value2\",\"key3\":\"value3\"}"); + EXPECT_EQ(theta[0].GetLabels(), "{key2:value2,key3:value3}"); } void CounterCallback(std::shared_ptr> in,