From 6844271a364fa9739aba71e7991c6a04716faef7 Mon Sep 17 00:00:00 2001 From: Lalit Bhasin Date: Thu, 1 Oct 2020 21:50:02 +0530 Subject: [PATCH 01/23] links for span - first draft --- api/include/opentelemetry/plugin/tracer.h | 5 +- api/include/opentelemetry/trace/link.h | 49 ++++++++++++++++++++ api/include/opentelemetry/trace/noop.h | 3 +- api/include/opentelemetry/trace/tracer.h | 16 ++++--- api/test/trace/BUILD | 11 +++++ api/test/trace/CMakeLists.txt | 3 +- examples/plugin/plugin/tracer.cc | 8 ++-- examples/plugin/plugin/tracer.h | 3 +- sdk/include/opentelemetry/sdk/trace/tracer.h | 3 +- sdk/src/trace/span.cc | 6 +++ sdk/src/trace/span.h | 1 + sdk/src/trace/tracer.cc | 5 +- sdk/test/trace/tracer_test.cc | 32 ++++++++++++- 13 files changed, 126 insertions(+), 19 deletions(-) create mode 100644 api/include/opentelemetry/trace/link.h diff --git a/api/include/opentelemetry/plugin/tracer.h b/api/include/opentelemetry/plugin/tracer.h index aed1d26d28..a131b04bc2 100644 --- a/api/include/opentelemetry/plugin/tracer.h +++ b/api/include/opentelemetry/plugin/tracer.h @@ -67,9 +67,10 @@ class Tracer final : public trace::Tracer, public std::enable_shared_from_this StartSpan( nostd::string_view name, const trace::KeyValueIterable &attributes, - const trace::StartSpanOptions &options = {}) noexcept override + const trace::StartSpanOptions &options = {}, + const nostd::span &links = {}) noexcept override { - auto span = tracer_handle_->tracer().StartSpan(name, attributes, options); + auto span = tracer_handle_->tracer().StartSpan(name, attributes, options, links); if (span == nullptr) { return nostd::shared_ptr(nullptr); diff --git a/api/include/opentelemetry/trace/link.h b/api/include/opentelemetry/trace/link.h new file mode 100644 index 0000000000..50993a58dc --- /dev/null +++ b/api/include/opentelemetry/trace/link.h @@ -0,0 +1,49 @@ +#pragma once + +#include +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/trace/key_value_iterable_view.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/version.h" +OPENTELEMETRY_BEGIN_NAMESPACE +namespace trace +{ +class Link final +{ +public: + Link() = default; + + Link(const opentelemetry::trace::SpanContext &span_context, + const trace_api::KeyValueIterable &attributes) + : span_context_(span_context), attributes_{attributes} + {} + + template ::value> * = nullptr> + Link(const SpanContext &span_context, const T &attributes) + : Link(span_context, KeyValueIterableView(attributes)) + {} + + Link(const SpanContext &span_context, + std::initializer_list> attributes) + : Link(span_context, + nostd::span>{ + attributes.begin(), attributes.end()}) + {} + + Link(const opentelemetry::trace::SpanContext &span_context) + : Link(span_context, + nostd::span>{}) + {} + + // returns the Span Context associated with this Link + const SpanContext &GetSpanContext() const { return span_context_; } + + // returns the attributes associated with link + const KeyValueIterable &GetAttributes() const { return attributes_; } + +private: + const trace_api::SpanContext &span_context_; + const trace_api::KeyValueIterable &attributes_; +}; +} // namespace trace +OPENTELEMETRY_END_NAMESPACE diff --git a/api/include/opentelemetry/trace/noop.h b/api/include/opentelemetry/trace/noop.h index 533225e851..77314cb86c 100644 --- a/api/include/opentelemetry/trace/noop.h +++ b/api/include/opentelemetry/trace/noop.h @@ -64,7 +64,8 @@ class NoopTracer final : public Tracer, public std::enable_shared_from_this StartSpan(nostd::string_view /*name*/, const KeyValueIterable & /*attributes*/, - const StartSpanOptions & /*options*/) noexcept override + const StartSpanOptions & /*options*/, + const nostd::span & /*links*/) noexcept override { // Don't allocate a no-op span for every StartSpan call, but use a static // singleton for this case. diff --git a/api/include/opentelemetry/trace/tracer.h b/api/include/opentelemetry/trace/tracer.h index 34a34be99e..e70b2df56e 100644 --- a/api/include/opentelemetry/trace/tracer.h +++ b/api/include/opentelemetry/trace/tracer.h @@ -4,6 +4,7 @@ #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/trace/default_span.h" +#include "opentelemetry/trace/link.h" #include "opentelemetry/trace/scope.h" #include "opentelemetry/trace/span.h" #include "opentelemetry/version.h" @@ -33,31 +34,34 @@ class Tracer */ virtual nostd::shared_ptr StartSpan(nostd::string_view name, const KeyValueIterable &attributes, - const StartSpanOptions &options = {}) noexcept = 0; + const StartSpanOptions &options = {}, + const nostd::span &links = {}) noexcept = 0; nostd::shared_ptr StartSpan(nostd::string_view name, const StartSpanOptions &options = {}) noexcept { - return this->StartSpan(name, {}, options); + return this->StartSpan(name, {}, options, {}); } template ::value> * = nullptr> nostd::shared_ptr StartSpan(nostd::string_view name, const T &attributes, - const StartSpanOptions &options = {}) noexcept + const StartSpanOptions &options = {}, + const nostd::span &links = {}) noexcept { - return this->StartSpan(name, KeyValueIterableView(attributes), options); + return this->StartSpan(name, KeyValueIterableView(attributes), options, links); } nostd::shared_ptr StartSpan( nostd::string_view name, std::initializer_list> attributes, - const StartSpanOptions &options = {}) noexcept + const StartSpanOptions &options = {}, + const nostd::span &links = {}) noexcept { return this->StartSpan(name, nostd::span>{ attributes.begin(), attributes.end()}, - options); + options, links); } /** diff --git a/api/test/trace/BUILD b/api/test/trace/BUILD index 0a313a14fe..a7bcd00ba1 100644 --- a/api/test/trace/BUILD +++ b/api/test/trace/BUILD @@ -126,3 +126,14 @@ cc_test( "@com_google_googletest//:gtest_main", ], ) + +cc_test( + name = "link_test", + srcs = [ + "link_test.cc", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/api/test/trace/CMakeLists.txt b/api/test/trace/CMakeLists.txt index 3d3dc88891..f828aee8be 100644 --- a/api/test/trace/CMakeLists.txt +++ b/api/test/trace/CMakeLists.txt @@ -8,7 +8,8 @@ foreach( span_context_test scope_test noop_test - tracer_test) + tracer_test + link_test) add_executable(api_${testname} "${testname}.cc") target_link_libraries(api_${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) diff --git a/examples/plugin/plugin/tracer.cc b/examples/plugin/plugin/tracer.cc index e8f324c9e7..9e8b6517f5 100644 --- a/examples/plugin/plugin/tracer.cc +++ b/examples/plugin/plugin/tracer.cc @@ -19,7 +19,8 @@ class Span final : public trace::Span Span(std::shared_ptr &&tracer, nostd::string_view name, const opentelemetry::trace::KeyValueIterable & /*attributes*/, - const trace::StartSpanOptions & /*options*/) noexcept + const trace::StartSpanOptions & /*options*/, + const nostd::span & /*links*/) noexcept : tracer_{std::move(tracer)}, name_{name} { std::cout << "StartSpan: " << name << "\n"; @@ -66,8 +67,9 @@ Tracer::Tracer(nostd::string_view /*output*/) {} nostd::shared_ptr Tracer::StartSpan( nostd::string_view name, const opentelemetry::trace::KeyValueIterable &attributes, - const trace::StartSpanOptions &options) noexcept + const trace::StartSpanOptions &options, + const nostd::span &links) noexcept { return nostd::shared_ptr{ - new (std::nothrow) Span{this->shared_from_this(), name, attributes, options}}; + new (std::nothrow) Span{this->shared_from_this(), name, attributes, options, links}}; } diff --git a/examples/plugin/plugin/tracer.h b/examples/plugin/plugin/tracer.h index c50b5f458b..8147dbb7c3 100644 --- a/examples/plugin/plugin/tracer.h +++ b/examples/plugin/plugin/tracer.h @@ -14,7 +14,8 @@ class Tracer final : public opentelemetry::trace::Tracer, opentelemetry::nostd::shared_ptr StartSpan( opentelemetry::nostd::string_view name, const opentelemetry::trace::KeyValueIterable & /*attributes*/, - const opentelemetry::trace::StartSpanOptions & /*options */) noexcept override; + const opentelemetry::trace::StartSpanOptions & /*options */, + const opentelemetry::nostd::span & /*links*/) noexcept override; void ForceFlushWithMicroseconds(uint64_t /*timeout*/) noexcept override {} diff --git a/sdk/include/opentelemetry/sdk/trace/tracer.h b/sdk/include/opentelemetry/sdk/trace/tracer.h index bb28842c75..322994a4e4 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer.h @@ -47,7 +47,8 @@ class Tracer final : public trace_api::Tracer, public std::enable_shared_from_th nostd::shared_ptr StartSpan( nostd::string_view name, const trace_api::KeyValueIterable &attributes, - const trace_api::StartSpanOptions &options = {}) noexcept override; + const trace_api::StartSpanOptions &options = {}, + const nostd::span &links = {}) noexcept override; void ForceFlushWithMicroseconds(uint64_t timeout) noexcept override; diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 76418af1dd..59ee65d287 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -62,6 +62,7 @@ Span::Span(std::shared_ptr &&tracer, nostd::string_view name, const trace_api::KeyValueIterable &attributes, const trace_api::StartSpanOptions &options, + const nostd::span &links, const trace_api::SpanContext &parent_span_context) noexcept : tracer_{std::move(tracer)}, processor_{processor}, @@ -98,6 +99,11 @@ Span::Span(std::shared_ptr &&tracer, return true; }); + for (auto const &link : links) + { + recordable_->AddLink(link.GetSpanContext(), link.GetAttributes()); + } + recordable_->SetStartTime(NowOr(options.start_system_time)); start_steady_time = NowOr(options.start_steady_time); processor_->OnStart(*recordable_); diff --git a/sdk/src/trace/span.h b/sdk/src/trace/span.h index 56baf8838f..23893ab01a 100644 --- a/sdk/src/trace/span.h +++ b/sdk/src/trace/span.h @@ -20,6 +20,7 @@ class Span final : public trace_api::Span nostd::string_view name, const trace_api::KeyValueIterable &attributes, const trace_api::StartSpanOptions &options, + const nostd::span &links, const trace_api::SpanContext &parent_span_context) noexcept; ~Span() override; diff --git a/sdk/src/trace/tracer.cc b/sdk/src/trace/tracer.cc index 70a7b42109..68baace19c 100644 --- a/sdk/src/trace/tracer.cc +++ b/sdk/src/trace/tracer.cc @@ -47,7 +47,8 @@ trace_api::SpanContext GetCurrentSpanContext() nostd::shared_ptr Tracer::StartSpan( nostd::string_view name, const trace_api::KeyValueIterable &attributes, - const trace_api::StartSpanOptions &options) noexcept + const trace_api::StartSpanOptions &options, + const nostd::span &links) noexcept { // TODO: replace nullptr with parent context in span context auto sampling_result = @@ -65,7 +66,7 @@ nostd::shared_ptr Tracer::StartSpan( { auto span = nostd::shared_ptr{ new (std::nothrow) Span{this->shared_from_this(), processor_.load(), name, attributes, - options, GetCurrentSpanContext()}}; + options, links, GetCurrentSpanContext()}}; // if the attributes is not nullptr, add attributes to the span. if (sampling_result.attributes) diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index 98a18ea688..6dceb135e5 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -5,6 +5,7 @@ #include "opentelemetry/sdk/trace/samplers/parent_or_else.h" #include "opentelemetry/sdk/trace/simple_processor.h" #include "opentelemetry/sdk/trace/span_data.h" +#include "opentelemetry/trace/link.h" #include @@ -15,6 +16,8 @@ namespace nostd = opentelemetry::nostd; namespace common = opentelemetry::common; using opentelemetry::exporter::memory::InMemorySpanData; using opentelemetry::exporter::memory::InMemorySpanExporter; +using opentelemetry::trace::KeyValueIterableView; +using opentelemetry::trace::Link; using opentelemetry::trace::SpanContext; /** @@ -57,7 +60,7 @@ std::shared_ptr initTracer( return std::shared_ptr(new Tracer(processor, sampler)); } } // namespace - +#if 0 TEST(Tracer, ToInMemorySpanExporter) { std::unique_ptr exporter(new InMemorySpanExporter()); @@ -331,6 +334,31 @@ TEST(Tracer, SpanSetEvents) ASSERT_EQ(1, span_data_events[2].GetAttributes().size()); } +#endif +TEST(Tracer, SpanSetLinks) +{ + std::unique_ptr exporter(new InMemorySpanExporter()); + std::shared_ptr span_data = exporter->GetData(); + auto tracer = initTracer(std::move(exporter)); + + SpanContext sp(true, true); + using Map = std::map; + Map m1 = {{"attr1", 123}, {"attr2", 456}}; + KeyValueIterableView iterable{m1}; + Link link(sp, iterable); + std::vector links = {link}; + auto span = tracer->StartSpan("span 1", {}, {}, links); + span->End(); + auto spans = span_data->GetSpans(); + ASSERT_EQ(1, spans.size()); + auto &span_data_links = spans.at(0)->GetLinks(); + ASSERT_EQ(1, span_data_links.size()); + auto link1 = span_data_links.at(0); + std::cout << nostd::get(link1.GetAttributes().at("attr1")); + ASSERT_EQ(nostd::get(link1.GetAttributes().at("attr1")), 123); + ASSERT_EQ(nostd::get(link1.GetAttributes().at("attr2")), 456); +} + TEST(Tracer, TestAlwaysOnSampler) { std::unique_ptr exporter(new InMemorySpanExporter()); @@ -441,4 +469,4 @@ TEST(Tracer, WithActiveSpan) spans = span_data->GetSpans(); ASSERT_EQ(1, spans.size()); EXPECT_EQ("span 1", spans.at(0)->GetName()); -} +} \ No newline at end of file From 91de78c3ac2aef178cb3580fd574f5e22f89542c Mon Sep 17 00:00:00 2001 From: Lalit Bhasin Date: Thu, 1 Oct 2020 21:54:17 +0530 Subject: [PATCH 02/23] remove comments --- sdk/test/trace/tracer_test.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index 6dceb135e5..16ad585168 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -60,7 +60,7 @@ std::shared_ptr initTracer( return std::shared_ptr(new Tracer(processor, sampler)); } } // namespace -#if 0 + TEST(Tracer, ToInMemorySpanExporter) { std::unique_ptr exporter(new InMemorySpanExporter()); @@ -334,7 +334,6 @@ TEST(Tracer, SpanSetEvents) ASSERT_EQ(1, span_data_events[2].GetAttributes().size()); } -#endif TEST(Tracer, SpanSetLinks) { std::unique_ptr exporter(new InMemorySpanExporter()); @@ -469,4 +468,4 @@ TEST(Tracer, WithActiveSpan) spans = span_data->GetSpans(); ASSERT_EQ(1, spans.size()); EXPECT_EQ("span 1", spans.at(0)->GetName()); -} \ No newline at end of file +} From be9d08c3be8baf1190b1096686db740550da2045 Mon Sep 17 00:00:00 2001 From: Lalit Bhasin Date: Thu, 1 Oct 2020 22:07:42 +0530 Subject: [PATCH 03/23] add missing file --- api/test/trace/link_test.cc | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 api/test/trace/link_test.cc diff --git a/api/test/trace/link_test.cc b/api/test/trace/link_test.cc new file mode 100644 index 0000000000..b44b9f411d --- /dev/null +++ b/api/test/trace/link_test.cc @@ -0,0 +1,59 @@ +#include "opentelemetry/trace/link.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/trace/key_value_iterable_view.h" +#include "opentelemetry/trace/span_context.h" + +#include +#include +#include + +using namespace opentelemetry; + +using opentelemetry::trace::KeyValueIterable; +using opentelemetry::trace::KeyValueIterableView; +using opentelemetry::trace::Link; +using opentelemetry::trace::SpanContext; + +using Map = std::map; +void validateKeyValueIterableView(const KeyValueIterable &attributes, Map &keys) +{ + attributes.ForEachKeyValue([&](nostd::string_view key, + opentelemetry::common::AttributeValue value) noexcept { + bool found = (keys.end() != keys.find(key)); + EXPECT_EQ(found, true); + return true; + }); +} + +void validateKeyValueInitializationList(const KeyValueIterable &attributes, + const std::vector &keys) +{ + int i = 0; + attributes.ForEachKeyValue([&](nostd::string_view key, + opentelemetry::common::AttributeValue value) noexcept { + std::cout << key; + return true; + }); +} +TEST(LinkTest, CreateLinkIterableView) +{ + + Map m1 = {{"abc", "123"}, {"xyz", "456"}}; + SpanContext s1(true, true); + KeyValueIterableView iterable{m1}; + + Link link(s1, iterable); + validateKeyValueIterableView(link.GetAttributes(), m1); + EXPECT_EQ(s1.IsSampled(), link.GetSpanContext().IsSampled()); +} + +TEST(LinkTest, CreateLinkInitlilizerList) +{ + + SpanContext s1(true, true); + Link link1(s1, {{"k1", "v1"}, {"k2", "v2"}}); + + std::map attributes = {{"attr1", 1}, {"attr2", 2}}; + Link link2(s1, attributes); +} From 4ba4a0c3d993ce99d396f010436e7273c223a1d2 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Mon, 5 Oct 2020 10:37:15 +0000 Subject: [PATCH 04/23] fix gcc48 compilation --- api/include/opentelemetry/trace/link.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/include/opentelemetry/trace/link.h b/api/include/opentelemetry/trace/link.h index 50993a58dc..c3141295e7 100644 --- a/api/include/opentelemetry/trace/link.h +++ b/api/include/opentelemetry/trace/link.h @@ -15,7 +15,7 @@ class Link final Link(const opentelemetry::trace::SpanContext &span_context, const trace_api::KeyValueIterable &attributes) - : span_context_(span_context), attributes_{attributes} + : span_context_(span_context), attributes_(attributes) {} template ::value> * = nullptr> From 27cb54994ecba4cd477703e48024d3b5ef6699a5 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 13 Oct 2020 20:43:34 +0530 Subject: [PATCH 05/23] test --- api/include/opentelemetry/plugin/tracer.h | 6 +- api/include/opentelemetry/trace/noop.h | 5 +- .../trace/span_context_kv_iterable.h | 35 +++++++ .../trace/span_context_kv_iterable_view.h | 99 +++++++++++++++++++ api/include/opentelemetry/trace/tracer.h | 83 ++++++++++++++-- api/test/trace/noop_test.cc | 12 +++ examples/plugin/plugin/tracer.cc | 10 +- examples/plugin/plugin/tracer.h | 4 +- sdk/include/opentelemetry/sdk/trace/tracer.h | 4 +- sdk/src/trace/span.cc | 42 +++++++- sdk/src/trace/span.h | 2 +- sdk/src/trace/tracer.cc | 6 +- sdk/test/trace/tracer_test.cc | 84 +++++++++++++--- 13 files changed, 344 insertions(+), 48 deletions(-) create mode 100644 api/include/opentelemetry/trace/span_context_kv_iterable.h create mode 100644 api/include/opentelemetry/trace/span_context_kv_iterable_view.h diff --git a/api/include/opentelemetry/plugin/tracer.h b/api/include/opentelemetry/plugin/tracer.h index a131b04bc2..a34ad036f6 100644 --- a/api/include/opentelemetry/plugin/tracer.h +++ b/api/include/opentelemetry/plugin/tracer.h @@ -67,10 +67,10 @@ class Tracer final : public trace::Tracer, public std::enable_shared_from_this StartSpan( nostd::string_view name, const trace::KeyValueIterable &attributes, - const trace::StartSpanOptions &options = {}, - const nostd::span &links = {}) noexcept override + const trace::SpanContextKeyValueIterable &links, + const trace::StartSpanOptions &options = {}) noexcept override { - auto span = tracer_handle_->tracer().StartSpan(name, attributes, options, links); + auto span = tracer_handle_->tracer().StartSpan(name, attributes, links, options); if (span == nullptr) { return nostd::shared_ptr(nullptr); diff --git a/api/include/opentelemetry/trace/noop.h b/api/include/opentelemetry/trace/noop.h index 77314cb86c..13f2859aba 100644 --- a/api/include/opentelemetry/trace/noop.h +++ b/api/include/opentelemetry/trace/noop.h @@ -9,6 +9,7 @@ #include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/trace/span.h" #include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_context_kv_iterable.h" #include "opentelemetry/trace/tracer.h" #include "opentelemetry/trace/tracer_provider.h" #include "opentelemetry/version.h" @@ -64,8 +65,8 @@ class NoopTracer final : public Tracer, public std::enable_shared_from_this StartSpan(nostd::string_view /*name*/, const KeyValueIterable & /*attributes*/, - const StartSpanOptions & /*options*/, - const nostd::span & /*links*/) noexcept override + const SpanContextKeyValueIterable & /*links*/, + const StartSpanOptions & /*options*/) noexcept override { // Don't allocate a no-op span for every StartSpan call, but use a static // singleton for this case. diff --git a/api/include/opentelemetry/trace/span_context_kv_iterable.h b/api/include/opentelemetry/trace/span_context_kv_iterable.h new file mode 100644 index 0000000000..d7970378dc --- /dev/null +++ b/api/include/opentelemetry/trace/span_context_kv_iterable.h @@ -0,0 +1,35 @@ +#pragma once + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/trace/key_value_iterable_view.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace trace +{ +/** + * Supports internal iteration over a collection of SpanContext/key-value pairs. + */ +class SpanContextKeyValueIterable +{ +public: + virtual ~SpanContextKeyValueIterable() = default; + + /** + * Iterate over SpanContext/key-value pairs + * @param callback a callback to invoke for each key-value for each SpanContext. + * If the callback returns false, the iteration is aborted. + * @return true if every SpanContext/key-value pair was iterated over + */ + virtual bool ForEachKeyValue( + nostd::function_ref< + bool(SpanContext, nostd::string_view, common::AttributeValue, bool /*is_last_kv */)> + callback) const noexcept = 0; + /** + * @return the number of key-value pairs + */ + virtual size_t size() const noexcept = 0; +}; +} // namespace trace +OPENTELEMETRY_END_NAMESPACE \ No newline at end of file diff --git a/api/include/opentelemetry/trace/span_context_kv_iterable_view.h b/api/include/opentelemetry/trace/span_context_kv_iterable_view.h new file mode 100644 index 0000000000..e27c7bd553 --- /dev/null +++ b/api/include/opentelemetry/trace/span_context_kv_iterable_view.h @@ -0,0 +1,99 @@ +#pragma once + +#include +#include +#include + +#include "opentelemetry/nostd/utility.h" +#include "opentelemetry/trace/key_value_iterable_view.h" +#include "opentelemetry/trace/span_context_kv_iterable.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace trace +{ +namespace detail +{ +template +inline void take_span_context_kv(SpanContext, opentelemetry::trace::KeyValueIterableView) +{} + +template ::value> * = nullptr> +inline void take_span_context_kv(SpanContext, T &) +{} + +inline void take_span_context_kv( + SpanContext, + std::initializer_list>) +{} + +template +auto is_span_context_kv_iterable_impl(T iterable) + -> decltype(take_span_context_kv(std::begin(iterable)->first, std::begin(iterable)->second), + nostd::size(iterable), + std::true_type{}); + +std::false_type is_span_context_kv_iterable_impl(...); + +template +struct is_span_context_kv_iterable +{ + static const bool value = + decltype(detail::is_span_context_kv_iterable_impl(std::declval()))::value; +}; +} // namespace detail + +template +class SpanContextKeyValueIterableView final : public SpanContextKeyValueIterable +{ + static_assert(detail::is_span_context_kv_iterable::value, + "Must be a context/key-value iterable"); + +public: + explicit SpanContextKeyValueIterableView(const T &links) noexcept : container_{&links} {} + + bool ForEachKeyValue( + nostd::function_ref + callback) const noexcept override + { + auto iter = std::begin(*container_); + auto last = std::end(*container_); + for (; iter != last; ++iter) + { + auto kv_iter = std::begin(iter->second); + auto kv_end = std::end(iter->second); + // attributes are optional, and so may be empty container + if (kv_iter == kv_end) + { + if (!callback(iter->first, "", static_cast(""), true)) + { + return false; + } + } + else + { + auto kv_last = std::prev(kv_end); + bool is_last_kv = false; + for (; kv_iter != kv_end; ++kv_iter) + { + if (kv_iter == kv_last) + { + is_last_kv = true; + } + if (!callback(iter->first, kv_iter->first, kv_iter->second, is_last_kv)) + { + return false; + } + } + } + } + return true; + } + + size_t size() const noexcept override { return nostd::size(*container_); } + +private: + const T *container_; +}; +} // namespace trace +OPENTELEMETRY_END_NAMESPACE \ No newline at end of file diff --git a/api/include/opentelemetry/trace/tracer.h b/api/include/opentelemetry/trace/tracer.h index e70b2df56e..0f98490134 100644 --- a/api/include/opentelemetry/trace/tracer.h +++ b/api/include/opentelemetry/trace/tracer.h @@ -7,6 +7,7 @@ #include "opentelemetry/trace/link.h" #include "opentelemetry/trace/scope.h" #include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context_kv_iterable_view.h" #include "opentelemetry/version.h" #include @@ -34,34 +35,98 @@ class Tracer */ virtual nostd::shared_ptr StartSpan(nostd::string_view name, const KeyValueIterable &attributes, - const StartSpanOptions &options = {}, - const nostd::span &links = {}) noexcept = 0; + const SpanContextKeyValueIterable &links, + const StartSpanOptions &options = {}) noexcept = 0; nostd::shared_ptr StartSpan(nostd::string_view name, const StartSpanOptions &options = {}) noexcept { - return this->StartSpan(name, {}, options, {}); + return this->StartSpan(name, {}, {}, options); } template ::value> * = nullptr> nostd::shared_ptr StartSpan(nostd::string_view name, const T &attributes, - const StartSpanOptions &options = {}, - const nostd::span &links = {}) noexcept + const StartSpanOptions &options = {}) noexcept + { + + /*SpanContextKeyValueIterableView>>>> links({}); */ + // return this->StartSpan(name, KeyValueIterableView(attributes), {}, options); + return this->StartSpan(name, attributes, {}, options); + } + + template ::value> * = nullptr, + nostd::enable_if_t::value> * = nullptr> + nostd::shared_ptr StartSpan(nostd::string_view name, + const T &attributes, + const U &links, + const StartSpanOptions &options = {}) noexcept + { + return this->StartSpan(name, KeyValueIterableView(attributes), + SpanContextKeyValueIterableView(links), options); + } + + nostd::shared_ptr StartSpan( + nostd::string_view name, + std::initializer_list> attributes, + const StartSpanOptions &options = {}) noexcept { - return this->StartSpan(name, KeyValueIterableView(attributes), options, links); + + return this->StartSpan(name, attributes, {}, options); + } + + template ::value> * = nullptr> + nostd::shared_ptr StartSpan( + nostd::string_view name, + const T &attributes, + std::initializer_list< + std::pair>>> + links, + const StartSpanOptions &options = {}) noexcept + { + return this->StartSpan( + name, attributes, + nostd::span>>>{ + links.begin(), links.end()}, + options); } + template ::value> * = nullptr> nostd::shared_ptr StartSpan( nostd::string_view name, std::initializer_list> attributes, - const StartSpanOptions &options = {}, - const nostd::span &links = {}) noexcept + const T &links, + const StartSpanOptions &options = {}) noexcept { return this->StartSpan(name, nostd::span>{ attributes.begin(), attributes.end()}, - options, links); + links, options); + } + + nostd::shared_ptr StartSpan( + nostd::string_view name, + std::initializer_list> attributes, + std::initializer_list< + std::pair>>> + links, + const StartSpanOptions &options = {}) noexcept + { + return this->StartSpan( + name, + nostd::span>{attributes.begin(), + attributes.end()}, + nostd::span>>>{ + links.begin(), links.end()}, + options); } /** diff --git a/api/test/trace/noop_test.cc b/api/test/trace/noop_test.cc index 4a069430ef..590250be39 100644 --- a/api/test/trace/noop_test.cc +++ b/api/test/trace/noop_test.cc @@ -43,3 +43,15 @@ TEST(NoopTest, UseNoopTracers) s1->GetContext(); } + +TEST(NoopTest, StartSpan) +{ + std::shared_ptr tracer{new NoopTracer{}}; + + std::map attrs = {{"a", "3"}}; + std::vector>> links = { + {SpanContext(), attrs}}; + auto s1 = tracer->StartSpan("abc", attrs, links); + + auto s2 = tracer->StartSpan("efg", {{"a", 3}}, {{SpanContext(), {{"b", 4}}}}); +} diff --git a/examples/plugin/plugin/tracer.cc b/examples/plugin/plugin/tracer.cc index 9e8b6517f5..5599721f15 100644 --- a/examples/plugin/plugin/tracer.cc +++ b/examples/plugin/plugin/tracer.cc @@ -19,8 +19,8 @@ class Span final : public trace::Span Span(std::shared_ptr &&tracer, nostd::string_view name, const opentelemetry::trace::KeyValueIterable & /*attributes*/, - const trace::StartSpanOptions & /*options*/, - const nostd::span & /*links*/) noexcept + const opentelemetry::trace::SpanContextKeyValueIterable & /*links*/, + const trace::StartSpanOptions & /*options*/) noexcept : tracer_{std::move(tracer)}, name_{name} { std::cout << "StartSpan: " << name << "\n"; @@ -67,9 +67,9 @@ Tracer::Tracer(nostd::string_view /*output*/) {} nostd::shared_ptr Tracer::StartSpan( nostd::string_view name, const opentelemetry::trace::KeyValueIterable &attributes, - const trace::StartSpanOptions &options, - const nostd::span &links) noexcept + const opentelemetry::trace::SpanContextKeyValueIterable &links, + const trace::StartSpanOptions &options) noexcept { return nostd::shared_ptr{ - new (std::nothrow) Span{this->shared_from_this(), name, attributes, options, links}}; + new (std::nothrow) Span{this->shared_from_this(), name, attributes, links, options}}; } diff --git a/examples/plugin/plugin/tracer.h b/examples/plugin/plugin/tracer.h index 8147dbb7c3..f4682da386 100644 --- a/examples/plugin/plugin/tracer.h +++ b/examples/plugin/plugin/tracer.h @@ -14,8 +14,8 @@ class Tracer final : public opentelemetry::trace::Tracer, opentelemetry::nostd::shared_ptr StartSpan( opentelemetry::nostd::string_view name, const opentelemetry::trace::KeyValueIterable & /*attributes*/, - const opentelemetry::trace::StartSpanOptions & /*options */, - const opentelemetry::nostd::span & /*links*/) noexcept override; + const opentelemetry::trace::SpanContextKeyValueIterable & /*links*/, + const opentelemetry::trace::StartSpanOptions & /*options */) noexcept override; void ForceFlushWithMicroseconds(uint64_t /*timeout*/) noexcept override {} diff --git a/sdk/include/opentelemetry/sdk/trace/tracer.h b/sdk/include/opentelemetry/sdk/trace/tracer.h index 322994a4e4..b7473912ba 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer.h @@ -47,8 +47,8 @@ class Tracer final : public trace_api::Tracer, public std::enable_shared_from_th nostd::shared_ptr StartSpan( nostd::string_view name, const trace_api::KeyValueIterable &attributes, - const trace_api::StartSpanOptions &options = {}, - const nostd::span &links = {}) noexcept override; + const trace_api::SpanContextKeyValueIterable &links, + const trace_api::StartSpanOptions &options = {}) noexcept override; void ForceFlushWithMicroseconds(uint64_t timeout) noexcept override; diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 59ee65d287..0e5a1525d5 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -5,6 +5,8 @@ #include "opentelemetry/trace/trace_flags.h" #include "opentelemetry/version.h" +#include + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -61,8 +63,8 @@ Span::Span(std::shared_ptr &&tracer, std::shared_ptr processor, nostd::string_view name, const trace_api::KeyValueIterable &attributes, + const trace_api::SpanContextKeyValueIterable &links, const trace_api::StartSpanOptions &options, - const nostd::span &links, const trace_api::SpanContext &parent_span_context) noexcept : tracer_{std::move(tracer)}, processor_{processor}, @@ -99,10 +101,40 @@ Span::Span(std::shared_ptr &&tracer, return true; }); - for (auto const &link : links) - { - recordable_->AddLink(link.GetSpanContext(), link.GetAttributes()); - } + links.ForEachKeyValue([&](trace_api::SpanContext span_context, nostd::string_view key, + opentelemetry::common::AttributeValue value, bool is_last_kv) noexcept { + static std::unordered_map + link_attributes = {}; + if (is_last_kv) + { + if (key.size()) + { + link_attributes.insert( + std::make_pair( + std::move(key), std::move(value))); + } + if (link_attributes.size()) + { + recordable_->AddLink( + span_context, + trace_api::KeyValueIterableView< + std::unordered_map>( + link_attributes)); + } + else + { + recordable_->AddLink(span_context); + } + link_attributes.clear(); + } + else + { + link_attributes.insert( + std::make_pair( + std::move(key), std::move(value))); + } + return true; + }); recordable_->SetStartTime(NowOr(options.start_system_time)); start_steady_time = NowOr(options.start_steady_time); diff --git a/sdk/src/trace/span.h b/sdk/src/trace/span.h index 23893ab01a..fbbc131df6 100644 --- a/sdk/src/trace/span.h +++ b/sdk/src/trace/span.h @@ -19,8 +19,8 @@ class Span final : public trace_api::Span std::shared_ptr processor, nostd::string_view name, const trace_api::KeyValueIterable &attributes, + const trace_api::SpanContextKeyValueIterable &links, const trace_api::StartSpanOptions &options, - const nostd::span &links, const trace_api::SpanContext &parent_span_context) noexcept; ~Span() override; diff --git a/sdk/src/trace/tracer.cc b/sdk/src/trace/tracer.cc index 68baace19c..3f155a6679 100644 --- a/sdk/src/trace/tracer.cc +++ b/sdk/src/trace/tracer.cc @@ -47,8 +47,8 @@ trace_api::SpanContext GetCurrentSpanContext() nostd::shared_ptr Tracer::StartSpan( nostd::string_view name, const trace_api::KeyValueIterable &attributes, - const trace_api::StartSpanOptions &options, - const nostd::span &links) noexcept + const trace_api::SpanContextKeyValueIterable &links, + const trace_api::StartSpanOptions &options) noexcept { // TODO: replace nullptr with parent context in span context auto sampling_result = @@ -66,7 +66,7 @@ nostd::shared_ptr Tracer::StartSpan( { auto span = nostd::shared_ptr{ new (std::nothrow) Span{this->shared_from_this(), processor_.load(), name, attributes, - options, links, GetCurrentSpanContext()}}; + links, options, GetCurrentSpanContext()}}; // if the attributes is not nullptr, add attributes to the span. if (sampling_result.attributes) diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index 16ad585168..3cf36ae685 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -340,22 +340,74 @@ TEST(Tracer, SpanSetLinks) std::shared_ptr span_data = exporter->GetData(); auto tracer = initTracer(std::move(exporter)); - SpanContext sp(true, true); - using Map = std::map; - Map m1 = {{"attr1", 123}, {"attr2", 456}}; - KeyValueIterableView iterable{m1}; - Link link(sp, iterable); - std::vector links = {link}; - auto span = tracer->StartSpan("span 1", {}, {}, links); - span->End(); - auto spans = span_data->GetSpans(); - ASSERT_EQ(1, spans.size()); - auto &span_data_links = spans.at(0)->GetLinks(); - ASSERT_EQ(1, span_data_links.size()); - auto link1 = span_data_links.at(0); - std::cout << nostd::get(link1.GetAttributes().at("attr1")); - ASSERT_EQ(nostd::get(link1.GetAttributes().at("attr1")), 123); - ASSERT_EQ(nostd::get(link1.GetAttributes().at("attr2")), 456); + { + + // Single span link passed through Initialization list + tracer->StartSpan("efg", {{"attr1", 1}}, {{SpanContext(), {{"attr2", 2}}}})->End(); + auto spans = span_data->GetSpans(); + ASSERT_EQ(1, spans.size()); + + auto &span_data_links = spans.at(0)->GetLinks(); + ASSERT_EQ(1, span_data_links.size()); + auto link = span_data_links.at(0); + ASSERT_EQ(nostd::get(link.GetAttributes().at("attr2")), 2); + } + { + + // Multiple span links passed through Initialization list + tracer + ->StartSpan("efg", {{"attr1", 1}}, + {{SpanContext(), {{"attr2", 2}}}, {SpanContext(), {{"attr3", 3}}}}) + ->End(); + auto spans = span_data->GetSpans(); + ASSERT_EQ(1, spans.size()); + + auto &span_data_links = spans.at(0)->GetLinks(); + ASSERT_EQ(2, span_data_links.size()); + auto link1 = span_data_links.at(0); + ASSERT_EQ(nostd::get(link1.GetAttributes().at("attr2")), 2); + auto link2 = span_data_links.at(1); + ASSERT_EQ(nostd::get(link2.GetAttributes().at("attr3")), 3); + } + + { + + // Multiple links, each with multiple attributes passed through Initialization list + tracer + ->StartSpan( + "efg", {{"attr1", 1}}, + {{SpanContext(), {{"attr2", 2}, {"attr3", 3}}}, {SpanContext(), {{"attr4", 4}}}}) + ->End(); + auto spans = span_data->GetSpans(); + ASSERT_EQ(1, spans.size()); + + auto &span_data_links = spans.at(0)->GetLinks(); + ASSERT_EQ(2, span_data_links.size()); + auto link1 = span_data_links.at(0); + ASSERT_EQ(nostd::get(link1.GetAttributes().at("attr2")), 2); + ASSERT_EQ(nostd::get(link1.GetAttributes().at("attr3")), 3); + auto link2 = span_data_links.at(1); + ASSERT_EQ(nostd::get(link2.GetAttributes().at("attr4")), 4); + } + + { + std::map attrs1 = {{"attr1", "1"}, {"attr2", "2"}}; + std::map attrs2 = {{"attr3", "3"}, {"attr4", "4"}}; + + std::vector>> links = { + {SpanContext(), attrs1}, {SpanContext(), attrs2}}; + tracer->StartSpan("efg", attrs1, links)->End(); + auto spans = span_data->GetSpans(); + + auto &span_data_links = spans.at(0)->GetLinks(); + ASSERT_EQ(2, span_data_links.size()); + auto link1 = span_data_links.at(0); + ASSERT_EQ(nostd::get(link1.GetAttributes().at("attr1")), "1"); + ASSERT_EQ(nostd::get(link1.GetAttributes().at("attr2")), "2"); + auto link2 = span_data_links.at(1); + ASSERT_EQ(nostd::get(link2.GetAttributes().at("attr3")), "3"); + ASSERT_EQ(nostd::get(link2.GetAttributes().at("attr4")), "4"); + } } TEST(Tracer, TestAlwaysOnSampler) From 9ec157e02bf8450a12d0ed8b9c9f8bc5049c8335 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 13 Oct 2020 20:45:08 +0530 Subject: [PATCH 06/23] remove link file --- api/include/opentelemetry/trace/link.h | 49 -------------------------- 1 file changed, 49 deletions(-) delete mode 100644 api/include/opentelemetry/trace/link.h diff --git a/api/include/opentelemetry/trace/link.h b/api/include/opentelemetry/trace/link.h deleted file mode 100644 index c3141295e7..0000000000 --- a/api/include/opentelemetry/trace/link.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include -#include "opentelemetry/nostd/span.h" -#include "opentelemetry/trace/key_value_iterable_view.h" -#include "opentelemetry/trace/span_context.h" -#include "opentelemetry/version.h" -OPENTELEMETRY_BEGIN_NAMESPACE -namespace trace -{ -class Link final -{ -public: - Link() = default; - - Link(const opentelemetry::trace::SpanContext &span_context, - const trace_api::KeyValueIterable &attributes) - : span_context_(span_context), attributes_(attributes) - {} - - template ::value> * = nullptr> - Link(const SpanContext &span_context, const T &attributes) - : Link(span_context, KeyValueIterableView(attributes)) - {} - - Link(const SpanContext &span_context, - std::initializer_list> attributes) - : Link(span_context, - nostd::span>{ - attributes.begin(), attributes.end()}) - {} - - Link(const opentelemetry::trace::SpanContext &span_context) - : Link(span_context, - nostd::span>{}) - {} - - // returns the Span Context associated with this Link - const SpanContext &GetSpanContext() const { return span_context_; } - - // returns the attributes associated with link - const KeyValueIterable &GetAttributes() const { return attributes_; } - -private: - const trace_api::SpanContext &span_context_; - const trace_api::KeyValueIterable &attributes_; -}; -} // namespace trace -OPENTELEMETRY_END_NAMESPACE From cee64d93c3767c0b5d5e1c8ca25cceaf7f70e898 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 13 Oct 2020 20:47:01 +0530 Subject: [PATCH 07/23] remove link file --- api/test/trace/link_test.cc | 59 ------------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 api/test/trace/link_test.cc diff --git a/api/test/trace/link_test.cc b/api/test/trace/link_test.cc deleted file mode 100644 index b44b9f411d..0000000000 --- a/api/test/trace/link_test.cc +++ /dev/null @@ -1,59 +0,0 @@ -#include "opentelemetry/trace/link.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/trace/key_value_iterable_view.h" -#include "opentelemetry/trace/span_context.h" - -#include -#include -#include - -using namespace opentelemetry; - -using opentelemetry::trace::KeyValueIterable; -using opentelemetry::trace::KeyValueIterableView; -using opentelemetry::trace::Link; -using opentelemetry::trace::SpanContext; - -using Map = std::map; -void validateKeyValueIterableView(const KeyValueIterable &attributes, Map &keys) -{ - attributes.ForEachKeyValue([&](nostd::string_view key, - opentelemetry::common::AttributeValue value) noexcept { - bool found = (keys.end() != keys.find(key)); - EXPECT_EQ(found, true); - return true; - }); -} - -void validateKeyValueInitializationList(const KeyValueIterable &attributes, - const std::vector &keys) -{ - int i = 0; - attributes.ForEachKeyValue([&](nostd::string_view key, - opentelemetry::common::AttributeValue value) noexcept { - std::cout << key; - return true; - }); -} -TEST(LinkTest, CreateLinkIterableView) -{ - - Map m1 = {{"abc", "123"}, {"xyz", "456"}}; - SpanContext s1(true, true); - KeyValueIterableView iterable{m1}; - - Link link(s1, iterable); - validateKeyValueIterableView(link.GetAttributes(), m1); - EXPECT_EQ(s1.IsSampled(), link.GetSpanContext().IsSampled()); -} - -TEST(LinkTest, CreateLinkInitlilizerList) -{ - - SpanContext s1(true, true); - Link link1(s1, {{"k1", "v1"}, {"k2", "v2"}}); - - std::map attributes = {{"attr1", 1}, {"attr2", 2}}; - Link link2(s1, attributes); -} From 9d078ac4d1c18fd2609fbe2f5dc1690e2e04cb43 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 13 Oct 2020 20:50:27 +0530 Subject: [PATCH 08/23] fix build --- api/test/trace/BUILD | 11 ----------- api/test/trace/CMakeLists.txt | 3 +-- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/api/test/trace/BUILD b/api/test/trace/BUILD index a7bcd00ba1..0a313a14fe 100644 --- a/api/test/trace/BUILD +++ b/api/test/trace/BUILD @@ -126,14 +126,3 @@ cc_test( "@com_google_googletest//:gtest_main", ], ) - -cc_test( - name = "link_test", - srcs = [ - "link_test.cc", - ], - deps = [ - "//api", - "@com_google_googletest//:gtest_main", - ], -) diff --git a/api/test/trace/CMakeLists.txt b/api/test/trace/CMakeLists.txt index f828aee8be..3d3dc88891 100644 --- a/api/test/trace/CMakeLists.txt +++ b/api/test/trace/CMakeLists.txt @@ -8,8 +8,7 @@ foreach( span_context_test scope_test noop_test - tracer_test - link_test) + tracer_test) add_executable(api_${testname} "${testname}.cc") target_link_libraries(api_${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) From e00f66900ccf4cff4835d7699c82be0ff3599b2e Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 15 Oct 2020 22:01:22 +0530 Subject: [PATCH 09/23] fix merge --- api/include/opentelemetry/trace/tracer.h | 1 - sdk/test/trace/tracer_test.cc | 2 -- 2 files changed, 3 deletions(-) diff --git a/api/include/opentelemetry/trace/tracer.h b/api/include/opentelemetry/trace/tracer.h index 0f98490134..b38b1f2dfd 100644 --- a/api/include/opentelemetry/trace/tracer.h +++ b/api/include/opentelemetry/trace/tracer.h @@ -4,7 +4,6 @@ #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/trace/default_span.h" -#include "opentelemetry/trace/link.h" #include "opentelemetry/trace/scope.h" #include "opentelemetry/trace/span.h" #include "opentelemetry/trace/span_context_kv_iterable_view.h" diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index ec82c032d8..5e11376741 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -5,7 +5,6 @@ #include "opentelemetry/sdk/trace/samplers/parent_or_else.h" #include "opentelemetry/sdk/trace/simple_processor.h" #include "opentelemetry/sdk/trace/span_data.h" -#include "opentelemetry/trace/link.h" #include @@ -17,7 +16,6 @@ namespace common = opentelemetry::common; using opentelemetry::exporter::memory::InMemorySpanData; using opentelemetry::exporter::memory::InMemorySpanExporter; using opentelemetry::trace::KeyValueIterableView; -using opentelemetry::trace::Link; using opentelemetry::trace::SpanContext; /** From e90d18b63dc24c381b6643d51b304b4f7a8a6ddf Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 15 Oct 2020 22:18:10 +0530 Subject: [PATCH 10/23] fix tests --- api/test/trace/noop_test.cc | 4 ++-- sdk/test/trace/tracer_test.cc | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/api/test/trace/noop_test.cc b/api/test/trace/noop_test.cc index 590250be39..e623e109f6 100644 --- a/api/test/trace/noop_test.cc +++ b/api/test/trace/noop_test.cc @@ -50,8 +50,8 @@ TEST(NoopTest, StartSpan) std::map attrs = {{"a", "3"}}; std::vector>> links = { - {SpanContext(), attrs}}; + {SpanContext(false, false), attrs}}; auto s1 = tracer->StartSpan("abc", attrs, links); - auto s2 = tracer->StartSpan("efg", {{"a", 3}}, {{SpanContext(), {{"b", 4}}}}); + auto s2 = tracer->StartSpan("efg", {{"a", 3}}, {{SpanContext(false, false), {{"b", 4}}}}); } diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index 5e11376741..30ced99119 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -341,7 +341,7 @@ TEST(Tracer, SpanSetLinks) { // Single span link passed through Initialization list - tracer->StartSpan("efg", {{"attr1", 1}}, {{SpanContext(), {{"attr2", 2}}}})->End(); + tracer->StartSpan("efg", {{"attr1", 1}}, {{SpanContext(false, false), {{"attr2", 2}}}})->End(); auto spans = span_data->GetSpans(); ASSERT_EQ(1, spans.size()); @@ -355,7 +355,8 @@ TEST(Tracer, SpanSetLinks) // Multiple span links passed through Initialization list tracer ->StartSpan("efg", {{"attr1", 1}}, - {{SpanContext(), {{"attr2", 2}}}, {SpanContext(), {{"attr3", 3}}}}) + {{SpanContext(false, false), {{"attr2", 2}}}, + {SpanContext(false, false), {{"attr3", 3}}}}) ->End(); auto spans = span_data->GetSpans(); ASSERT_EQ(1, spans.size()); @@ -372,9 +373,9 @@ TEST(Tracer, SpanSetLinks) // Multiple links, each with multiple attributes passed through Initialization list tracer - ->StartSpan( - "efg", {{"attr1", 1}}, - {{SpanContext(), {{"attr2", 2}, {"attr3", 3}}}, {SpanContext(), {{"attr4", 4}}}}) + ->StartSpan("efg", {{"attr1", 1}}, + {{SpanContext(false, false), {{"attr2", 2}, {"attr3", 3}}}, + {SpanContext(false, false), {{"attr4", 4}}}}) ->End(); auto spans = span_data->GetSpans(); ASSERT_EQ(1, spans.size()); @@ -393,7 +394,7 @@ TEST(Tracer, SpanSetLinks) std::map attrs2 = {{"attr3", "3"}, {"attr4", "4"}}; std::vector>> links = { - {SpanContext(), attrs1}, {SpanContext(), attrs2}}; + {SpanContext(false, false), attrs1}, {SpanContext(false, false), attrs2}}; tracer->StartSpan("efg", attrs1, links)->End(); auto spans = span_data->GetSpans(); From e5ce74a49196b95330cd1d90a0104ed7dc504a8c Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 15 Oct 2020 23:16:49 +0530 Subject: [PATCH 11/23] removed unnecessary file --- sdk/src/trace/tracer.cc.orig | 109 ---------------------------- sdk/src/trace/tracer_BACKUP_1799.cc | 109 ---------------------------- sdk/src/trace/tracer_BASE_1799.cc | 94 ------------------------ sdk/src/trace/tracer_REMOTE_1034.cc | 102 -------------------------- sdk/src/trace/tracer_REMOTE_1799.cc | 102 -------------------------- 5 files changed, 516 deletions(-) delete mode 100644 sdk/src/trace/tracer.cc.orig delete mode 100644 sdk/src/trace/tracer_BACKUP_1799.cc delete mode 100644 sdk/src/trace/tracer_BASE_1799.cc delete mode 100644 sdk/src/trace/tracer_REMOTE_1034.cc delete mode 100644 sdk/src/trace/tracer_REMOTE_1799.cc diff --git a/sdk/src/trace/tracer.cc.orig b/sdk/src/trace/tracer.cc.orig deleted file mode 100644 index 7386652698..0000000000 --- a/sdk/src/trace/tracer.cc.orig +++ /dev/null @@ -1,109 +0,0 @@ -#include "opentelemetry/sdk/trace/tracer.h" - -#include "opentelemetry/context/runtime_context.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/common/atomic_shared_ptr.h" -#include "opentelemetry/version.h" -#include "src/trace/span.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ -namespace trace -{ -Tracer::Tracer(std::shared_ptr processor, std::shared_ptr sampler) noexcept - : processor_{processor}, sampler_{sampler} -{} - -void Tracer::SetProcessor(std::shared_ptr processor) noexcept -{ - processor_.store(processor); -} - -std::shared_ptr Tracer::GetProcessor() const noexcept -{ - return processor_.load(); -} - -std::shared_ptr Tracer::GetSampler() const noexcept -{ - return sampler_; -} - -trace_api::SpanContext GetCurrentSpanContext(const trace_api::SpanContext &explicit_parent) -{ - // Use the explicit parent, if it's valid. - if (explicit_parent.IsValid()) - { - return explicit_parent; - } - - // Use the currently active span, if there's one. - auto curr_span_context = context::RuntimeContext::GetValue(SpanKey); - - if (nostd::holds_alternative>(curr_span_context)) - { - auto curr_span = nostd::get>(curr_span_context); - return curr_span->GetContext(); - } - - // Otherwise return an invalid SpanContext. - return trace_api::SpanContext::GetInvalid(); -} - -nostd::shared_ptr Tracer::StartSpan( - nostd::string_view name, - const trace_api::KeyValueIterable &attributes, - const trace_api::SpanContextKeyValueIterable &links, - const trace_api::StartSpanOptions &options) noexcept -{ - trace_api::SpanContext parent = GetCurrentSpanContext(options.parent); - - // TODO: replace nullptr with parent context in span context - auto sampling_result = - sampler_->ShouldSample(nullptr, parent.trace_id(), name, options.kind, attributes); - if (sampling_result.decision == Decision::DROP) - { - // Don't allocate a no-op span for every DROP decision, but use a static - // singleton for this case. - static nostd::shared_ptr noop_span( - new trace_api::NoopSpan{this->shared_from_this()}); - - return noop_span; - } - else - { -<<<<<<< HEAD - auto span = nostd::shared_ptr{ - new (std::nothrow) Span{this->shared_from_this(), processor_.load(), name, attributes, - links, options, GetCurrentSpanContext()}}; -======= - auto span = nostd::shared_ptr{new (std::nothrow) Span{ - this->shared_from_this(), processor_.load(), name, attributes, options, parent}}; ->>>>>>> master - - // if the attributes is not nullptr, add attributes to the span. - if (sampling_result.attributes) - { - for (auto &kv : *sampling_result.attributes) - { - span->SetAttribute(kv.first, kv.second); - } - } - - return span; - } -} - -void Tracer::ForceFlushWithMicroseconds(uint64_t timeout) noexcept -{ - (void)timeout; -} - -void Tracer::CloseWithMicroseconds(uint64_t timeout) noexcept -{ - (void)timeout; -} -} // namespace trace -} // namespace sdk -OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/tracer_BACKUP_1799.cc b/sdk/src/trace/tracer_BACKUP_1799.cc deleted file mode 100644 index 7386652698..0000000000 --- a/sdk/src/trace/tracer_BACKUP_1799.cc +++ /dev/null @@ -1,109 +0,0 @@ -#include "opentelemetry/sdk/trace/tracer.h" - -#include "opentelemetry/context/runtime_context.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/common/atomic_shared_ptr.h" -#include "opentelemetry/version.h" -#include "src/trace/span.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ -namespace trace -{ -Tracer::Tracer(std::shared_ptr processor, std::shared_ptr sampler) noexcept - : processor_{processor}, sampler_{sampler} -{} - -void Tracer::SetProcessor(std::shared_ptr processor) noexcept -{ - processor_.store(processor); -} - -std::shared_ptr Tracer::GetProcessor() const noexcept -{ - return processor_.load(); -} - -std::shared_ptr Tracer::GetSampler() const noexcept -{ - return sampler_; -} - -trace_api::SpanContext GetCurrentSpanContext(const trace_api::SpanContext &explicit_parent) -{ - // Use the explicit parent, if it's valid. - if (explicit_parent.IsValid()) - { - return explicit_parent; - } - - // Use the currently active span, if there's one. - auto curr_span_context = context::RuntimeContext::GetValue(SpanKey); - - if (nostd::holds_alternative>(curr_span_context)) - { - auto curr_span = nostd::get>(curr_span_context); - return curr_span->GetContext(); - } - - // Otherwise return an invalid SpanContext. - return trace_api::SpanContext::GetInvalid(); -} - -nostd::shared_ptr Tracer::StartSpan( - nostd::string_view name, - const trace_api::KeyValueIterable &attributes, - const trace_api::SpanContextKeyValueIterable &links, - const trace_api::StartSpanOptions &options) noexcept -{ - trace_api::SpanContext parent = GetCurrentSpanContext(options.parent); - - // TODO: replace nullptr with parent context in span context - auto sampling_result = - sampler_->ShouldSample(nullptr, parent.trace_id(), name, options.kind, attributes); - if (sampling_result.decision == Decision::DROP) - { - // Don't allocate a no-op span for every DROP decision, but use a static - // singleton for this case. - static nostd::shared_ptr noop_span( - new trace_api::NoopSpan{this->shared_from_this()}); - - return noop_span; - } - else - { -<<<<<<< HEAD - auto span = nostd::shared_ptr{ - new (std::nothrow) Span{this->shared_from_this(), processor_.load(), name, attributes, - links, options, GetCurrentSpanContext()}}; -======= - auto span = nostd::shared_ptr{new (std::nothrow) Span{ - this->shared_from_this(), processor_.load(), name, attributes, options, parent}}; ->>>>>>> master - - // if the attributes is not nullptr, add attributes to the span. - if (sampling_result.attributes) - { - for (auto &kv : *sampling_result.attributes) - { - span->SetAttribute(kv.first, kv.second); - } - } - - return span; - } -} - -void Tracer::ForceFlushWithMicroseconds(uint64_t timeout) noexcept -{ - (void)timeout; -} - -void Tracer::CloseWithMicroseconds(uint64_t timeout) noexcept -{ - (void)timeout; -} -} // namespace trace -} // namespace sdk -OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/tracer_BASE_1799.cc b/sdk/src/trace/tracer_BASE_1799.cc deleted file mode 100644 index 70a7b42109..0000000000 --- a/sdk/src/trace/tracer_BASE_1799.cc +++ /dev/null @@ -1,94 +0,0 @@ -#include "opentelemetry/sdk/trace/tracer.h" - -#include "opentelemetry/context/runtime_context.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/common/atomic_shared_ptr.h" -#include "opentelemetry/version.h" -#include "src/trace/span.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ -namespace trace -{ -Tracer::Tracer(std::shared_ptr processor, std::shared_ptr sampler) noexcept - : processor_{processor}, sampler_{sampler} -{} - -void Tracer::SetProcessor(std::shared_ptr processor) noexcept -{ - processor_.store(processor); -} - -std::shared_ptr Tracer::GetProcessor() const noexcept -{ - return processor_.load(); -} - -std::shared_ptr Tracer::GetSampler() const noexcept -{ - return sampler_; -} - -// Helper function to extract the current span context from the runtime context. -// Returns an invalid span context if the runtime context doesn't contain a span. -trace_api::SpanContext GetCurrentSpanContext() -{ - context::ContextValue curr_span_context = context::RuntimeContext::GetValue(SpanKey); - - if (nostd::holds_alternative>(curr_span_context)) - { - auto curr_span = nostd::get>(curr_span_context); - return curr_span->GetContext(); - } - return trace_api::SpanContext(); -} - -nostd::shared_ptr Tracer::StartSpan( - nostd::string_view name, - const trace_api::KeyValueIterable &attributes, - const trace_api::StartSpanOptions &options) noexcept -{ - // TODO: replace nullptr with parent context in span context - auto sampling_result = - sampler_->ShouldSample(nullptr, trace_api::TraceId(), name, options.kind, attributes); - if (sampling_result.decision == Decision::DROP) - { - // Don't allocate a no-op span for every DROP decision, but use a static - // singleton for this case. - static nostd::shared_ptr noop_span( - new trace_api::NoopSpan{this->shared_from_this()}); - - return noop_span; - } - else - { - auto span = nostd::shared_ptr{ - new (std::nothrow) Span{this->shared_from_this(), processor_.load(), name, attributes, - options, GetCurrentSpanContext()}}; - - // if the attributes is not nullptr, add attributes to the span. - if (sampling_result.attributes) - { - for (auto &kv : *sampling_result.attributes) - { - span->SetAttribute(kv.first, kv.second); - } - } - - return span; - } -} - -void Tracer::ForceFlushWithMicroseconds(uint64_t timeout) noexcept -{ - (void)timeout; -} - -void Tracer::CloseWithMicroseconds(uint64_t timeout) noexcept -{ - (void)timeout; -} -} // namespace trace -} // namespace sdk -OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/tracer_REMOTE_1034.cc b/sdk/src/trace/tracer_REMOTE_1034.cc deleted file mode 100644 index ee3d74ce1e..0000000000 --- a/sdk/src/trace/tracer_REMOTE_1034.cc +++ /dev/null @@ -1,102 +0,0 @@ -#include "opentelemetry/sdk/trace/tracer.h" - -#include "opentelemetry/context/runtime_context.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/common/atomic_shared_ptr.h" -#include "opentelemetry/version.h" -#include "src/trace/span.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ -namespace trace -{ -Tracer::Tracer(std::shared_ptr processor, std::shared_ptr sampler) noexcept - : processor_{processor}, sampler_{sampler} -{} - -void Tracer::SetProcessor(std::shared_ptr processor) noexcept -{ - processor_.store(processor); -} - -std::shared_ptr Tracer::GetProcessor() const noexcept -{ - return processor_.load(); -} - -std::shared_ptr Tracer::GetSampler() const noexcept -{ - return sampler_; -} - -trace_api::SpanContext GetCurrentSpanContext(const trace_api::SpanContext &explicit_parent) -{ - // Use the explicit parent, if it's valid. - if (explicit_parent.IsValid()) - { - return explicit_parent; - } - - // Use the currently active span, if there's one. - auto curr_span_context = context::RuntimeContext::GetValue(SpanKey); - - if (nostd::holds_alternative>(curr_span_context)) - { - auto curr_span = nostd::get>(curr_span_context); - return curr_span->GetContext(); - } - - // Otherwise return an invalid SpanContext. - return trace_api::SpanContext::GetInvalid(); -} - -nostd::shared_ptr Tracer::StartSpan( - nostd::string_view name, - const trace_api::KeyValueIterable &attributes, - const trace_api::StartSpanOptions &options) noexcept -{ - trace_api::SpanContext parent = GetCurrentSpanContext(options.parent); - - // TODO: replace nullptr with parent context in span context - auto sampling_result = - sampler_->ShouldSample(nullptr, parent.trace_id(), name, options.kind, attributes); - if (sampling_result.decision == Decision::DROP) - { - // Don't allocate a no-op span for every DROP decision, but use a static - // singleton for this case. - static nostd::shared_ptr noop_span( - new trace_api::NoopSpan{this->shared_from_this()}); - - return noop_span; - } - else - { - auto span = nostd::shared_ptr{new (std::nothrow) Span{ - this->shared_from_this(), processor_.load(), name, attributes, options, parent}}; - - // if the attributes is not nullptr, add attributes to the span. - if (sampling_result.attributes) - { - for (auto &kv : *sampling_result.attributes) - { - span->SetAttribute(kv.first, kv.second); - } - } - - return span; - } -} - -void Tracer::ForceFlushWithMicroseconds(uint64_t timeout) noexcept -{ - (void)timeout; -} - -void Tracer::CloseWithMicroseconds(uint64_t timeout) noexcept -{ - (void)timeout; -} -} // namespace trace -} // namespace sdk -OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/tracer_REMOTE_1799.cc b/sdk/src/trace/tracer_REMOTE_1799.cc deleted file mode 100644 index ee3d74ce1e..0000000000 --- a/sdk/src/trace/tracer_REMOTE_1799.cc +++ /dev/null @@ -1,102 +0,0 @@ -#include "opentelemetry/sdk/trace/tracer.h" - -#include "opentelemetry/context/runtime_context.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/common/atomic_shared_ptr.h" -#include "opentelemetry/version.h" -#include "src/trace/span.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ -namespace trace -{ -Tracer::Tracer(std::shared_ptr processor, std::shared_ptr sampler) noexcept - : processor_{processor}, sampler_{sampler} -{} - -void Tracer::SetProcessor(std::shared_ptr processor) noexcept -{ - processor_.store(processor); -} - -std::shared_ptr Tracer::GetProcessor() const noexcept -{ - return processor_.load(); -} - -std::shared_ptr Tracer::GetSampler() const noexcept -{ - return sampler_; -} - -trace_api::SpanContext GetCurrentSpanContext(const trace_api::SpanContext &explicit_parent) -{ - // Use the explicit parent, if it's valid. - if (explicit_parent.IsValid()) - { - return explicit_parent; - } - - // Use the currently active span, if there's one. - auto curr_span_context = context::RuntimeContext::GetValue(SpanKey); - - if (nostd::holds_alternative>(curr_span_context)) - { - auto curr_span = nostd::get>(curr_span_context); - return curr_span->GetContext(); - } - - // Otherwise return an invalid SpanContext. - return trace_api::SpanContext::GetInvalid(); -} - -nostd::shared_ptr Tracer::StartSpan( - nostd::string_view name, - const trace_api::KeyValueIterable &attributes, - const trace_api::StartSpanOptions &options) noexcept -{ - trace_api::SpanContext parent = GetCurrentSpanContext(options.parent); - - // TODO: replace nullptr with parent context in span context - auto sampling_result = - sampler_->ShouldSample(nullptr, parent.trace_id(), name, options.kind, attributes); - if (sampling_result.decision == Decision::DROP) - { - // Don't allocate a no-op span for every DROP decision, but use a static - // singleton for this case. - static nostd::shared_ptr noop_span( - new trace_api::NoopSpan{this->shared_from_this()}); - - return noop_span; - } - else - { - auto span = nostd::shared_ptr{new (std::nothrow) Span{ - this->shared_from_this(), processor_.load(), name, attributes, options, parent}}; - - // if the attributes is not nullptr, add attributes to the span. - if (sampling_result.attributes) - { - for (auto &kv : *sampling_result.attributes) - { - span->SetAttribute(kv.first, kv.second); - } - } - - return span; - } -} - -void Tracer::ForceFlushWithMicroseconds(uint64_t timeout) noexcept -{ - (void)timeout; -} - -void Tracer::CloseWithMicroseconds(uint64_t timeout) noexcept -{ - (void)timeout; -} -} // namespace trace -} // namespace sdk -OPENTELEMETRY_END_NAMESPACE From 85f255bfcbc469ec286a0c372b84b413a1eeb3eb Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 15 Oct 2020 23:37:31 +0530 Subject: [PATCH 12/23] Delete tracer_LOCAL_1034.cc --- sdk/src/trace/tracer_LOCAL_1034.cc | 95 ------------------------------ 1 file changed, 95 deletions(-) delete mode 100644 sdk/src/trace/tracer_LOCAL_1034.cc diff --git a/sdk/src/trace/tracer_LOCAL_1034.cc b/sdk/src/trace/tracer_LOCAL_1034.cc deleted file mode 100644 index 3f155a6679..0000000000 --- a/sdk/src/trace/tracer_LOCAL_1034.cc +++ /dev/null @@ -1,95 +0,0 @@ -#include "opentelemetry/sdk/trace/tracer.h" - -#include "opentelemetry/context/runtime_context.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/common/atomic_shared_ptr.h" -#include "opentelemetry/version.h" -#include "src/trace/span.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ -namespace trace -{ -Tracer::Tracer(std::shared_ptr processor, std::shared_ptr sampler) noexcept - : processor_{processor}, sampler_{sampler} -{} - -void Tracer::SetProcessor(std::shared_ptr processor) noexcept -{ - processor_.store(processor); -} - -std::shared_ptr Tracer::GetProcessor() const noexcept -{ - return processor_.load(); -} - -std::shared_ptr Tracer::GetSampler() const noexcept -{ - return sampler_; -} - -// Helper function to extract the current span context from the runtime context. -// Returns an invalid span context if the runtime context doesn't contain a span. -trace_api::SpanContext GetCurrentSpanContext() -{ - context::ContextValue curr_span_context = context::RuntimeContext::GetValue(SpanKey); - - if (nostd::holds_alternative>(curr_span_context)) - { - auto curr_span = nostd::get>(curr_span_context); - return curr_span->GetContext(); - } - return trace_api::SpanContext(); -} - -nostd::shared_ptr Tracer::StartSpan( - nostd::string_view name, - const trace_api::KeyValueIterable &attributes, - const trace_api::SpanContextKeyValueIterable &links, - const trace_api::StartSpanOptions &options) noexcept -{ - // TODO: replace nullptr with parent context in span context - auto sampling_result = - sampler_->ShouldSample(nullptr, trace_api::TraceId(), name, options.kind, attributes); - if (sampling_result.decision == Decision::DROP) - { - // Don't allocate a no-op span for every DROP decision, but use a static - // singleton for this case. - static nostd::shared_ptr noop_span( - new trace_api::NoopSpan{this->shared_from_this()}); - - return noop_span; - } - else - { - auto span = nostd::shared_ptr{ - new (std::nothrow) Span{this->shared_from_this(), processor_.load(), name, attributes, - links, options, GetCurrentSpanContext()}}; - - // if the attributes is not nullptr, add attributes to the span. - if (sampling_result.attributes) - { - for (auto &kv : *sampling_result.attributes) - { - span->SetAttribute(kv.first, kv.second); - } - } - - return span; - } -} - -void Tracer::ForceFlushWithMicroseconds(uint64_t timeout) noexcept -{ - (void)timeout; -} - -void Tracer::CloseWithMicroseconds(uint64_t timeout) noexcept -{ - (void)timeout; -} -} // namespace trace -} // namespace sdk -OPENTELEMETRY_END_NAMESPACE From 39c2b37d90e651a5649e00745e186edad6d82ffd Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 15 Oct 2020 23:37:49 +0530 Subject: [PATCH 13/23] Delete tracer_BACKUP_1034.cc --- sdk/src/trace/tracer_BACKUP_1034.cc | 109 ---------------------------- 1 file changed, 109 deletions(-) delete mode 100644 sdk/src/trace/tracer_BACKUP_1034.cc diff --git a/sdk/src/trace/tracer_BACKUP_1034.cc b/sdk/src/trace/tracer_BACKUP_1034.cc deleted file mode 100644 index 7386652698..0000000000 --- a/sdk/src/trace/tracer_BACKUP_1034.cc +++ /dev/null @@ -1,109 +0,0 @@ -#include "opentelemetry/sdk/trace/tracer.h" - -#include "opentelemetry/context/runtime_context.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/common/atomic_shared_ptr.h" -#include "opentelemetry/version.h" -#include "src/trace/span.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ -namespace trace -{ -Tracer::Tracer(std::shared_ptr processor, std::shared_ptr sampler) noexcept - : processor_{processor}, sampler_{sampler} -{} - -void Tracer::SetProcessor(std::shared_ptr processor) noexcept -{ - processor_.store(processor); -} - -std::shared_ptr Tracer::GetProcessor() const noexcept -{ - return processor_.load(); -} - -std::shared_ptr Tracer::GetSampler() const noexcept -{ - return sampler_; -} - -trace_api::SpanContext GetCurrentSpanContext(const trace_api::SpanContext &explicit_parent) -{ - // Use the explicit parent, if it's valid. - if (explicit_parent.IsValid()) - { - return explicit_parent; - } - - // Use the currently active span, if there's one. - auto curr_span_context = context::RuntimeContext::GetValue(SpanKey); - - if (nostd::holds_alternative>(curr_span_context)) - { - auto curr_span = nostd::get>(curr_span_context); - return curr_span->GetContext(); - } - - // Otherwise return an invalid SpanContext. - return trace_api::SpanContext::GetInvalid(); -} - -nostd::shared_ptr Tracer::StartSpan( - nostd::string_view name, - const trace_api::KeyValueIterable &attributes, - const trace_api::SpanContextKeyValueIterable &links, - const trace_api::StartSpanOptions &options) noexcept -{ - trace_api::SpanContext parent = GetCurrentSpanContext(options.parent); - - // TODO: replace nullptr with parent context in span context - auto sampling_result = - sampler_->ShouldSample(nullptr, parent.trace_id(), name, options.kind, attributes); - if (sampling_result.decision == Decision::DROP) - { - // Don't allocate a no-op span for every DROP decision, but use a static - // singleton for this case. - static nostd::shared_ptr noop_span( - new trace_api::NoopSpan{this->shared_from_this()}); - - return noop_span; - } - else - { -<<<<<<< HEAD - auto span = nostd::shared_ptr{ - new (std::nothrow) Span{this->shared_from_this(), processor_.load(), name, attributes, - links, options, GetCurrentSpanContext()}}; -======= - auto span = nostd::shared_ptr{new (std::nothrow) Span{ - this->shared_from_this(), processor_.load(), name, attributes, options, parent}}; ->>>>>>> master - - // if the attributes is not nullptr, add attributes to the span. - if (sampling_result.attributes) - { - for (auto &kv : *sampling_result.attributes) - { - span->SetAttribute(kv.first, kv.second); - } - } - - return span; - } -} - -void Tracer::ForceFlushWithMicroseconds(uint64_t timeout) noexcept -{ - (void)timeout; -} - -void Tracer::CloseWithMicroseconds(uint64_t timeout) noexcept -{ - (void)timeout; -} -} // namespace trace -} // namespace sdk -OPENTELEMETRY_END_NAMESPACE From c13c1822c1bc1f9688e452a658f2ad5ec6aa37fa Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 15 Oct 2020 23:37:59 +0530 Subject: [PATCH 14/23] Delete tracer_BASE_1034.cc --- sdk/src/trace/tracer_BASE_1034.cc | 94 ------------------------------- 1 file changed, 94 deletions(-) delete mode 100644 sdk/src/trace/tracer_BASE_1034.cc diff --git a/sdk/src/trace/tracer_BASE_1034.cc b/sdk/src/trace/tracer_BASE_1034.cc deleted file mode 100644 index 70a7b42109..0000000000 --- a/sdk/src/trace/tracer_BASE_1034.cc +++ /dev/null @@ -1,94 +0,0 @@ -#include "opentelemetry/sdk/trace/tracer.h" - -#include "opentelemetry/context/runtime_context.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/common/atomic_shared_ptr.h" -#include "opentelemetry/version.h" -#include "src/trace/span.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ -namespace trace -{ -Tracer::Tracer(std::shared_ptr processor, std::shared_ptr sampler) noexcept - : processor_{processor}, sampler_{sampler} -{} - -void Tracer::SetProcessor(std::shared_ptr processor) noexcept -{ - processor_.store(processor); -} - -std::shared_ptr Tracer::GetProcessor() const noexcept -{ - return processor_.load(); -} - -std::shared_ptr Tracer::GetSampler() const noexcept -{ - return sampler_; -} - -// Helper function to extract the current span context from the runtime context. -// Returns an invalid span context if the runtime context doesn't contain a span. -trace_api::SpanContext GetCurrentSpanContext() -{ - context::ContextValue curr_span_context = context::RuntimeContext::GetValue(SpanKey); - - if (nostd::holds_alternative>(curr_span_context)) - { - auto curr_span = nostd::get>(curr_span_context); - return curr_span->GetContext(); - } - return trace_api::SpanContext(); -} - -nostd::shared_ptr Tracer::StartSpan( - nostd::string_view name, - const trace_api::KeyValueIterable &attributes, - const trace_api::StartSpanOptions &options) noexcept -{ - // TODO: replace nullptr with parent context in span context - auto sampling_result = - sampler_->ShouldSample(nullptr, trace_api::TraceId(), name, options.kind, attributes); - if (sampling_result.decision == Decision::DROP) - { - // Don't allocate a no-op span for every DROP decision, but use a static - // singleton for this case. - static nostd::shared_ptr noop_span( - new trace_api::NoopSpan{this->shared_from_this()}); - - return noop_span; - } - else - { - auto span = nostd::shared_ptr{ - new (std::nothrow) Span{this->shared_from_this(), processor_.load(), name, attributes, - options, GetCurrentSpanContext()}}; - - // if the attributes is not nullptr, add attributes to the span. - if (sampling_result.attributes) - { - for (auto &kv : *sampling_result.attributes) - { - span->SetAttribute(kv.first, kv.second); - } - } - - return span; - } -} - -void Tracer::ForceFlushWithMicroseconds(uint64_t timeout) noexcept -{ - (void)timeout; -} - -void Tracer::CloseWithMicroseconds(uint64_t timeout) noexcept -{ - (void)timeout; -} -} // namespace trace -} // namespace sdk -OPENTELEMETRY_END_NAMESPACE From 76d7c112eed0aa4e6cc49236d29fd4495046497b Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 15 Oct 2020 23:38:08 +0530 Subject: [PATCH 15/23] Delete tracer_LOCAL_1799.cc --- sdk/src/trace/tracer_LOCAL_1799.cc | 95 ------------------------------ 1 file changed, 95 deletions(-) delete mode 100644 sdk/src/trace/tracer_LOCAL_1799.cc diff --git a/sdk/src/trace/tracer_LOCAL_1799.cc b/sdk/src/trace/tracer_LOCAL_1799.cc deleted file mode 100644 index 3f155a6679..0000000000 --- a/sdk/src/trace/tracer_LOCAL_1799.cc +++ /dev/null @@ -1,95 +0,0 @@ -#include "opentelemetry/sdk/trace/tracer.h" - -#include "opentelemetry/context/runtime_context.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/sdk/common/atomic_shared_ptr.h" -#include "opentelemetry/version.h" -#include "src/trace/span.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ -namespace trace -{ -Tracer::Tracer(std::shared_ptr processor, std::shared_ptr sampler) noexcept - : processor_{processor}, sampler_{sampler} -{} - -void Tracer::SetProcessor(std::shared_ptr processor) noexcept -{ - processor_.store(processor); -} - -std::shared_ptr Tracer::GetProcessor() const noexcept -{ - return processor_.load(); -} - -std::shared_ptr Tracer::GetSampler() const noexcept -{ - return sampler_; -} - -// Helper function to extract the current span context from the runtime context. -// Returns an invalid span context if the runtime context doesn't contain a span. -trace_api::SpanContext GetCurrentSpanContext() -{ - context::ContextValue curr_span_context = context::RuntimeContext::GetValue(SpanKey); - - if (nostd::holds_alternative>(curr_span_context)) - { - auto curr_span = nostd::get>(curr_span_context); - return curr_span->GetContext(); - } - return trace_api::SpanContext(); -} - -nostd::shared_ptr Tracer::StartSpan( - nostd::string_view name, - const trace_api::KeyValueIterable &attributes, - const trace_api::SpanContextKeyValueIterable &links, - const trace_api::StartSpanOptions &options) noexcept -{ - // TODO: replace nullptr with parent context in span context - auto sampling_result = - sampler_->ShouldSample(nullptr, trace_api::TraceId(), name, options.kind, attributes); - if (sampling_result.decision == Decision::DROP) - { - // Don't allocate a no-op span for every DROP decision, but use a static - // singleton for this case. - static nostd::shared_ptr noop_span( - new trace_api::NoopSpan{this->shared_from_this()}); - - return noop_span; - } - else - { - auto span = nostd::shared_ptr{ - new (std::nothrow) Span{this->shared_from_this(), processor_.load(), name, attributes, - links, options, GetCurrentSpanContext()}}; - - // if the attributes is not nullptr, add attributes to the span. - if (sampling_result.attributes) - { - for (auto &kv : *sampling_result.attributes) - { - span->SetAttribute(kv.first, kv.second); - } - } - - return span; - } -} - -void Tracer::ForceFlushWithMicroseconds(uint64_t timeout) noexcept -{ - (void)timeout; -} - -void Tracer::CloseWithMicroseconds(uint64_t timeout) noexcept -{ - (void)timeout; -} -} // namespace trace -} // namespace sdk -OPENTELEMETRY_END_NAMESPACE From 8722685c204c8aab48eddb912a5c5a5c038dd2ea Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 15 Oct 2020 23:42:48 +0530 Subject: [PATCH 16/23] fix tracer --- api/include/opentelemetry/trace/tracer.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/api/include/opentelemetry/trace/tracer.h b/api/include/opentelemetry/trace/tracer.h index b38b1f2dfd..79c4a56cf3 100644 --- a/api/include/opentelemetry/trace/tracer.h +++ b/api/include/opentelemetry/trace/tracer.h @@ -48,11 +48,6 @@ class Tracer const T &attributes, const StartSpanOptions &options = {}) noexcept { - - /*SpanContextKeyValueIterableView>>>> links({}); */ - // return this->StartSpan(name, KeyValueIterableView(attributes), {}, options); return this->StartSpan(name, attributes, {}, options); } From 983de1c28cc9b365f06ba8692466daa8d0177159 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Fri, 16 Oct 2020 00:10:34 +0530 Subject: [PATCH 17/23] fix newline --- api/include/opentelemetry/trace/span_context_kv_iterable.h | 2 +- api/include/opentelemetry/trace/span_context_kv_iterable_view.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/include/opentelemetry/trace/span_context_kv_iterable.h b/api/include/opentelemetry/trace/span_context_kv_iterable.h index d7970378dc..5d2bd64422 100644 --- a/api/include/opentelemetry/trace/span_context_kv_iterable.h +++ b/api/include/opentelemetry/trace/span_context_kv_iterable.h @@ -32,4 +32,4 @@ class SpanContextKeyValueIterable virtual size_t size() const noexcept = 0; }; } // namespace trace -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +OPENTELEMETRY_END_NAMESPACE diff --git a/api/include/opentelemetry/trace/span_context_kv_iterable_view.h b/api/include/opentelemetry/trace/span_context_kv_iterable_view.h index e27c7bd553..ae3e5b00ec 100644 --- a/api/include/opentelemetry/trace/span_context_kv_iterable_view.h +++ b/api/include/opentelemetry/trace/span_context_kv_iterable_view.h @@ -96,4 +96,4 @@ class SpanContextKeyValueIterableView final : public SpanContextKeyValueIterable const T *container_; }; } // namespace trace -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +OPENTELEMETRY_END_NAMESPACE From 84b755f4edad4b57573bb1904fb62cb7b91bff9c Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 11 Nov 2020 00:51:37 +0530 Subject: [PATCH 18/23] fix spancontext kv view --- .../trace/span_context_kv_iterable.h | 2 +- .../trace/span_context_kv_iterable_view.h | 67 ++++++++++++------- sdk/src/trace/span.cc | 37 ++-------- 3 files changed, 46 insertions(+), 60 deletions(-) diff --git a/api/include/opentelemetry/trace/span_context_kv_iterable.h b/api/include/opentelemetry/trace/span_context_kv_iterable.h index 5d2bd64422..fb52daf83d 100644 --- a/api/include/opentelemetry/trace/span_context_kv_iterable.h +++ b/api/include/opentelemetry/trace/span_context_kv_iterable.h @@ -24,7 +24,7 @@ class SpanContextKeyValueIterable */ virtual bool ForEachKeyValue( nostd::function_ref< - bool(SpanContext, nostd::string_view, common::AttributeValue, bool /*is_last_kv */)> + bool(SpanContext, opentelemetry::trace::KeyValueIterable&)> callback) const noexcept = 0; /** * @return the number of key-value pairs diff --git a/api/include/opentelemetry/trace/span_context_kv_iterable_view.h b/api/include/opentelemetry/trace/span_context_kv_iterable_view.h index ae3e5b00ec..51f582d5a9 100644 --- a/api/include/opentelemetry/trace/span_context_kv_iterable_view.h +++ b/api/include/opentelemetry/trace/span_context_kv_iterable_view.h @@ -53,47 +53,62 @@ class SpanContextKeyValueIterableView final : public SpanContextKeyValueIterable explicit SpanContextKeyValueIterableView(const T &links) noexcept : container_{&links} {} bool ForEachKeyValue( - nostd::function_ref + nostd::function_ref callback) const noexcept override { auto iter = std::begin(*container_); auto last = std::end(*container_); for (; iter != last; ++iter) { - auto kv_iter = std::begin(iter->second); - auto kv_end = std::end(iter->second); - // attributes are optional, and so may be empty container - if (kv_iter == kv_end) - { - if (!callback(iter->first, "", static_cast(""), true)) - { - return false; - } - } - else - { - auto kv_last = std::prev(kv_end); - bool is_last_kv = false; - for (; kv_iter != kv_end; ++kv_iter) - { - if (kv_iter == kv_last) - { - is_last_kv = true; - } - if (!callback(iter->first, kv_iter->first, kv_iter->second, is_last_kv)) - { - return false; - } - } + auto attributes = iter->second; + if (!this->do_callback(iter->first, iter->second, callback)){ + return false; } } return true; } + size_t size() const noexcept override { return nostd::size(*container_); } private: const T *container_; + + bool do_callback( + SpanContext span_context, + const KeyValueIterable &attributes, + nostd::function_ref callback + ) const noexcept + { + if (!callback(span_context, const_cast (attributes))) + { + return false; + } + return true; + } + + template ::value> * = nullptr> + bool do_callback( + SpanContext span_context, + const U &attributes, + nostd::function_ref callback + ) const noexcept + { + return do_callback( span_context, KeyValueIterableView(attributes), callback); + } + + bool do_callback( + SpanContext span_context, + std::initializer_list> attributes, + nostd::function_ref callback + ) const noexcept + { + return do_callback(span_context, + nostd::span>{attributes.begin(), + attributes.end()}, + callback); + } + }; } // namespace trace OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 0e5a1525d5..acc789ac9c 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -101,40 +101,11 @@ Span::Span(std::shared_ptr &&tracer, return true; }); - links.ForEachKeyValue([&](trace_api::SpanContext span_context, nostd::string_view key, - opentelemetry::common::AttributeValue value, bool is_last_kv) noexcept { - static std::unordered_map - link_attributes = {}; - if (is_last_kv) + links.ForEachKeyValue([&](opentelemetry::trace::SpanContext span_context, opentelemetry::trace::KeyValueIterable& attributes) { - if (key.size()) - { - link_attributes.insert( - std::make_pair( - std::move(key), std::move(value))); - } - if (link_attributes.size()) - { - recordable_->AddLink( - span_context, - trace_api::KeyValueIterableView< - std::unordered_map>( - link_attributes)); - } - else - { - recordable_->AddLink(span_context); - } - link_attributes.clear(); - } - else - { - link_attributes.insert( - std::make_pair( - std::move(key), std::move(value))); - } - return true; - }); + recordable_->AddLink(span_context, attributes); + return true; + }); recordable_->SetStartTime(NowOr(options.start_system_time)); start_steady_time = NowOr(options.start_steady_time); From 42ad517349bda664d8971d53c4cde06c9058a39e Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 11 Nov 2020 01:22:18 +0530 Subject: [PATCH 19/23] format --- .../trace/span_context_kv_iterable.h | 5 +- .../trace/span_context_kv_iterable_view.h | 49 +++++++++---------- sdk/src/trace/span.cc | 10 ++-- 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/api/include/opentelemetry/trace/span_context_kv_iterable.h b/api/include/opentelemetry/trace/span_context_kv_iterable.h index 64362d10d8..ca6c837b48 100644 --- a/api/include/opentelemetry/trace/span_context_kv_iterable.h +++ b/api/include/opentelemetry/trace/span_context_kv_iterable.h @@ -23,9 +23,8 @@ class SpanContextKeyValueIterable * @return true if every SpanContext/key-value pair was iterated over */ virtual bool ForEachKeyValue( - nostd::function_ref< - bool(SpanContext, opentelemetry::common::KeyValueIterable&)> - callback) const noexcept = 0; + nostd::function_ref callback) + const noexcept = 0; /** * @return the number of key-value pairs */ diff --git a/api/include/opentelemetry/trace/span_context_kv_iterable_view.h b/api/include/opentelemetry/trace/span_context_kv_iterable_view.h index ad49480c7a..8106829e0a 100644 --- a/api/include/opentelemetry/trace/span_context_kv_iterable_view.h +++ b/api/include/opentelemetry/trace/span_context_kv_iterable_view.h @@ -4,8 +4,8 @@ #include #include -#include "opentelemetry/nostd/utility.h" #include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/nostd/utility.h" #include "opentelemetry/trace/span_context_kv_iterable.h" #include "opentelemetry/version.h" @@ -53,34 +53,33 @@ class SpanContextKeyValueIterableView final : public SpanContextKeyValueIterable explicit SpanContextKeyValueIterableView(const T &links) noexcept : container_{&links} {} bool ForEachKeyValue( - nostd::function_ref - callback) const noexcept override + nostd::function_ref callback) + const noexcept override { auto iter = std::begin(*container_); auto last = std::end(*container_); for (; iter != last; ++iter) { auto attributes = iter->second; - if (!this->do_callback(iter->first, iter->second, callback)){ + if (!this->do_callback(iter->first, iter->second, callback)) + { return false; } } return true; } - size_t size() const noexcept override { return nostd::size(*container_); } private: const T *container_; - bool do_callback( - SpanContext span_context, - const KeyValueIterable &attributes, - nostd::function_ref callback - ) const noexcept + bool do_callback(SpanContext span_context, + const KeyValueIterable &attributes, + nostd::function_ref + callback) const noexcept { - if (!callback(span_context, const_cast (attributes))) + if (!callback(span_context, const_cast(attributes))) { return false; } @@ -88,27 +87,25 @@ class SpanContextKeyValueIterableView final : public SpanContextKeyValueIterable } template ::value> * = nullptr> - bool do_callback( - SpanContext span_context, - const U &attributes, - nostd::function_ref callback - ) const noexcept + bool do_callback(SpanContext span_context, + const U &attributes, + nostd::function_ref + callback) const noexcept { - return do_callback( span_context, KeyValueIterableView(attributes), callback); + return do_callback(span_context, KeyValueIterableView(attributes), callback); } bool do_callback( - SpanContext span_context, - std::initializer_list> attributes, - nostd::function_ref callback - ) const noexcept + SpanContext span_context, + std::initializer_list> attributes, + nostd::function_ref callback) + const noexcept { - return do_callback(span_context, - nostd::span>{attributes.begin(), - attributes.end()}, - callback); + return do_callback(span_context, + nostd::span>{ + attributes.begin(), attributes.end()}, + callback); } - }; } // namespace trace OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 65a5fc4247..1c0ee86cc6 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -101,11 +101,11 @@ Span::Span(std::shared_ptr &&tracer, return true; }); - links.ForEachKeyValue([&](opentelemetry::trace::SpanContext span_context, opentelemetry::common::KeyValueIterable& attributes) - { - recordable_->AddLink(span_context, attributes); - return true; - }); + links.ForEachKeyValue([&](opentelemetry::trace::SpanContext span_context, + opentelemetry::common::KeyValueIterable &attributes) { + recordable_->AddLink(span_context, attributes); + return true; + }); recordable_->SetStartTime(NowOr(options.start_system_time)); start_steady_time = NowOr(options.start_steady_time); From 147b92dfea782e3ef87638aef431f09329186e53 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 11 Nov 2020 01:26:06 +0530 Subject: [PATCH 20/23] fix kv_iterable header --- api/include/opentelemetry/trace/span_context_kv_iterable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/include/opentelemetry/trace/span_context_kv_iterable.h b/api/include/opentelemetry/trace/span_context_kv_iterable.h index ca6c837b48..6620f1a46f 100644 --- a/api/include/opentelemetry/trace/span_context_kv_iterable.h +++ b/api/include/opentelemetry/trace/span_context_kv_iterable.h @@ -1,8 +1,8 @@ #pragma once #include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable_view.h" #include "opentelemetry/nostd/function_ref.h" -#include "opentelemetry/trace/key_value_iterable_view.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE From 49ec04cf628b02b786508faf9973a4500b1eb186 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 11 Nov 2020 01:46:20 +0530 Subject: [PATCH 21/23] fix kv iterable namespace --- .../trace/span_context_kv_iterable_view.h | 24 +++++++++---------- api/include/opentelemetry/trace/tracer.h | 10 ++++---- sdk/test/trace/tracer_test.cc | 2 +- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/api/include/opentelemetry/trace/span_context_kv_iterable_view.h b/api/include/opentelemetry/trace/span_context_kv_iterable_view.h index 8106829e0a..d649902295 100644 --- a/api/include/opentelemetry/trace/span_context_kv_iterable_view.h +++ b/api/include/opentelemetry/trace/span_context_kv_iterable_view.h @@ -15,10 +15,10 @@ namespace trace namespace detail { template -inline void take_span_context_kv(SpanContext, opentelemetry::common::KeyValueIterableView) +inline void take_span_context_kv(SpanContext, common::KeyValueIterableView) {} -template ::value> * = nullptr> +template ::value> * = nullptr> inline void take_span_context_kv(SpanContext, T &) {} @@ -75,31 +75,31 @@ class SpanContextKeyValueIterableView final : public SpanContextKeyValueIterable const T *container_; bool do_callback(SpanContext span_context, - const KeyValueIterable &attributes, + const common::KeyValueIterable &attributes, nostd::function_ref callback) const noexcept { - if (!callback(span_context, const_cast(attributes))) + if (!callback(span_context, const_cast(attributes))) { return false; } return true; } - template ::value> * = nullptr> - bool do_callback(SpanContext span_context, - const U &attributes, - nostd::function_ref - callback) const noexcept + template ::value> * = nullptr> + bool do_callback( + SpanContext span_context, + const U &attributes, + nostd::function_ref callback) const noexcept { - return do_callback(span_context, KeyValueIterableView(attributes), callback); + return do_callback(span_context, common::KeyValueIterableView(attributes), callback); } bool do_callback( SpanContext span_context, std::initializer_list> attributes, - nostd::function_ref callback) - const noexcept + nostd::function_ref callback) const noexcept { return do_callback(span_context, nostd::span>{ diff --git a/api/include/opentelemetry/trace/tracer.h b/api/include/opentelemetry/trace/tracer.h index 68c94f9fd2..09cf389d8b 100644 --- a/api/include/opentelemetry/trace/tracer.h +++ b/api/include/opentelemetry/trace/tracer.h @@ -54,8 +54,8 @@ class Tracer template ::value> * = nullptr, - nostd::enable_if_t::value> * = nullptr> + nostd::enable_if_t::value> * = nullptr, + nostd::enable_if_t::value> * = nullptr> nostd::shared_ptr StartSpan(nostd::string_view name, const T &attributes, const U &links, @@ -74,7 +74,8 @@ class Tracer return this->StartSpan(name, attributes, {}, options); } - template ::value> * = nullptr> + template ::value> * = nullptr> nostd::shared_ptr StartSpan( nostd::string_view name, const T &attributes, @@ -92,7 +93,8 @@ class Tracer options); } - template ::value> * = nullptr> + template ::value> * = nullptr> nostd::shared_ptr StartSpan( nostd::string_view name, std::initializer_list> attributes, diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index a2e69f0591..22160617df 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -13,9 +13,9 @@ using opentelemetry::core::SteadyTimestamp; using opentelemetry::core::SystemTimestamp; namespace nostd = opentelemetry::nostd; namespace common = opentelemetry::common; +using opentelemetry::common::KeyValueIterableView; using opentelemetry::exporter::memory::InMemorySpanData; using opentelemetry::exporter::memory::InMemorySpanExporter; -using opentelemetry::trace::KeyValueIterableView; using opentelemetry::trace::SpanContext; /** From 6bdc5219c041c39b8e08e3e0a489d5f5855dbae5 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 11 Nov 2020 23:37:35 +0530 Subject: [PATCH 22/23] remove un-necessary header --- sdk/src/trace/span.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 1c0ee86cc6..c5c02a9bcd 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -5,8 +5,6 @@ #include "opentelemetry/trace/trace_flags.h" #include "opentelemetry/version.h" -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { From 693917c27d72b447cad70cf14c2ba1f5187c39d3 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 12 Nov 2020 12:20:04 +0530 Subject: [PATCH 23/23] review comments --- .../trace/span_context_kv_iterable.h | 4 ++-- .../trace/span_context_kv_iterable_view.h | 22 ++++++++++--------- sdk/src/trace/span.cc | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/api/include/opentelemetry/trace/span_context_kv_iterable.h b/api/include/opentelemetry/trace/span_context_kv_iterable.h index 6620f1a46f..bcc7465b89 100644 --- a/api/include/opentelemetry/trace/span_context_kv_iterable.h +++ b/api/include/opentelemetry/trace/span_context_kv_iterable.h @@ -23,8 +23,8 @@ class SpanContextKeyValueIterable * @return true if every SpanContext/key-value pair was iterated over */ virtual bool ForEachKeyValue( - nostd::function_ref callback) - const noexcept = 0; + nostd::function_ref + callback) const noexcept = 0; /** * @return the number of key-value pairs */ diff --git a/api/include/opentelemetry/trace/span_context_kv_iterable_view.h b/api/include/opentelemetry/trace/span_context_kv_iterable_view.h index d649902295..09aba93216 100644 --- a/api/include/opentelemetry/trace/span_context_kv_iterable_view.h +++ b/api/include/opentelemetry/trace/span_context_kv_iterable_view.h @@ -53,14 +53,13 @@ class SpanContextKeyValueIterableView final : public SpanContextKeyValueIterable explicit SpanContextKeyValueIterableView(const T &links) noexcept : container_{&links} {} bool ForEachKeyValue( - nostd::function_ref callback) - const noexcept override + nostd::function_ref + callback) const noexcept override { auto iter = std::begin(*container_); auto last = std::end(*container_); for (; iter != last; ++iter) { - auto attributes = iter->second; if (!this->do_callback(iter->first, iter->second, callback)) { return false; @@ -74,12 +73,13 @@ class SpanContextKeyValueIterableView final : public SpanContextKeyValueIterable private: const T *container_; - bool do_callback(SpanContext span_context, - const common::KeyValueIterable &attributes, - nostd::function_ref - callback) const noexcept + bool do_callback( + SpanContext span_context, + const common::KeyValueIterable &attributes, + nostd::function_ref + callback) const noexcept { - if (!callback(span_context, const_cast(attributes))) + if (!callback(span_context, attributes)) { return false; } @@ -91,7 +91,8 @@ class SpanContextKeyValueIterableView final : public SpanContextKeyValueIterable bool do_callback( SpanContext span_context, const U &attributes, - nostd::function_ref callback) const noexcept + nostd::function_ref callback) const + noexcept { return do_callback(span_context, common::KeyValueIterableView(attributes), callback); } @@ -99,7 +100,8 @@ class SpanContextKeyValueIterableView final : public SpanContextKeyValueIterable bool do_callback( SpanContext span_context, std::initializer_list> attributes, - nostd::function_ref callback) const noexcept + nostd::function_ref callback) const + noexcept { return do_callback(span_context, nostd::span>{ diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index c5c02a9bcd..25219453eb 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -100,7 +100,7 @@ Span::Span(std::shared_ptr &&tracer, }); links.ForEachKeyValue([&](opentelemetry::trace::SpanContext span_context, - opentelemetry::common::KeyValueIterable &attributes) { + const opentelemetry::common::KeyValueIterable &attributes) { recordable_->AddLink(span_context, attributes); return true; });