From 8b7aee9efaba14ad9cafee0587f7d9f970741bea Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Wed, 29 Jun 2022 11:12:26 -0700 Subject: [PATCH 1/5] Removing referece to deprecated InstrumentationLibrary in OTLP --- .../opentelemetry/exporters/otlp/otlp_recordable.h | 2 +- exporters/otlp/src/otlp_recordable.cc | 10 +++++----- exporters/otlp/src/otlp_recordable_utils.cc | 8 ++++---- exporters/otlp/test/otlp_recordable_test.cc | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h index a29d063a92..dcbcf42129 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h @@ -30,7 +30,7 @@ class OtlpRecordable final : public opentelemetry::sdk::trace::Recordable const std::string GetResourceSchemaURL() const noexcept; const std::string GetInstrumentationLibrarySchemaURL() const noexcept; - proto::common::v1::InstrumentationLibrary GetProtoInstrumentationLibrary() const noexcept; + proto::common::v1::InstrumentationScope GetProtoInstrumentationScope() const noexcept; void SetIdentity(const opentelemetry::trace::SpanContext &span_context, opentelemetry::trace::SpanId parent_span_id) noexcept override; diff --git a/exporters/otlp/src/otlp_recordable.cc b/exporters/otlp/src/otlp_recordable.cc index 93281c3865..e31d773e15 100644 --- a/exporters/otlp/src/otlp_recordable.cc +++ b/exporters/otlp/src/otlp_recordable.cc @@ -62,16 +62,16 @@ const std::string OtlpRecordable::GetInstrumentationLibrarySchemaURL() const noe return schema_url; } -proto::common::v1::InstrumentationLibrary OtlpRecordable::GetProtoInstrumentationLibrary() +proto::common::v1::InstrumentationScope OtlpRecordable::GetProtoInstrumentationScope() const noexcept { - proto::common::v1::InstrumentationLibrary instrumentation_library; + proto::common::v1::InstrumentationScope instrumentation_scope; if (instrumentation_library_) { - instrumentation_library.set_name(instrumentation_library_->GetName()); - instrumentation_library.set_version(instrumentation_library_->GetVersion()); + instrumentation_scope.set_name(instrumentation_library_->GetName()); + instrumentation_scope.set_version(instrumentation_library_->GetVersion()); } - return instrumentation_library; + return instrumentation_scope; } void OtlpRecordable::SetResource(const sdk::resource::Resource &resource) noexcept diff --git a/exporters/otlp/src/otlp_recordable_utils.cc b/exporters/otlp/src/otlp_recordable_utils.cc index 427037034b..d13fbbf236 100644 --- a/exporters/otlp/src/otlp_recordable_utils.cc +++ b/exporters/otlp/src/otlp_recordable_utils.cc @@ -60,12 +60,12 @@ void OtlpRecordableUtils::PopulateRequest( { auto rec = std::unique_ptr(static_cast(recordable.release())); auto resource_span = request->add_resource_spans(); - auto instrumentation_lib = resource_span->add_instrumentation_library_spans(); + auto scope_spans = resource_span->add_scope_spans(); - *instrumentation_lib->add_spans() = std::move(rec->span()); - *instrumentation_lib->mutable_instrumentation_library() = rec->GetProtoInstrumentationLibrary(); + *scope_spans->add_spans() = std::move(rec->span()); + *scope_spans->mutable_scope() = rec->GetProtoInstrumentationScope(); - instrumentation_lib->set_schema_url(rec->GetInstrumentationLibrarySchemaURL()); + scope_spans->set_schema_url(rec->GetInstrumentationLibrarySchemaURL()); *resource_span->mutable_resource() = rec->ProtoResource(); resource_span->set_schema_url(rec->GetResourceSchemaURL()); diff --git a/exporters/otlp/test/otlp_recordable_test.cc b/exporters/otlp/test/otlp_recordable_test.cc index 049f3e5aeb..630c31dc2f 100644 --- a/exporters/otlp/test/otlp_recordable_test.cc +++ b/exporters/otlp/test/otlp_recordable_test.cc @@ -64,7 +64,7 @@ TEST(OtlpRecordable, SetInstrumentationLibrary) OtlpRecordable rec; auto inst_lib = trace_sdk::InstrumentationLibrary::Create("test", "v1"); rec.SetInstrumentationLibrary(*inst_lib); - auto proto_instr_libr = rec.GetProtoInstrumentationLibrary(); + auto proto_instr_libr = rec.GetProtoInstrumentationScope(); EXPECT_EQ(proto_instr_libr.name(), inst_lib->GetName()); EXPECT_EQ(proto_instr_libr.version(), inst_lib->GetVersion()); } From bbf3a8276f2b7c0ef8cf6c0e5095d646ada7590a Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Wed, 29 Jun 2022 11:37:12 -0700 Subject: [PATCH 2/5] Fix format --- exporters/otlp/src/otlp_recordable_utils.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exporters/otlp/src/otlp_recordable_utils.cc b/exporters/otlp/src/otlp_recordable_utils.cc index d13fbbf236..14c0dffdab 100644 --- a/exporters/otlp/src/otlp_recordable_utils.cc +++ b/exporters/otlp/src/otlp_recordable_utils.cc @@ -59,10 +59,10 @@ void OtlpRecordableUtils::PopulateRequest( 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_span = request->add_resource_spans(); + auto scope_spans = resource_span->add_scope_spans(); - *scope_spans->add_spans() = std::move(rec->span()); + *scope_spans->add_spans() = std::move(rec->span()); *scope_spans->mutable_scope() = rec->GetProtoInstrumentationScope(); scope_spans->set_schema_url(rec->GetInstrumentationLibrarySchemaURL()); From 0a78bbb0e93bc5ebf08b7666f85facfc1994a8ee Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Wed, 29 Jun 2022 11:56:23 -0700 Subject: [PATCH 3/5] Fix test --- exporters/otlp/test/otlp_http_exporter_test.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index ef0b5a509e..c2a8669652 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -142,8 +142,8 @@ TEST_F(OtlpHttpExporterTestPeer, ExportJsonIntegrationTest) report_trace_id](opentelemetry::ext::http::client::EventHandler &callback) { auto check_json = nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); auto resource_span = *check_json["resource_spans"].begin(); - auto instrumentation_library_span = *resource_span["instrumentation_library_spans"].begin(); - auto span = *instrumentation_library_span["spans"].begin(); + auto scope_span = *resource_span["scope_spans"].begin(); + auto span = *scope_span["spans"].begin(); auto received_trace_id = span["trace_id"].get(); EXPECT_EQ(received_trace_id, report_trace_id); @@ -223,7 +223,7 @@ TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTest) request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], static_cast(mock_session->GetRequest()->body_.size())); auto received_trace_id = - request_body.resource_spans(0).instrumentation_library_spans(0).spans(0).trace_id(); + request_body.resource_spans(0).scope_spans(0).spans(0).trace_id(); EXPECT_EQ(received_trace_id, report_trace_id); auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); From 92bd7f4b90b26089fbbd8547824c84457c94069d Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Wed, 29 Jun 2022 13:02:33 -0700 Subject: [PATCH 4/5] Fix format in test --- exporters/otlp/test/otlp_http_exporter_test.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index c2a8669652..c2fc66ed12 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -141,10 +141,10 @@ TEST_F(OtlpHttpExporterTestPeer, ExportJsonIntegrationTest) .WillOnce([&mock_session, report_trace_id](opentelemetry::ext::http::client::EventHandler &callback) { auto check_json = nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_span = *check_json["resource_spans"].begin(); - auto scope_span = *resource_span["scope_spans"].begin(); - auto span = *scope_span["spans"].begin(); - auto received_trace_id = span["trace_id"].get(); + auto resource_span = *check_json["resource_spans"].begin(); + auto scope_span = *resource_span["scope_spans"].begin(); + auto span = *scope_span["spans"].begin(); + auto received_trace_id = span["trace_id"].get(); EXPECT_EQ(received_trace_id, report_trace_id); auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); From adb702426f327005e070b58fa0a87c36c06dfe77 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Wed, 29 Jun 2022 13:19:17 -0700 Subject: [PATCH 5/5] More format in test code --- exporters/otlp/test/otlp_http_exporter_test.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index c2fc66ed12..d773adf788 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -222,8 +222,7 @@ TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTest) opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest request_body; request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], static_cast(mock_session->GetRequest()->body_.size())); - auto received_trace_id = - request_body.resource_spans(0).scope_spans(0).spans(0).trace_id(); + auto received_trace_id = request_body.resource_spans(0).scope_spans(0).spans(0).trace_id(); EXPECT_EQ(received_trace_id, report_trace_id); auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key");