From 062bc09feaf4f93c3ce9afeb0e4d4f87805d435f Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 27 Apr 2021 03:49:44 +0530 Subject: [PATCH 01/14] draft --- exporters/memory/CMakeLists.txt | 4 ++-- .../opentelemetry/exporters/otlp/recordable.h | 2 ++ exporters/otlp/src/recordable.cc | 6 ++++++ .../opentelemetry/exporters/zipkin/recordable.h | 6 +++++- exporters/zipkin/src/recordable.cc | 6 ++++++ sdk/include/opentelemetry/sdk/trace/recordable.h | 8 ++++++++ sdk/include/opentelemetry/sdk/trace/span_data.h | 14 ++++++++++++++ sdk/include/opentelemetry/sdk/trace/tracer.h | 3 +++ sdk/src/trace/span.cc | 2 +- 9 files changed, 47 insertions(+), 4 deletions(-) diff --git a/exporters/memory/CMakeLists.txt b/exporters/memory/CMakeLists.txt index 870e932730..913c9cc3bc 100644 --- a/exporters/memory/CMakeLists.txt +++ b/exporters/memory/CMakeLists.txt @@ -30,11 +30,11 @@ if(BUILD_TESTING) target_link_libraries( in_memory_span_data_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} - opentelemetry_exporter_in_memory) + opentelemetry_exporter_in_memory opentelemetry_resources) target_link_libraries( in_memory_span_exporter_test ${GTEST_BOTH_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} opentelemetry_exporter_in_memory) + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_exporter_in_memory opentelemetry_resources) gtest_add_tests( TARGET in_memory_span_data_test diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h b/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h index b4d7fae38d..0b0f3f3ca5 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h @@ -38,6 +38,8 @@ class Recordable final : public sdk::trace::Recordable void SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept override; + void SetResource( const opentelemetry::sdk::resource::Resource& resource) noexcept override; + void SetStartTime(opentelemetry::core::SystemTimestamp start_time) noexcept override; void SetDuration(std::chrono::nanoseconds duration) noexcept override; diff --git a/exporters/otlp/src/recordable.cc b/exporters/otlp/src/recordable.cc index b236ef125e..a6fd9a8902 100644 --- a/exporters/otlp/src/recordable.cc +++ b/exporters/otlp/src/recordable.cc @@ -213,6 +213,12 @@ void Recordable::SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept span_.set_kind(proto_span_kind); } + void SetResource( const opentelemetry::sdk::resource::Resource& resource) noexcept + { + + } + + void Recordable::SetStartTime(opentelemetry::core::SystemTimestamp start_time) noexcept { span_.set_start_time_unix_nano(start_time.time_since_epoch().count()); diff --git a/exporters/zipkin/include/opentelemetry/exporters/zipkin/recordable.h b/exporters/zipkin/include/opentelemetry/exporters/zipkin/recordable.h index f72dc4414f..801d529839 100644 --- a/exporters/zipkin/include/opentelemetry/exporters/zipkin/recordable.h +++ b/exporters/zipkin/include/opentelemetry/exporters/zipkin/recordable.h @@ -57,9 +57,13 @@ class Recordable final : public sdk::trace::Recordable void SetStartTime(opentelemetry::core::SystemTimestamp start_time) noexcept override; - virtual void SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept override; + void SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept override; + + void SetResource( const opentelemetry::sdk::resource::Resource& resource) noexcept override; + void SetDuration(std::chrono::nanoseconds duration) noexcept override; + private: ZipkinSpan span_; diff --git a/exporters/zipkin/src/recordable.cc b/exporters/zipkin/src/recordable.cc index 14d9c1fafc..b4f6502d8b 100644 --- a/exporters/zipkin/src/recordable.cc +++ b/exporters/zipkin/src/recordable.cc @@ -204,6 +204,12 @@ void Recordable::SetName(nostd::string_view name) noexcept span_["name"] = name.data(); } +void SetResource( const opentelemetry::sdk::resource::Resource& resource) noexcept +{ + +} + + void Recordable::SetStartTime(opentelemetry::core::SystemTimestamp start_time) noexcept { span_["timestamp"] = diff --git a/sdk/include/opentelemetry/sdk/trace/recordable.h b/sdk/include/opentelemetry/sdk/trace/recordable.h index ef5678d921..db4191198a 100644 --- a/sdk/include/opentelemetry/sdk/trace/recordable.h +++ b/sdk/include/opentelemetry/sdk/trace/recordable.h @@ -6,6 +6,7 @@ #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/common/empty_attributes.h" #include "opentelemetry/trace/canonical_code.h" +#include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/trace/span.h" #include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_id.h" @@ -114,6 +115,13 @@ class Recordable */ virtual void SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept = 0; + + /** + * Set Resource of the span + * @param Resource the resource to set + */ + virtual void SetResource( const opentelemetry::sdk::resource::Resource& resource) noexcept = 0; + /** * Set the start time of the span. * @param start_time the start time to set diff --git a/sdk/include/opentelemetry/sdk/trace/span_data.h b/sdk/include/opentelemetry/sdk/trace/span_data.h index 6eca905583..bb43ddd242 100644 --- a/sdk/include/opentelemetry/sdk/trace/span_data.h +++ b/sdk/include/opentelemetry/sdk/trace/span_data.h @@ -144,6 +144,13 @@ class SpanData final : public Recordable */ opentelemetry::nostd::string_view GetDescription() const noexcept { return status_desc_; } + /** + * Get the attributes associated with the resource + * @returns the attributes associated with the resource configured for TracerProvider + */ + + const opentelemetry::sdk::resource::ResourceAttributes& GetResource() const noexcept { return resourceAttributes_;} + /** * Get the start time for this span * @return the start time for this span @@ -225,6 +232,12 @@ class SpanData final : public Recordable span_kind_ = span_kind; } + void SetResource( const opentelemetry::sdk::resource::Resource& resource) noexcept override + { + resourceAttributes_ = resource.GetAttributes(); + } + + void SetStartTime(opentelemetry::core::SystemTimestamp start_time) noexcept override { start_time_ = start_time; @@ -244,6 +257,7 @@ class SpanData final : public Recordable std::vector events_; std::vector links_; opentelemetry::trace::SpanKind span_kind_{opentelemetry::trace::SpanKind::kInternal}; + opentelemetry::sdk::resource::ResourceAttributes resourceAttributes_; }; } // namespace trace } // namespace sdk diff --git a/sdk/include/opentelemetry/sdk/trace/tracer.h b/sdk/include/opentelemetry/sdk/trace/tracer.h index f764c48478..c9b3feb718 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer.h @@ -35,6 +35,9 @@ class Tracer final : public trace_api::Tracer, public std::enable_shared_from_th /** Returns the currently active span processor. */ SpanProcessor &GetActiveProcessor() noexcept { return context_->GetActiveProcessor(); } + /** Returns the currently configured resource **/ + const opentelemetry::sdk::resource::Resource &GetResource() { return context_->GetResource();} + // Note: Test only Sampler &GetSampler() { return context_->GetSampler(); } diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 388d0ab923..625ec6582f 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -117,7 +117,7 @@ Span::Span(std::shared_ptr &&tracer, recordable_->SetSpanKind(options.kind); recordable_->SetStartTime(NowOr(options.start_system_time)); start_steady_time = NowOr(options.start_steady_time); - // recordable_->SetResource(tracer_->GetResoource()); TODO + recordable_->SetResource(tracer_->GetResource()); // recordable_->SetResource(tracer_->GetInstrumentationLibrary()); TODO tracer_->GetActiveProcessor().OnStart(*recordable_, parent_span_context); } From 44e8f0571b22c6e2995765ce581ac5324ef50d11 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 27 Apr 2021 05:41:00 +0530 Subject: [PATCH 02/14] more changes --- exporters/memory/BUILD | 3 +- exporters/otlp/BUILD | 1 + exporters/otlp/CMakeLists.txt | 2 +- .../opentelemetry/exporters/otlp/recordable.h | 6 +- exporters/otlp/src/otlp_exporter.cc | 8 ++ exporters/otlp/src/recordable.cc | 114 ++++++++++++++++++ exporters/zipkin/CMakeLists.txt | 2 +- .../exporters/zipkin/recordable.h | 3 + exporters/zipkin/src/recordable.cc | 8 +- exporters/zipkin/src/zipkin_exporter.cc | 5 + .../zipkin/test/zipkin_recordable_test.cc | 9 ++ .../ext/zpages/threadsafe_span_data.h | 6 + sdk/test/trace/span_data_test.cc | 10 ++ 13 files changed, 171 insertions(+), 6 deletions(-) diff --git a/exporters/memory/BUILD b/exporters/memory/BUILD index a3ab2d1532..b98b0fc818 100644 --- a/exporters/memory/BUILD +++ b/exporters/memory/BUILD @@ -9,6 +9,7 @@ cc_library( deps = [ "//api", "//sdk/src/trace", + "//sdk/resource" ], ) @@ -28,7 +29,7 @@ cc_library( strip_include_prefix = "include", deps = [ ":in_memory_span_data", - "//sdk/src/trace", + "//sdk/src/trace" ], ) diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index 1124adf341..ecb24a4bf2 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -29,6 +29,7 @@ cc_library( strip_include_prefix = "include", deps = [ "//sdk/src/trace", + "//sdk/resource" "@com_github_opentelemetry_proto//:trace_proto_cc", ], ) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 0529436ac6..09d8034aca 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -5,7 +5,7 @@ set_target_properties(opentelemetry_exporter_otprotocol PROPERTIES EXPORT_NAME otlp_exporter) target_link_libraries(opentelemetry_exporter_otprotocol - PUBLIC opentelemetry_trace opentelemetry_proto) + PUBLIC opentelemetry_trace opentelemetry_resources opentelemetry_proto) install( TARGETS opentelemetry_exporter_otprotocol diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h b/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h index 0b0f3f3ca5..6327a0b240 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h @@ -1,7 +1,7 @@ #pragma once #include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" - +#include "opentelemetry/proto/resource/v1/resource.pb.h" #include "opentelemetry/proto/trace/v1/trace.pb.h" #include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" @@ -19,6 +19,9 @@ class Recordable final : public sdk::trace::Recordable public: const proto::trace::v1::Span &span() const noexcept { return span_; } + /** Dynamically converts the resource of this span into a proto. */ + proto::resource::v1::Resource resource() const noexcept; + void SetIdentity(const opentelemetry::trace::SpanContext &span_context, opentelemetry::trace::SpanId parent_span_id) noexcept override; @@ -46,6 +49,7 @@ class Recordable final : public sdk::trace::Recordable private: proto::trace::v1::Span span_; + opentelemetry::sdk::resource::Resource &resource_{opentelemetry::sdk::resource::Resource::GetEmpty()}; }; } // namespace otlp } // namespace exporter diff --git a/exporters/otlp/src/otlp_exporter.cc b/exporters/otlp/src/otlp_exporter.cc index 20433c2393..dc1a950d30 100644 --- a/exporters/otlp/src/otlp_exporter.cc +++ b/exporters/otlp/src/otlp_exporter.cc @@ -23,9 +23,17 @@ void PopulateRequest(const nostd::span> { auto resource_span = request->add_resource_spans(); auto instrumentation_lib = resource_span->add_instrumentation_library_spans(); + bool has_resource = false; + for (auto &recordable : spans) { + // We assume all the spans are for the same resource. + if (!has_resource) + { + *resource_span->mutable_resource() = rec->resource(); + has_resource = true; + } auto rec = std::unique_ptr(static_cast(recordable.release())); *instrumentation_lib->add_spans() = std::move(rec->span()); } diff --git a/exporters/otlp/src/recordable.cc b/exporters/otlp/src/recordable.cc index a6fd9a8902..134998b5e0 100644 --- a/exporters/otlp/src/recordable.cc +++ b/exporters/otlp/src/recordable.cc @@ -123,6 +123,120 @@ void PopulateAttribute(opentelemetry::proto::common::v1::KeyValue *attribute, } } + +/** Maps from C++ attribute into OTLP proto attribute. */ +void PopulateAttribute(opentelemetry::proto::common::v1::KeyValue *attribute, + nostd::string_view key, + const sdk::common::OwnedAttributeValue &value) +{ + // Assert size of variant to ensure that this method gets updated if the variant + // definition changes + static_assert( + nostd::variant_size::value == kOwnedAttributeValueSize, + "AttributeValue contains unknown type"); + + attribute->set_key(key.data(), key.size()); + + if (nostd::holds_alternative(value)) + { + attribute->mutable_value()->set_bool_value(nostd::get(value)); + } + else if (nostd::holds_alternative(value)) + { + attribute->mutable_value()->set_int_value(nostd::get(value)); + } + else if (nostd::holds_alternative(value)) + { + attribute->mutable_value()->set_int_value(nostd::get(value)); + } + else if (nostd::holds_alternative(value)) + { + attribute->mutable_value()->set_int_value(nostd::get(value)); + } + else if (nostd::holds_alternative(value)) + { + attribute->mutable_value()->set_int_value(nostd::get(value)); + } + else if (nostd::holds_alternative(value)) + { + attribute->mutable_value()->set_double_value(nostd::get(value)); + } + else if (nostd::holds_alternative(value)) + { + attribute->mutable_value()->set_string_value(nostd::get(value)); + } + else if (nostd::holds_alternative(value)) + { + attribute->mutable_value()->set_int_value(nostd::get(value)); + } + else if (nostd::holds_alternative>(value)) + { + for (const auto &val : nostd::get>(value)) + { + attribute->mutable_value()->mutable_array_value()->add_values()->set_bool_value(val); + } + } + else if (nostd::holds_alternative>(value)) + { + for (const auto &val : nostd::get>(value)) + { + attribute->mutable_value()->mutable_array_value()->add_values()->set_int_value(val); + } + } + else if (nostd::holds_alternative>(value)) + { + for (const auto &val : nostd::get>(value)) + { + attribute->mutable_value()->mutable_array_value()->add_values()->set_int_value(val); + } + } + else if (nostd::holds_alternative>(value)) + { + for (const auto &val : nostd::get>(value)) + { + attribute->mutable_value()->mutable_array_value()->add_values()->set_int_value(val); + } + } + else if (nostd::holds_alternative>(value)) + { + for (const auto &val : nostd::get>(value)) + { + attribute->mutable_value()->mutable_array_value()->add_values()->set_int_value(val); + } + } + else if (nostd::holds_alternative>(value)) + { + for (const auto &val : nostd::get>(value)) + { + attribute->mutable_value()->mutable_array_value()->add_values()->set_double_value(val); + } + } + else if (nostd::holds_alternative>(value)) + { + for (const auto &val : nostd::get>(value)) + { + attribute->mutable_value()->mutable_array_value()->add_values()->set_string_value(val); + } + } +} + +proto::resource::v1::Resource Recordable::resource() const noexcept +{ + proto::resource::v1::Resource proto; + for (const auto &kv : resource_.GetAttributes()) + { + PopulateAttribute(proto.add_attributes(), kv.first, kv.second); + } + return proto; +} + +void Recordable::SetResource( + const opentelemetry::sdk::resource::Resource &resource) noexcept +{ + resource_ = resource; +}; + + void Recordable::SetAttribute(nostd::string_view key, const opentelemetry::common::AttributeValue &value) noexcept { diff --git a/exporters/zipkin/CMakeLists.txt b/exporters/zipkin/CMakeLists.txt index 5d4fe8ddbd..0d5d978045 100644 --- a/exporters/zipkin/CMakeLists.txt +++ b/exporters/zipkin/CMakeLists.txt @@ -38,7 +38,7 @@ if(BUILD_TESTING) target_link_libraries( zipkin_recordable_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} - opentelemetry_exporter_zipkin_trace http_client_curl) + opentelemetry_exporter_zipkin_trace opentelemetry_resources http_client_curl) gtest_add_tests( TARGET zipkin_recordable_test diff --git a/exporters/zipkin/include/opentelemetry/exporters/zipkin/recordable.h b/exporters/zipkin/include/opentelemetry/exporters/zipkin/recordable.h index 801d529839..bd2257a8bd 100644 --- a/exporters/zipkin/include/opentelemetry/exporters/zipkin/recordable.h +++ b/exporters/zipkin/include/opentelemetry/exporters/zipkin/recordable.h @@ -38,6 +38,8 @@ class Recordable final : public sdk::trace::Recordable public: const ZipkinSpan &span() const noexcept { return span_; } + const std::string & GetServiceName() const noexcept { return service_name_; } + void SetIdentity(const opentelemetry::trace::SpanContext &span_context, opentelemetry::trace::SpanId parent_span_id) noexcept override; @@ -67,6 +69,7 @@ class Recordable final : public sdk::trace::Recordable private: ZipkinSpan span_; + std::string service_name_; }; } // namespace zipkin } // namespace exporter diff --git a/exporters/zipkin/src/recordable.cc b/exporters/zipkin/src/recordable.cc index b4f6502d8b..09fec67735 100644 --- a/exporters/zipkin/src/recordable.cc +++ b/exporters/zipkin/src/recordable.cc @@ -204,9 +204,13 @@ void Recordable::SetName(nostd::string_view name) noexcept span_["name"] = name.data(); } -void SetResource( const opentelemetry::sdk::resource::Resource& resource) noexcept +void Recordable::SetResource( const opentelemetry::sdk::resource::Resource& resource) noexcept { - + // only service.name attribute is supported by specs as of now. + auto attributes= resource.GetAttributes(); + if (attributes.find("service.name") != attributes.end()) { + service_name_ = nostd::get(attributes["service.name"]); + } } diff --git a/exporters/zipkin/src/zipkin_exporter.cc b/exporters/zipkin/src/zipkin_exporter.cc index 87bddb57bd..ed8de881db 100644 --- a/exporters/zipkin/src/zipkin_exporter.cc +++ b/exporters/zipkin/src/zipkin_exporter.cc @@ -62,6 +62,11 @@ sdk::common::ExportResult ZipkinExporter::Export( auto json_span = rec->span(); // add localEndPoint json_span["localEndpoint"] = local_end_point_; + // check service.name + auto service_name = rec->GetServiceName(); + if (service_name.size()){ + json_span["localEndpoint"]["serviceName"] = service_name; + } json_spans.push_back(json_span); } } diff --git a/exporters/zipkin/test/zipkin_recordable_test.cc b/exporters/zipkin/test/zipkin_recordable_test.cc index 0e8a132c1d..411483c3f5 100644 --- a/exporters/zipkin/test/zipkin_recordable_test.cc +++ b/exporters/zipkin/test/zipkin_recordable_test.cc @@ -205,6 +205,15 @@ TEST(ZipkinSpanRecordable, SetArrayAtrribute) EXPECT_EQ(rec.span(), j_span); } +TEST(ZipkinSpanRecordable, SetResource) +{ + opentelemetry::exporter::zipkin::Recordable rec; + std::string service_name = "test"; + auto resource = opentelemetry::sdk::resource::Resource::Create({{"service.name", service_name}}); + rec.SetResource(resource); + EXPECT_EQ(rec.GetServiceName(), service_name); +} + /** * AttributeValue can contain different int types, such as int, int64_t, * unsigned int, and uint64_t. To avoid writing test cases for each, we can diff --git a/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h b/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h index 0d3b0488a1..0e2da32160 100644 --- a/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h +++ b/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h @@ -160,6 +160,12 @@ class ThreadsafeSpanData final : public opentelemetry::sdk::trace::Recordable span_kind_ = span_kind; } + void SetResource( const opentelemetry::sdk::resource::Resource& /*resource*/) noexcept override + { + //Not Implemented + } + + void SetStartTime(opentelemetry::core::SystemTimestamp start_time) noexcept override { std::lock_guard lock(mutex_); diff --git a/sdk/test/trace/span_data_test.cc b/sdk/test/trace/span_data_test.cc index 0a528987df..b6d146e139 100644 --- a/sdk/test/trace/span_data_test.cc +++ b/sdk/test/trace/span_data_test.cc @@ -91,6 +91,16 @@ TEST(SpanData, EventAttributes) } } +TEST(SpanData, Resources) +{ + SpanData data; + auto resource = opentelemetry::sdk::resource::Resource::Create({}); + auto input_attr = resource.GetAttributes(); + data.SetResource(resource); + auto output_attr = data.GetResource(); + EXPECT_EQ(input_attr, output_attr); +} + TEST(SpanData, Links) { SpanData data; From d7d7f5a690d43232b0d44f8a45ec2bc273bf2799 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 27 Apr 2021 05:45:28 +0530 Subject: [PATCH 03/14] format --- exporters/memory/BUILD | 4 ++-- exporters/memory/CMakeLists.txt | 3 ++- exporters/otlp/BUILD | 2 +- exporters/otlp/CMakeLists.txt | 5 +++-- .../opentelemetry/exporters/otlp/recordable.h | 5 +++-- exporters/otlp/src/otlp_exporter.cc | 5 ++--- exporters/otlp/src/recordable.cc | 11 ++--------- exporters/zipkin/CMakeLists.txt | 3 ++- .../opentelemetry/exporters/zipkin/recordable.h | 6 ++---- exporters/zipkin/src/recordable.cc | 14 +++++++------- exporters/zipkin/src/zipkin_exporter.cc | 3 ++- .../ext/zpages/threadsafe_span_data.h | 5 ++--- sdk/include/opentelemetry/sdk/trace/recordable.h | 5 ++--- sdk/include/opentelemetry/sdk/trace/span_data.h | 10 ++++++---- sdk/include/opentelemetry/sdk/trace/tracer.h | 2 +- sdk/test/trace/span_data_test.cc | 2 +- 16 files changed, 40 insertions(+), 45 deletions(-) diff --git a/exporters/memory/BUILD b/exporters/memory/BUILD index b98b0fc818..9229cf611e 100644 --- a/exporters/memory/BUILD +++ b/exporters/memory/BUILD @@ -8,8 +8,8 @@ cc_library( strip_include_prefix = "include", deps = [ "//api", + "//sdk/resource", "//sdk/src/trace", - "//sdk/resource" ], ) @@ -29,7 +29,7 @@ cc_library( strip_include_prefix = "include", deps = [ ":in_memory_span_data", - "//sdk/src/trace" + "//sdk/src/trace", ], ) diff --git a/exporters/memory/CMakeLists.txt b/exporters/memory/CMakeLists.txt index 913c9cc3bc..20d963a9df 100644 --- a/exporters/memory/CMakeLists.txt +++ b/exporters/memory/CMakeLists.txt @@ -34,7 +34,8 @@ if(BUILD_TESTING) target_link_libraries( in_memory_span_exporter_test ${GTEST_BOTH_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} opentelemetry_exporter_in_memory opentelemetry_resources) + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_exporter_in_memory + opentelemetry_resources) gtest_add_tests( TARGET in_memory_span_data_test diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index ecb24a4bf2..8b407ee487 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -28,8 +28,8 @@ cc_library( ], strip_include_prefix = "include", deps = [ + "//sdk/resource", "//sdk/src/trace", - "//sdk/resource" "@com_github_opentelemetry_proto//:trace_proto_cc", ], ) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 09d8034aca..526a824da6 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -4,8 +4,9 @@ add_library(opentelemetry_exporter_otprotocol src/recordable.cc set_target_properties(opentelemetry_exporter_otprotocol PROPERTIES EXPORT_NAME otlp_exporter) -target_link_libraries(opentelemetry_exporter_otprotocol - PUBLIC opentelemetry_trace opentelemetry_resources opentelemetry_proto) +target_link_libraries( + opentelemetry_exporter_otprotocol + PUBLIC opentelemetry_trace opentelemetry_resources opentelemetry_proto) install( TARGETS opentelemetry_exporter_otprotocol diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h b/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h index 6327a0b240..bd13a01111 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h @@ -41,7 +41,7 @@ class Recordable final : public sdk::trace::Recordable void SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept override; - void SetResource( const opentelemetry::sdk::resource::Resource& resource) noexcept override; + void SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept override; void SetStartTime(opentelemetry::core::SystemTimestamp start_time) noexcept override; @@ -49,7 +49,8 @@ class Recordable final : public sdk::trace::Recordable private: proto::trace::v1::Span span_; - opentelemetry::sdk::resource::Resource &resource_{opentelemetry::sdk::resource::Resource::GetEmpty()}; + opentelemetry::sdk::resource::Resource &resource_{ + opentelemetry::sdk::resource::Resource::GetEmpty()}; }; } // namespace otlp } // namespace exporter diff --git a/exporters/otlp/src/otlp_exporter.cc b/exporters/otlp/src/otlp_exporter.cc index dc1a950d30..303c9e70d1 100644 --- a/exporters/otlp/src/otlp_exporter.cc +++ b/exporters/otlp/src/otlp_exporter.cc @@ -23,8 +23,7 @@ void PopulateRequest(const nostd::span> { auto resource_span = request->add_resource_spans(); auto instrumentation_lib = resource_span->add_instrumentation_library_spans(); - bool has_resource = false; - + bool has_resource = false; for (auto &recordable : spans) { @@ -32,7 +31,7 @@ void PopulateRequest(const nostd::span> if (!has_resource) { *resource_span->mutable_resource() = rec->resource(); - has_resource = true; + has_resource = true; } auto rec = std::unique_ptr(static_cast(recordable.release())); *instrumentation_lib->add_spans() = std::move(rec->span()); diff --git a/exporters/otlp/src/recordable.cc b/exporters/otlp/src/recordable.cc index 134998b5e0..677bd5ce93 100644 --- a/exporters/otlp/src/recordable.cc +++ b/exporters/otlp/src/recordable.cc @@ -123,7 +123,6 @@ void PopulateAttribute(opentelemetry::proto::common::v1::KeyValue *attribute, } } - /** Maps from C++ attribute into OTLP proto attribute. */ void PopulateAttribute(opentelemetry::proto::common::v1::KeyValue *attribute, nostd::string_view key, @@ -230,13 +229,11 @@ proto::resource::v1::Resource Recordable::resource() const noexcept return proto; } -void Recordable::SetResource( - const opentelemetry::sdk::resource::Resource &resource) noexcept +void Recordable::SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept { resource_ = resource; }; - void Recordable::SetAttribute(nostd::string_view key, const opentelemetry::common::AttributeValue &value) noexcept { @@ -327,11 +324,7 @@ void Recordable::SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept span_.set_kind(proto_span_kind); } - void SetResource( const opentelemetry::sdk::resource::Resource& resource) noexcept - { - - } - +void SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept {} void Recordable::SetStartTime(opentelemetry::core::SystemTimestamp start_time) noexcept { diff --git a/exporters/zipkin/CMakeLists.txt b/exporters/zipkin/CMakeLists.txt index 0d5d978045..50c3103533 100644 --- a/exporters/zipkin/CMakeLists.txt +++ b/exporters/zipkin/CMakeLists.txt @@ -38,7 +38,8 @@ if(BUILD_TESTING) target_link_libraries( zipkin_recordable_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} - opentelemetry_exporter_zipkin_trace opentelemetry_resources http_client_curl) + opentelemetry_exporter_zipkin_trace opentelemetry_resources + http_client_curl) gtest_add_tests( TARGET zipkin_recordable_test diff --git a/exporters/zipkin/include/opentelemetry/exporters/zipkin/recordable.h b/exporters/zipkin/include/opentelemetry/exporters/zipkin/recordable.h index bd2257a8bd..c5ee8752bf 100644 --- a/exporters/zipkin/include/opentelemetry/exporters/zipkin/recordable.h +++ b/exporters/zipkin/include/opentelemetry/exporters/zipkin/recordable.h @@ -38,7 +38,7 @@ class Recordable final : public sdk::trace::Recordable public: const ZipkinSpan &span() const noexcept { return span_; } - const std::string & GetServiceName() const noexcept { return service_name_; } + const std::string &GetServiceName() const noexcept { return service_name_; } void SetIdentity(const opentelemetry::trace::SpanContext &span_context, opentelemetry::trace::SpanId parent_span_id) noexcept override; @@ -61,11 +61,9 @@ class Recordable final : public sdk::trace::Recordable void SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept override; - void SetResource( const opentelemetry::sdk::resource::Resource& resource) noexcept override; - + void SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept override; void SetDuration(std::chrono::nanoseconds duration) noexcept override; - private: ZipkinSpan span_; diff --git a/exporters/zipkin/src/recordable.cc b/exporters/zipkin/src/recordable.cc index 09fec67735..38799eab53 100644 --- a/exporters/zipkin/src/recordable.cc +++ b/exporters/zipkin/src/recordable.cc @@ -204,16 +204,16 @@ void Recordable::SetName(nostd::string_view name) noexcept span_["name"] = name.data(); } -void Recordable::SetResource( const opentelemetry::sdk::resource::Resource& resource) noexcept +void Recordable::SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept { - // only service.name attribute is supported by specs as of now. - auto attributes= resource.GetAttributes(); - if (attributes.find("service.name") != attributes.end()) { - service_name_ = nostd::get(attributes["service.name"]); - } + // only service.name attribute is supported by specs as of now. + auto attributes = resource.GetAttributes(); + if (attributes.find("service.name") != attributes.end()) + { + service_name_ = nostd::get(attributes["service.name"]); + } } - void Recordable::SetStartTime(opentelemetry::core::SystemTimestamp start_time) noexcept { span_["timestamp"] = diff --git a/exporters/zipkin/src/zipkin_exporter.cc b/exporters/zipkin/src/zipkin_exporter.cc index ed8de881db..acef753ef7 100644 --- a/exporters/zipkin/src/zipkin_exporter.cc +++ b/exporters/zipkin/src/zipkin_exporter.cc @@ -64,7 +64,8 @@ sdk::common::ExportResult ZipkinExporter::Export( json_span["localEndpoint"] = local_end_point_; // check service.name auto service_name = rec->GetServiceName(); - if (service_name.size()){ + if (service_name.size()) + { json_span["localEndpoint"]["serviceName"] = service_name; } json_spans.push_back(json_span); diff --git a/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h b/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h index 0e2da32160..d3736e9add 100644 --- a/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h +++ b/ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h @@ -160,12 +160,11 @@ class ThreadsafeSpanData final : public opentelemetry::sdk::trace::Recordable span_kind_ = span_kind; } - void SetResource( const opentelemetry::sdk::resource::Resource& /*resource*/) noexcept override + void SetResource(const opentelemetry::sdk::resource::Resource & /*resource*/) noexcept override { - //Not Implemented + // Not Implemented } - void SetStartTime(opentelemetry::core::SystemTimestamp start_time) noexcept override { std::lock_guard lock(mutex_); diff --git a/sdk/include/opentelemetry/sdk/trace/recordable.h b/sdk/include/opentelemetry/sdk/trace/recordable.h index db4191198a..db67d38b8c 100644 --- a/sdk/include/opentelemetry/sdk/trace/recordable.h +++ b/sdk/include/opentelemetry/sdk/trace/recordable.h @@ -5,8 +5,8 @@ #include "opentelemetry/core/timestamp.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/common/empty_attributes.h" -#include "opentelemetry/trace/canonical_code.h" #include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/trace/canonical_code.h" #include "opentelemetry/trace/span.h" #include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_id.h" @@ -115,12 +115,11 @@ class Recordable */ virtual void SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept = 0; - /** * Set Resource of the span * @param Resource the resource to set */ - virtual void SetResource( const opentelemetry::sdk::resource::Resource& resource) noexcept = 0; + virtual void SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept = 0; /** * Set the start time of the span. diff --git a/sdk/include/opentelemetry/sdk/trace/span_data.h b/sdk/include/opentelemetry/sdk/trace/span_data.h index bb43ddd242..5e231c12d4 100644 --- a/sdk/include/opentelemetry/sdk/trace/span_data.h +++ b/sdk/include/opentelemetry/sdk/trace/span_data.h @@ -148,8 +148,11 @@ class SpanData final : public Recordable * Get the attributes associated with the resource * @returns the attributes associated with the resource configured for TracerProvider */ - - const opentelemetry::sdk::resource::ResourceAttributes& GetResource() const noexcept { return resourceAttributes_;} + + const opentelemetry::sdk::resource::ResourceAttributes &GetResource() const noexcept + { + return resourceAttributes_; + } /** * Get the start time for this span @@ -232,12 +235,11 @@ class SpanData final : public Recordable span_kind_ = span_kind; } - void SetResource( const opentelemetry::sdk::resource::Resource& resource) noexcept override + void SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept override { resourceAttributes_ = resource.GetAttributes(); } - void SetStartTime(opentelemetry::core::SystemTimestamp start_time) noexcept override { start_time_ = start_time; diff --git a/sdk/include/opentelemetry/sdk/trace/tracer.h b/sdk/include/opentelemetry/sdk/trace/tracer.h index c9b3feb718..e4491436a9 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer.h @@ -36,7 +36,7 @@ class Tracer final : public trace_api::Tracer, public std::enable_shared_from_th SpanProcessor &GetActiveProcessor() noexcept { return context_->GetActiveProcessor(); } /** Returns the currently configured resource **/ - const opentelemetry::sdk::resource::Resource &GetResource() { return context_->GetResource();} + const opentelemetry::sdk::resource::Resource &GetResource() { return context_->GetResource(); } // Note: Test only Sampler &GetSampler() { return context_->GetSampler(); } diff --git a/sdk/test/trace/span_data_test.cc b/sdk/test/trace/span_data_test.cc index b6d146e139..bdcb8e95ad 100644 --- a/sdk/test/trace/span_data_test.cc +++ b/sdk/test/trace/span_data_test.cc @@ -94,7 +94,7 @@ TEST(SpanData, EventAttributes) TEST(SpanData, Resources) { SpanData data; - auto resource = opentelemetry::sdk::resource::Resource::Create({}); + auto resource = opentelemetry::sdk::resource::Resource::Create({}); auto input_attr = resource.GetAttributes(); data.SetResource(resource); auto output_attr = data.GetResource(); From c2307ba7bd0a3c5c4d7c758cd67aa4b9e80d5e22 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 27 Apr 2021 05:49:54 +0530 Subject: [PATCH 04/14] fix bazel --- exporters/memory/BUILD | 2 +- exporters/otlp/BUILD | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/exporters/memory/BUILD b/exporters/memory/BUILD index 9229cf611e..c839044316 100644 --- a/exporters/memory/BUILD +++ b/exporters/memory/BUILD @@ -8,7 +8,7 @@ cc_library( strip_include_prefix = "include", deps = [ "//api", - "//sdk/resource", + "//sdk/src/resource", "//sdk/src/trace", ], ) diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index 8b407ee487..8eae69449c 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -28,7 +28,7 @@ cc_library( ], strip_include_prefix = "include", deps = [ - "//sdk/resource", + "//sdk/src/resource", "//sdk/src/trace", "@com_github_opentelemetry_proto//:trace_proto_cc", ], From 42dfa0e7e83fa5b2c6139492c95ff67dbdacd85b Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 28 Apr 2021 05:51:10 +0530 Subject: [PATCH 05/14] attribute constant --- exporters/otlp/src/recordable.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exporters/otlp/src/recordable.cc b/exporters/otlp/src/recordable.cc index db645ea6f4..097434c2be 100644 --- a/exporters/otlp/src/recordable.cc +++ b/exporters/otlp/src/recordable.cc @@ -9,7 +9,8 @@ namespace otlp // // See `attribute_value.h` for details. // -const int kAttributeValueSize = 15; +const int kAttributeValueSize = 15; +const int kOwnedAttributeValueSize = 15; void Recordable::SetIdentity(const opentelemetry::trace::SpanContext &span_context, opentelemetry::trace::SpanId parent_span_id) noexcept From dd694cd8c3c6c9e18c427a7f2cfeed0af8df779f Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 28 Apr 2021 14:56:53 +0000 Subject: [PATCH 06/14] fix otlp --- .../otlp/include/opentelemetry/exporters/otlp/recordable.h | 1 - exporters/otlp/src/otlp_exporter.cc | 2 +- exporters/otlp/src/recordable.cc | 4 ---- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h b/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h index f3b6b1ae91..3faeb34203 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h @@ -41,7 +41,6 @@ class Recordable final : public sdk::trace::Recordable void SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept override; - void SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept override; void SetStartTime(opentelemetry::common::SystemTimestamp start_time) noexcept override; diff --git a/exporters/otlp/src/otlp_exporter.cc b/exporters/otlp/src/otlp_exporter.cc index 303c9e70d1..b1c732c90d 100644 --- a/exporters/otlp/src/otlp_exporter.cc +++ b/exporters/otlp/src/otlp_exporter.cc @@ -27,13 +27,13 @@ void PopulateRequest(const nostd::span> for (auto &recordable : spans) { + auto rec = std::unique_ptr(static_cast(recordable.release())); // We assume all the spans are for the same resource. if (!has_resource) { *resource_span->mutable_resource() = rec->resource(); has_resource = true; } - auto rec = std::unique_ptr(static_cast(recordable.release())); *instrumentation_lib->add_spans() = std::move(rec->span()); } } diff --git a/exporters/otlp/src/recordable.cc b/exporters/otlp/src/recordable.cc index 097434c2be..ec24a7ab4c 100644 --- a/exporters/otlp/src/recordable.cc +++ b/exporters/otlp/src/recordable.cc @@ -165,10 +165,6 @@ void PopulateAttribute(opentelemetry::proto::common::v1::KeyValue *attribute, { attribute->mutable_value()->set_string_value(nostd::get(value)); } - else if (nostd::holds_alternative(value)) - { - attribute->mutable_value()->set_int_value(nostd::get(value)); - } else if (nostd::holds_alternative>(value)) { for (const auto &val : nostd::get>(value)) From 56dbd3cce7b7ea44ee765cc8ff3586d1d845475f Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 28 Apr 2021 15:45:37 +0000 Subject: [PATCH 07/14] fix reference --- .../include/opentelemetry/exporters/otlp/recordable.h | 3 +-- exporters/otlp/src/recordable.cc | 9 ++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h b/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h index 3faeb34203..0117a75640 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h @@ -49,8 +49,7 @@ class Recordable final : public sdk::trace::Recordable private: proto::trace::v1::Span span_; - opentelemetry::sdk::resource::Resource &resource_{ - opentelemetry::sdk::resource::Resource::GetEmpty()}; + const opentelemetry::sdk::resource::Resource *resource_; }; } // namespace otlp } // namespace exporter diff --git a/exporters/otlp/src/recordable.cc b/exporters/otlp/src/recordable.cc index ec24a7ab4c..9b266d9b41 100644 --- a/exporters/otlp/src/recordable.cc +++ b/exporters/otlp/src/recordable.cc @@ -219,16 +219,19 @@ void PopulateAttribute(opentelemetry::proto::common::v1::KeyValue *attribute, proto::resource::v1::Resource Recordable::resource() const noexcept { proto::resource::v1::Resource proto; - for (const auto &kv : resource_.GetAttributes()) + if (resource_) { - PopulateAttribute(proto.add_attributes(), kv.first, kv.second); + for (const auto &kv : resource_->GetAttributes()) + { + PopulateAttribute(proto.add_attributes(), kv.first, kv.second); + } } return proto; } void Recordable::SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept { - resource_ = resource; + resource_ = &resource; }; void Recordable::SetAttribute(nostd::string_view key, From bfd1a32824f05176d3a597ecb74967ad2c26f347 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 28 Apr 2021 04:18:39 +0530 Subject: [PATCH 08/14] add todo - for resource otlp --- exporters/otlp/src/otlp_exporter.cc | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/exporters/otlp/src/otlp_exporter.cc b/exporters/otlp/src/otlp_exporter.cc index b1c732c90d..74e1a71bd4 100644 --- a/exporters/otlp/src/otlp_exporter.cc +++ b/exporters/otlp/src/otlp_exporter.cc @@ -28,12 +28,7 @@ void PopulateRequest(const nostd::span> for (auto &recordable : spans) { auto rec = std::unique_ptr(static_cast(recordable.release())); - // We assume all the spans are for the same resource. - if (!has_resource) - { - *resource_span->mutable_resource() = rec->resource(); - has_resource = true; - } + // TODO - Handle Resource *instrumentation_lib->add_spans() = std::move(rec->span()); } } From 8477133ccb1a85b428b52b32128f3774889462aa Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 28 Apr 2021 04:47:50 +0530 Subject: [PATCH 09/14] fix span_data --- sdk/include/opentelemetry/sdk/trace/span_data.h | 9 +++------ sdk/test/trace/span_data_test.cc | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/span_data.h b/sdk/include/opentelemetry/sdk/trace/span_data.h index 12381b0779..f846b99378 100644 --- a/sdk/include/opentelemetry/sdk/trace/span_data.h +++ b/sdk/include/opentelemetry/sdk/trace/span_data.h @@ -149,10 +149,7 @@ class SpanData final : public Recordable * @returns the attributes associated with the resource configured for TracerProvider */ - const opentelemetry::sdk::resource::ResourceAttributes &GetResource() const noexcept - { - return resourceAttributes_; - } + const opentelemetry::sdk::resource::Resource &GetResource() const noexcept { return *resource_; } /** * Get the start time for this span @@ -237,7 +234,7 @@ class SpanData final : public Recordable void SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept override { - resourceAttributes_ = resource.GetAttributes(); + resource_ = &resource; } void SetStartTime(opentelemetry::common::SystemTimestamp start_time) noexcept override @@ -259,7 +256,7 @@ class SpanData final : public Recordable std::vector events_; std::vector links_; opentelemetry::trace::SpanKind span_kind_{opentelemetry::trace::SpanKind::kInternal}; - opentelemetry::sdk::resource::ResourceAttributes resourceAttributes_; + const opentelemetry::sdk::resource::Resource *resource_; }; } // namespace trace } // namespace sdk diff --git a/sdk/test/trace/span_data_test.cc b/sdk/test/trace/span_data_test.cc index d0e876c49f..2ae870b7ea 100644 --- a/sdk/test/trace/span_data_test.cc +++ b/sdk/test/trace/span_data_test.cc @@ -97,7 +97,7 @@ TEST(SpanData, Resources) auto resource = opentelemetry::sdk::resource::Resource::Create({}); auto input_attr = resource.GetAttributes(); data.SetResource(resource); - auto output_attr = data.GetResource(); + auto output_attr = data.GetResource().GetAttributes(); EXPECT_EQ(input_attr, output_attr); } From 420113ea8772e5cbfa695ef14685e9fe6cbdc304 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 28 Apr 2021 05:17:18 +0530 Subject: [PATCH 10/14] fix format --- sdk/include/opentelemetry/sdk/trace/recordable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/trace/recordable.h b/sdk/include/opentelemetry/sdk/trace/recordable.h index ee23e45e05..64492b665b 100644 --- a/sdk/include/opentelemetry/sdk/trace/recordable.h +++ b/sdk/include/opentelemetry/sdk/trace/recordable.h @@ -5,8 +5,8 @@ #include "opentelemetry/common/timestamp.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/common/empty_attributes.h" -#include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h" +#include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/trace/canonical_code.h" #include "opentelemetry/trace/span.h" #include "opentelemetry/trace/span_context.h" From 8875ce37965fe0df1582ccd05a8fc9bc1ec9017d Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 29 Apr 2021 09:51:08 +0530 Subject: [PATCH 11/14] Fix merge conflict --- .../sdk/trace/multi_recordable.h | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/multi_recordable.h b/sdk/include/opentelemetry/sdk/trace/multi_recordable.h index 925685a14f..be04566627 100644 --- a/sdk/include/opentelemetry/sdk/trace/multi_recordable.h +++ b/sdk/include/opentelemetry/sdk/trace/multi_recordable.h @@ -63,8 +63,8 @@ class MultiRecordable : public Recordable } } - virtual void SetAttribute(nostd::string_view key, - const opentelemetry::common::AttributeValue &value) noexcept override + void SetAttribute(nostd::string_view key, + const opentelemetry::common::AttributeValue &value) noexcept override { for (auto &recordable : recordables_) { @@ -72,9 +72,9 @@ class MultiRecordable : public Recordable } } - virtual void AddEvent(nostd::string_view name, - opentelemetry::common::SystemTimestamp timestamp, - const opentelemetry::common::KeyValueIterable &attributes) noexcept override + void AddEvent(nostd::string_view name, + opentelemetry::common::SystemTimestamp timestamp, + const opentelemetry::common::KeyValueIterable &attributes) noexcept override { for (auto &recordable : recordables_) @@ -83,8 +83,8 @@ class MultiRecordable : public Recordable } } - virtual void AddLink(const opentelemetry::trace::SpanContext &span_context, - const opentelemetry::common::KeyValueIterable &attributes) noexcept override + void AddLink(const opentelemetry::trace::SpanContext &span_context, + const opentelemetry::common::KeyValueIterable &attributes) noexcept override { for (auto &recordable : recordables_) { @@ -92,8 +92,8 @@ class MultiRecordable : public Recordable } } - virtual void SetStatus(opentelemetry::trace::StatusCode code, - nostd::string_view description) noexcept override + void SetStatus(opentelemetry::trace::StatusCode code, + nostd::string_view description) noexcept override { for (auto &recordable : recordables_) { @@ -101,7 +101,7 @@ class MultiRecordable : public Recordable } } - virtual void SetName(nostd::string_view name) noexcept override + void SetName(nostd::string_view name) noexcept override { for (auto &recordable : recordables_) { @@ -109,7 +109,7 @@ class MultiRecordable : public Recordable } } - virtual void SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept override + void SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept override { for (auto &recordable : recordables_) { @@ -117,7 +117,15 @@ class MultiRecordable : public Recordable } } - virtual void SetStartTime(opentelemetry::common::SystemTimestamp start_time) noexcept override + void SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept override + { + for (auto &recordable : recordables_) + { + recordable.second->SetResource(resource); + } + } + + void SetStartTime(opentelemetry::common::SystemTimestamp start_time) noexcept override { for (auto &recordable : recordables_) { @@ -125,7 +133,7 @@ class MultiRecordable : public Recordable } } - virtual void SetDuration(std::chrono::nanoseconds duration) noexcept override + void SetDuration(std::chrono::nanoseconds duration) noexcept override { for (auto &recordable : recordables_) { From 47f98fe97dc505f498f5638463a4067659a75648 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 29 Apr 2021 10:20:34 +0530 Subject: [PATCH 12/14] review comment --- .../otlp/include/opentelemetry/exporters/otlp/recordable.h | 2 +- exporters/otlp/src/recordable.cc | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h b/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h index 489d584176..53fc5f4d55 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h @@ -20,7 +20,7 @@ class Recordable final : public sdk::trace::Recordable const proto::trace::v1::Span &span() const noexcept { return span_; } /** Dynamically converts the resource of this span into a proto. */ - proto::resource::v1::Resource resource() const noexcept; + proto::resource::v1::Resource ProtoResource() const noexcept; void SetIdentity(const opentelemetry::trace::SpanContext &span_context, opentelemetry::trace::SpanId parent_span_id) noexcept override; diff --git a/exporters/otlp/src/recordable.cc b/exporters/otlp/src/recordable.cc index e16ce79e44..a973bad994 100644 --- a/exporters/otlp/src/recordable.cc +++ b/exporters/otlp/src/recordable.cc @@ -216,7 +216,7 @@ void PopulateAttribute(opentelemetry::proto::common::v1::KeyValue *attribute, } } -proto::resource::v1::Resource Recordable::resource() const noexcept +proto::resource::v1::Resource Recordable::ProtoResource() const noexcept { proto::resource::v1::Resource proto; if (resource_) @@ -324,8 +324,6 @@ void Recordable::SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept span_.set_kind(proto_span_kind); } -void SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept {} - void Recordable::SetStartTime(opentelemetry::common::SystemTimestamp start_time) noexcept { span_.set_start_time_unix_nano(start_time.time_since_epoch().count()); From e8ff60f65b040d44eb0d12f17387e79c45f7cbcb Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 29 Apr 2021 10:24:28 +0530 Subject: [PATCH 13/14] review comment --- sdk/src/trace/span.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 9632eb96b0..395b3c3dd7 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -103,7 +103,6 @@ Span::Span(std::shared_ptr &&tracer, recordable_->SetStartTime(NowOr(options.start_system_time)); start_steady_time = NowOr(options.start_steady_time); recordable_->SetResource(tracer_->GetResource()); - // recordable_->SetResource(tracer_->GetInstrumentationLibrary()); TODO tracer_->GetProcessor().OnStart(*recordable_, parent_span_context); } From a5d4f13a33167d5f8d7cf07cf4ef3bd6fafaaaa4 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Sat, 1 May 2021 00:47:20 +0530 Subject: [PATCH 14/14] Trigger Build