From 408d5138e6a6f377ec2f0decfe6966c1da694611 Mon Sep 17 00:00:00 2001 From: Matthijs Brobbel Date: Tue, 26 Sep 2023 17:19:58 +0200 Subject: [PATCH 01/10] Group spans by resource and instrumentation scope in OTLP export requests --- .../exporters/otlp/otlp_recordable.h | 3 ++ exporters/otlp/src/otlp_recordable.cc | 11 +++++ exporters/otlp/src/otlp_recordable_utils.cc | 46 +++++++++++++++---- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h index 29bc6011f9..bc505a959b 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h @@ -27,7 +27,10 @@ class OtlpRecordable final : public opentelemetry::sdk::trace::Recordable /** Dynamically converts the resource of this span into a proto. */ proto::resource::v1::Resource ProtoResource() const noexcept; + const opentelemetry::sdk::resource::Resource *GetResource() const noexcept; const std::string GetResourceSchemaURL() const noexcept; + const opentelemetry::sdk::instrumentationscope::InstrumentationScope *GetInstrumentationScope() + const noexcept; const std::string GetInstrumentationLibrarySchemaURL() const noexcept; proto::common::v1::InstrumentationScope GetProtoInstrumentationScope() const noexcept; diff --git a/exporters/otlp/src/otlp_recordable.cc b/exporters/otlp/src/otlp_recordable.cc index e0b181a452..a3ab4327f2 100644 --- a/exporters/otlp/src/otlp_recordable.cc +++ b/exporters/otlp/src/otlp_recordable.cc @@ -40,6 +40,11 @@ proto::resource::v1::Resource OtlpRecordable::ProtoResource() const noexcept return proto; } +const opentelemetry::sdk::resource::Resource *OtlpRecordable::GetResource() const noexcept +{ + return resource_; +} + const std::string OtlpRecordable::GetResourceSchemaURL() const noexcept { std::string schema_url; @@ -51,6 +56,12 @@ const std::string OtlpRecordable::GetResourceSchemaURL() const noexcept return schema_url; } +const opentelemetry::sdk::instrumentationscope::InstrumentationScope * +OtlpRecordable::GetInstrumentationScope() const noexcept +{ + return instrumentation_scope_; +} + const std::string OtlpRecordable::GetInstrumentationLibrarySchemaURL() const noexcept { std::string schema_url; diff --git a/exporters/otlp/src/otlp_recordable_utils.cc b/exporters/otlp/src/otlp_recordable_utils.cc index 1b1da94e08..a82ff90dda 100644 --- a/exporters/otlp/src/otlp_recordable_utils.cc +++ b/exporters/otlp/src/otlp_recordable_utils.cc @@ -56,19 +56,49 @@ void OtlpRecordableUtils::PopulateRequest( return; } + using spans_by_scope = + std::unordered_map>, + InstrumentationScopePointerHasher, InstrumentationScopePointerEqual>; + std::unordered_map spans_index; + + // Collect spans per resource and instrumentation scope for (auto &recordable : spans) { auto rec = std::unique_ptr(static_cast(recordable.release())); - auto resource_span = request->add_resource_spans(); - auto scope_spans = resource_span->add_scope_spans(); + auto resource = rec->GetResource(); + auto instrumentation = rec->GetInstrumentationScope(); - *scope_spans->add_spans() = std::move(rec->span()); - *scope_spans->mutable_scope() = rec->GetProtoInstrumentationScope(); - - scope_spans->set_schema_url(rec->GetInstrumentationLibrarySchemaURL()); + spans_index[resource][instrumentation].emplace_back(std::move(rec)); + } - *resource_span->mutable_resource() = rec->ProtoResource(); - resource_span->set_schema_url(rec->GetResourceSchemaURL()); + // Add all resource spans + for (auto &input_resource_spans : spans_index) + { + // Add the resource + auto resource_spans = request->add_resource_spans(); + proto::resource::v1::Resource resource_proto; + OtlpPopulateAttributeUtils::PopulateAttribute(&resource_proto, *input_resource_spans.first); + *resource_spans->mutable_resource() = resource_proto; + resource_spans->set_schema_url(input_resource_spans.first->GetSchemaURL()); + + // Add all scope spans + for (auto &input_scope_spans : input_resource_spans.second) + { + // Add the instrumentation scope + auto scope_spans = resource_spans->add_scope_spans(); + proto::common::v1::InstrumentationScope instrumentation_scope_proto; + instrumentation_scope_proto.set_name(input_scope_spans.first->GetName()); + instrumentation_scope_proto.set_version(input_scope_spans.first->GetVersion()); + *scope_spans->mutable_scope() = instrumentation_scope_proto; + scope_spans->set_schema_url(input_scope_spans.first->GetSchemaURL()); + + // Add all spans to this scope spans + for (auto &input_scope_spans : input_scope_spans.second) + { + *scope_spans->add_spans() = std::move(input_scope_spans->span()); + } + } } } From 4c9164adfd5e8210dd6ee9b997174c635ac4c40a Mon Sep 17 00:00:00 2001 From: Matthijs Brobbel Date: Tue, 26 Sep 2023 22:30:35 +0200 Subject: [PATCH 02/10] Add a test --- exporters/otlp/test/otlp_recordable_test.cc | 50 +++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/exporters/otlp/test/otlp_recordable_test.cc b/exporters/otlp/test/otlp_recordable_test.cc index 4db58844f7..9565041cb8 100644 --- a/exporters/otlp/test/otlp_recordable_test.cc +++ b/exporters/otlp/test/otlp_recordable_test.cc @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/exporters/otlp/otlp_recordable.h" +#include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" #include "opentelemetry/sdk/resource/resource.h" #if defined(__GNUC__) @@ -285,6 +286,55 @@ TEST(OtlpRecordable, SetArrayAttribute) } } +// Test otlp resource populate request util +TEST(OtlpRecordable, PopulateRequest) +{ + auto rec1 = std::unique_ptr(new OtlpRecordable); + const std::string service_name_key = "service.name"; + std::string service_name1 = "one"; + auto resource1 = resource::Resource::Create({{service_name_key, service_name1}}); + rec1->SetResource(resource1); + auto inst_lib1 = trace_sdk::InstrumentationScope::Create("one", "1"); + rec1->SetInstrumentationScope(*inst_lib1); + + auto rec2 = std::unique_ptr(new OtlpRecordable); + std::string service_name2 = "two"; + auto resource2 = resource::Resource::Create({{service_name_key, service_name2}}); + rec2->SetResource(resource2); + auto inst_lib2 = trace_sdk::InstrumentationScope::Create("two", "2"); + rec2->SetInstrumentationScope(*inst_lib2); + + // This has the same resource as rec2, but a different scope + auto rec3 = std::unique_ptr(new OtlpRecordable); + rec3->SetResource(resource2); + auto inst_lib3 = trace_sdk::InstrumentationScope::Create("three", "3"); + rec3->SetInstrumentationScope(*inst_lib3); + + proto::collector::trace::v1::ExportTraceServiceRequest req; + std::vector> spans; + spans.push_back(std::move(rec1)); + spans.push_back(std::move(rec2)); + spans.push_back(std::move(rec3)); + const nostd::span, 3> spans_span(spans.data(), 3); + OtlpRecordableUtils::PopulateRequest(spans_span, &req); + + EXPECT_EQ(req.resource_spans().size(), 2); + for (auto resource_spans : req.resource_spans()) + { + auto service_name = resource_spans.resource().attributes(0).value().string_value(); + auto scope_spans_size = resource_spans.scope_spans().size(); + if (service_name == "one") + { + EXPECT_EQ(scope_spans_size, 1); + EXPECT_EQ(resource_spans.scope_spans(0).scope().name(), "one"); + } + if (service_name == "two") + { + EXPECT_EQ(scope_spans_size, 2); + } + } +} + template struct EmptyArrayAttributeTest : public testing::Test { From b125116daaaf6fe17085fc75ba95cf09e73250d4 Mon Sep 17 00:00:00 2001 From: Matthijs Brobbel Date: Wed, 27 Sep 2023 09:37:47 +0200 Subject: [PATCH 03/10] Use `std::vector` instead of `std::list` in spans map --- exporters/otlp/src/otlp_recordable_utils.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporters/otlp/src/otlp_recordable_utils.cc b/exporters/otlp/src/otlp_recordable_utils.cc index a82ff90dda..c330f60a44 100644 --- a/exporters/otlp/src/otlp_recordable_utils.cc +++ b/exporters/otlp/src/otlp_recordable_utils.cc @@ -58,7 +58,7 @@ void OtlpRecordableUtils::PopulateRequest( using spans_by_scope = std::unordered_map>, + std::vector>, InstrumentationScopePointerHasher, InstrumentationScopePointerEqual>; std::unordered_map spans_index; From ed3e87e31e40cbef07e9c307b3cd1a7ed8aba936 Mon Sep 17 00:00:00 2001 From: Matthijs Brobbel Date: Wed, 27 Sep 2023 09:37:59 +0200 Subject: [PATCH 04/10] Use `std::make_unique` --- exporters/otlp/test/otlp_recordable_test.cc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/exporters/otlp/test/otlp_recordable_test.cc b/exporters/otlp/test/otlp_recordable_test.cc index 9565041cb8..2fd8b3d9b0 100644 --- a/exporters/otlp/test/otlp_recordable_test.cc +++ b/exporters/otlp/test/otlp_recordable_test.cc @@ -289,23 +289,20 @@ TEST(OtlpRecordable, SetArrayAttribute) // Test otlp resource populate request util TEST(OtlpRecordable, PopulateRequest) { - auto rec1 = std::unique_ptr(new OtlpRecordable); - const std::string service_name_key = "service.name"; - std::string service_name1 = "one"; - auto resource1 = resource::Resource::Create({{service_name_key, service_name1}}); + std::unique_ptr rec1 = std::make_unique(); + auto resource1 = resource::Resource::Create({{"service.name", "one"}}); rec1->SetResource(resource1); auto inst_lib1 = trace_sdk::InstrumentationScope::Create("one", "1"); rec1->SetInstrumentationScope(*inst_lib1); - auto rec2 = std::unique_ptr(new OtlpRecordable); - std::string service_name2 = "two"; - auto resource2 = resource::Resource::Create({{service_name_key, service_name2}}); + std::unique_ptr rec2 = std::make_unique(); + auto resource2 = resource::Resource::Create({{"service.name", "two"}}); rec2->SetResource(resource2); auto inst_lib2 = trace_sdk::InstrumentationScope::Create("two", "2"); rec2->SetInstrumentationScope(*inst_lib2); // This has the same resource as rec2, but a different scope - auto rec3 = std::unique_ptr(new OtlpRecordable); + std::unique_ptr rec3 = std::make_unique(); rec3->SetResource(resource2); auto inst_lib3 = trace_sdk::InstrumentationScope::Create("three", "3"); rec3->SetInstrumentationScope(*inst_lib3); From 9a73f02c68e00f70fb519de842698448ec62b7ad Mon Sep 17 00:00:00 2001 From: Matthijs Brobbel Date: Wed, 27 Sep 2023 11:37:33 +0200 Subject: [PATCH 05/10] Revert "Use `std::make_unique`" This reverts commit ed3e87e31e40cbef07e9c307b3cd1a7ed8aba936. --- exporters/otlp/test/otlp_recordable_test.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/exporters/otlp/test/otlp_recordable_test.cc b/exporters/otlp/test/otlp_recordable_test.cc index 2fd8b3d9b0..9565041cb8 100644 --- a/exporters/otlp/test/otlp_recordable_test.cc +++ b/exporters/otlp/test/otlp_recordable_test.cc @@ -289,20 +289,23 @@ TEST(OtlpRecordable, SetArrayAttribute) // Test otlp resource populate request util TEST(OtlpRecordable, PopulateRequest) { - std::unique_ptr rec1 = std::make_unique(); - auto resource1 = resource::Resource::Create({{"service.name", "one"}}); + auto rec1 = std::unique_ptr(new OtlpRecordable); + const std::string service_name_key = "service.name"; + std::string service_name1 = "one"; + auto resource1 = resource::Resource::Create({{service_name_key, service_name1}}); rec1->SetResource(resource1); auto inst_lib1 = trace_sdk::InstrumentationScope::Create("one", "1"); rec1->SetInstrumentationScope(*inst_lib1); - std::unique_ptr rec2 = std::make_unique(); - auto resource2 = resource::Resource::Create({{"service.name", "two"}}); + auto rec2 = std::unique_ptr(new OtlpRecordable); + std::string service_name2 = "two"; + auto resource2 = resource::Resource::Create({{service_name_key, service_name2}}); rec2->SetResource(resource2); auto inst_lib2 = trace_sdk::InstrumentationScope::Create("two", "2"); rec2->SetInstrumentationScope(*inst_lib2); // This has the same resource as rec2, but a different scope - std::unique_ptr rec3 = std::make_unique(); + auto rec3 = std::unique_ptr(new OtlpRecordable); rec3->SetResource(resource2); auto inst_lib3 = trace_sdk::InstrumentationScope::Create("three", "3"); rec3->SetInstrumentationScope(*inst_lib3); From 2d49291f8bc314d6b4e85150bdcca636babe82d6 Mon Sep 17 00:00:00 2001 From: Matthijs Brobbel Date: Wed, 27 Sep 2023 11:40:35 +0200 Subject: [PATCH 06/10] Fix variable shadowing --- exporters/otlp/src/otlp_recordable_utils.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exporters/otlp/src/otlp_recordable_utils.cc b/exporters/otlp/src/otlp_recordable_utils.cc index c330f60a44..b14f6edfab 100644 --- a/exporters/otlp/src/otlp_recordable_utils.cc +++ b/exporters/otlp/src/otlp_recordable_utils.cc @@ -94,9 +94,9 @@ void OtlpRecordableUtils::PopulateRequest( scope_spans->set_schema_url(input_scope_spans.first->GetSchemaURL()); // Add all spans to this scope spans - for (auto &input_scope_spans : input_scope_spans.second) + for (auto &input_span : input_scope_spans.second) { - *scope_spans->add_spans() = std::move(input_scope_spans->span()); + *scope_spans->add_spans() = std::move(input_span->span()); } } } From f428ab7fa3c251adda61a5d71986cf1ea60e1348 Mon Sep 17 00:00:00 2001 From: Matthijs Brobbel Date: Wed, 27 Sep 2023 12:43:42 +0200 Subject: [PATCH 07/10] Add `nullptr` check --- exporters/otlp/src/otlp_recordable_utils.cc | 24 +++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/exporters/otlp/src/otlp_recordable_utils.cc b/exporters/otlp/src/otlp_recordable_utils.cc index b14f6edfab..60e8b944de 100644 --- a/exporters/otlp/src/otlp_recordable_utils.cc +++ b/exporters/otlp/src/otlp_recordable_utils.cc @@ -77,21 +77,27 @@ void OtlpRecordableUtils::PopulateRequest( { // Add the resource auto resource_spans = request->add_resource_spans(); - proto::resource::v1::Resource resource_proto; - OtlpPopulateAttributeUtils::PopulateAttribute(&resource_proto, *input_resource_spans.first); - *resource_spans->mutable_resource() = resource_proto; - resource_spans->set_schema_url(input_resource_spans.first->GetSchemaURL()); + if (input_resource_spans.first) + { + proto::resource::v1::Resource resource_proto; + OtlpPopulateAttributeUtils::PopulateAttribute(&resource_proto, *input_resource_spans.first); + *resource_spans->mutable_resource() = resource_proto; + resource_spans->set_schema_url(input_resource_spans.first->GetSchemaURL()); + } // Add all scope spans for (auto &input_scope_spans : input_resource_spans.second) { // Add the instrumentation scope auto scope_spans = resource_spans->add_scope_spans(); - proto::common::v1::InstrumentationScope instrumentation_scope_proto; - instrumentation_scope_proto.set_name(input_scope_spans.first->GetName()); - instrumentation_scope_proto.set_version(input_scope_spans.first->GetVersion()); - *scope_spans->mutable_scope() = instrumentation_scope_proto; - scope_spans->set_schema_url(input_scope_spans.first->GetSchemaURL()); + if (input_scope_spans.first) + { + proto::common::v1::InstrumentationScope instrumentation_scope_proto; + instrumentation_scope_proto.set_name(input_scope_spans.first->GetName()); + instrumentation_scope_proto.set_version(input_scope_spans.first->GetVersion()); + *scope_spans->mutable_scope() = instrumentation_scope_proto; + scope_spans->set_schema_url(input_scope_spans.first->GetSchemaURL()); + } // Add all spans to this scope spans for (auto &input_span : input_scope_spans.second) From c2471c86b319015dce625a99f6ea8e4576675d0c Mon Sep 17 00:00:00 2001 From: Matthijs Brobbel Date: Wed, 27 Sep 2023 13:23:40 +0200 Subject: [PATCH 08/10] Don't use `InstrumentationScopePointerHasher` and `InstrumentationScopePointerEqual` --- exporters/otlp/src/otlp_recordable_utils.cc | 3 +- exporters/otlp/test/otlp_recordable_test.cc | 55 ++++++++++++++++++--- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/exporters/otlp/src/otlp_recordable_utils.cc b/exporters/otlp/src/otlp_recordable_utils.cc index 60e8b944de..59e4aadf4e 100644 --- a/exporters/otlp/src/otlp_recordable_utils.cc +++ b/exporters/otlp/src/otlp_recordable_utils.cc @@ -58,8 +58,7 @@ void OtlpRecordableUtils::PopulateRequest( using spans_by_scope = std::unordered_map>, - InstrumentationScopePointerHasher, InstrumentationScopePointerEqual>; + std::vector>>; std::unordered_map spans_index; // Collect spans per resource and instrumentation scope diff --git a/exporters/otlp/test/otlp_recordable_test.cc b/exporters/otlp/test/otlp_recordable_test.cc index 9565041cb8..09d0b3661d 100644 --- a/exporters/otlp/test/otlp_recordable_test.cc +++ b/exporters/otlp/test/otlp_recordable_test.cc @@ -289,17 +289,14 @@ TEST(OtlpRecordable, SetArrayAttribute) // Test otlp resource populate request util TEST(OtlpRecordable, PopulateRequest) { - auto rec1 = std::unique_ptr(new OtlpRecordable); - const std::string service_name_key = "service.name"; - std::string service_name1 = "one"; - auto resource1 = resource::Resource::Create({{service_name_key, service_name1}}); + auto rec1 = std::unique_ptr(new OtlpRecordable); + auto resource1 = resource::Resource::Create({{"service.name", "one"}}); rec1->SetResource(resource1); auto inst_lib1 = trace_sdk::InstrumentationScope::Create("one", "1"); rec1->SetInstrumentationScope(*inst_lib1); - auto rec2 = std::unique_ptr(new OtlpRecordable); - std::string service_name2 = "two"; - auto resource2 = resource::Resource::Create({{service_name_key, service_name2}}); + auto rec2 = std::unique_ptr(new OtlpRecordable); + auto resource2 = resource::Resource::Create({{"service.name", "two"}}); rec2->SetResource(resource2); auto inst_lib2 = trace_sdk::InstrumentationScope::Create("two", "2"); rec2->SetInstrumentationScope(*inst_lib2); @@ -335,6 +332,50 @@ TEST(OtlpRecordable, PopulateRequest) } } +// Test otlp resource populate request util with missing data +TEST(OtlpRecordable, PopulateRequestMissing) +{ + // Missing scope + auto rec1 = std::unique_ptr(new OtlpRecordable); + auto resource1 = resource::Resource::Create({{"service.name", "one"}}); + rec1->SetResource(resource1); + + // Missing resource + auto rec2 = std::unique_ptr(new OtlpRecordable); + auto inst_lib2 = trace_sdk::InstrumentationScope::Create("two", "2"); + rec2->SetInstrumentationScope(*inst_lib2); + + proto::collector::trace::v1::ExportTraceServiceRequest req; + std::vector> spans; + spans.push_back(std::move(rec1)); + spans.push_back(std::move(rec2)); + const nostd::span, 2> spans_span(spans.data(), 2); + OtlpRecordableUtils::PopulateRequest(spans_span, &req); + + EXPECT_EQ(req.resource_spans().size(), 2); + for (auto resource_spans : req.resource_spans()) + { + // Select the one with missing scope + if (resource_spans.resource().attributes().size() != 0) + { + // It has a service name + EXPECT_EQ(resource_spans.resource().attributes(0).value().string_value(), "one"); + // And scope spans + EXPECT_EQ(resource_spans.scope_spans().size(), 1); + // But the scope data is missing + EXPECT_EQ(resource_spans.scope_spans(0).scope().name(), ""); + } + else + { + // It has no resource attributes + EXPECT_EQ(resource_spans.resource().attributes().size(), 0); + // It has a scope + EXPECT_EQ(resource_spans.scope_spans().size(), 1); + EXPECT_EQ(resource_spans.scope_spans(0).scope().name(), "two"); + } + } +} + template struct EmptyArrayAttributeTest : public testing::Test { From 0fdc79ac4fb4d2a39696f4d36e1b5343dc8f141f Mon Sep 17 00:00:00 2001 From: Matthijs Brobbel Date: Wed, 27 Sep 2023 13:49:26 +0200 Subject: [PATCH 09/10] Fix test --- exporters/otlp/test/otlp_recordable_test.cc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/exporters/otlp/test/otlp_recordable_test.cc b/exporters/otlp/test/otlp_recordable_test.cc index 09d0b3661d..7762e12556 100644 --- a/exporters/otlp/test/otlp_recordable_test.cc +++ b/exporters/otlp/test/otlp_recordable_test.cc @@ -355,23 +355,22 @@ TEST(OtlpRecordable, PopulateRequestMissing) EXPECT_EQ(req.resource_spans().size(), 2); for (auto resource_spans : req.resource_spans()) { + // Both should have scope spans + EXPECT_EQ(resource_spans.scope_spans().size(), 1); // Select the one with missing scope - if (resource_spans.resource().attributes().size() != 0) + if (resource_spans.resource().attributes().size() > 0 && + resource_spans.resource().attributes(0).value().string_value() == "one") { - // It has a service name - EXPECT_EQ(resource_spans.resource().attributes(0).value().string_value(), "one"); - // And scope spans - EXPECT_EQ(resource_spans.scope_spans().size(), 1); - // But the scope data is missing + // Scope data is missing EXPECT_EQ(resource_spans.scope_spans(0).scope().name(), ""); + EXPECT_EQ(resource_spans.scope_spans(0).scope().version(), ""); } else { - // It has no resource attributes + // The other has no resource attributes EXPECT_EQ(resource_spans.resource().attributes().size(), 0); - // It has a scope - EXPECT_EQ(resource_spans.scope_spans().size(), 1); EXPECT_EQ(resource_spans.scope_spans(0).scope().name(), "two"); + EXPECT_EQ(resource_spans.scope_spans(0).scope().version(), "2"); } } } From c1a474ec57cdb471a057620a105cb00dbf2a52bf Mon Sep 17 00:00:00 2001 From: Matthijs Brobbel Date: Wed, 27 Sep 2023 15:19:59 +0200 Subject: [PATCH 10/10] Fix test --- exporters/otlp/test/otlp_recordable_test.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/exporters/otlp/test/otlp_recordable_test.cc b/exporters/otlp/test/otlp_recordable_test.cc index 7762e12556..9f3ba62b16 100644 --- a/exporters/otlp/test/otlp_recordable_test.cc +++ b/exporters/otlp/test/otlp_recordable_test.cc @@ -357,20 +357,18 @@ TEST(OtlpRecordable, PopulateRequestMissing) { // Both should have scope spans EXPECT_EQ(resource_spans.scope_spans().size(), 1); + auto scope = resource_spans.scope_spans(0).scope(); // Select the one with missing scope - if (resource_spans.resource().attributes().size() > 0 && - resource_spans.resource().attributes(0).value().string_value() == "one") + if (scope.name() == "") { - // Scope data is missing - EXPECT_EQ(resource_spans.scope_spans(0).scope().name(), ""); - EXPECT_EQ(resource_spans.scope_spans(0).scope().version(), ""); + // Version is also empty + EXPECT_EQ(scope.version(), ""); } else { - // The other has no resource attributes - EXPECT_EQ(resource_spans.resource().attributes().size(), 0); - EXPECT_EQ(resource_spans.scope_spans(0).scope().name(), "two"); - EXPECT_EQ(resource_spans.scope_spans(0).scope().version(), "2"); + // The other has a name and version + EXPECT_EQ(scope.name(), "two"); + EXPECT_EQ(scope.version(), "2"); } } }