From cdcd3745830492a08685f380c2691a26efb429e9 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Mon, 5 Apr 2021 15:56:38 -0400 Subject: [PATCH 01/17] Migrate processor + sampler to TracerContext to ensure changes in TracerProvider reflect to all tracers. --- .../sdk/common/atomic_unique_ptr.h | 2 + sdk/include/opentelemetry/sdk/trace/tracer.h | 44 +++------ .../opentelemetry/sdk/trace/tracer_context.h | 79 +++++++++++++++ .../opentelemetry/sdk/trace/tracer_provider.h | 39 ++++---- sdk/src/trace/span.cc | 12 +-- sdk/src/trace/span.h | 5 +- sdk/src/trace/tracer.cc | 26 +---- sdk/src/trace/tracer_context.cc | 40 ++++++++ sdk/src/trace/tracer_provider.cc | 39 +++----- sdk/test/trace/sampler_benchmark.cc | 6 +- sdk/test/trace/tracer_provider_test.cc | 50 +++------- sdk/test/trace/tracer_test.cc | 99 +++++-------------- 12 files changed, 215 insertions(+), 226 deletions(-) create mode 100644 sdk/include/opentelemetry/sdk/trace/tracer_context.h create mode 100644 sdk/src/trace/tracer_context.cc diff --git a/sdk/include/opentelemetry/sdk/common/atomic_unique_ptr.h b/sdk/include/opentelemetry/sdk/common/atomic_unique_ptr.h index d93d9b72b2..32217da220 100644 --- a/sdk/include/opentelemetry/sdk/common/atomic_unique_ptr.h +++ b/sdk/include/opentelemetry/sdk/common/atomic_unique_ptr.h @@ -20,6 +20,8 @@ class AtomicUniquePtr public: AtomicUniquePtr() noexcept {} + explicit AtomicUniquePtr(std::unique_ptr &&other) noexcept : ptr_(other.release()) {} + ~AtomicUniquePtr() noexcept { Reset(); } T &operator*() const noexcept { return *Get(); } diff --git a/sdk/include/opentelemetry/sdk/trace/tracer.h b/sdk/include/opentelemetry/sdk/trace/tracer.h index 1e52b0e377..4e31c2c204 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer.h @@ -4,6 +4,7 @@ #include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/sdk/trace/processor.h" #include "opentelemetry/sdk/trace/samplers/always_on.h" +#include "opentelemetry/sdk/trace/tracer_context.h" #include "opentelemetry/trace/noop.h" #include "opentelemetry/trace/tracer.h" #include "opentelemetry/version.h" @@ -18,33 +19,8 @@ namespace trace class Tracer final : public trace_api::Tracer, public std::enable_shared_from_this { public: - /** - * Initialize a new tracer. - * @param processor The span processor for this tracer. This must not be a - * nullptr. - */ - explicit Tracer(std::shared_ptr processor, - const opentelemetry::sdk::resource::Resource &resource, - std::shared_ptr sampler = std::make_shared()) noexcept; - - /** - * Set the span processor associated with this tracer. - * @param processor The new span processor for this tracer. This must not be - * a nullptr. - */ - void SetProcessor(std::shared_ptr processor) noexcept; - - /** - * Obtain the span processor associated with this tracer. - * @return The span processor for this tracer. - */ - std::shared_ptr GetProcessor() const noexcept; - - /** - * Obtain the sampler associated with this tracer. - * @return The sampler for this tracer. - */ - std::shared_ptr GetSampler() const noexcept; + /** Construct a new Tracer with the given context pipeline. */ + explicit Tracer(std::shared_ptr context) noexcept; nostd::shared_ptr StartSpan( nostd::string_view name, @@ -56,10 +32,18 @@ class Tracer final : public trace_api::Tracer, public std::enable_shared_from_th void CloseWithMicroseconds(uint64_t timeout) noexcept override; + + /** Returns the currently active span processor. */ + SpanProcessor& GetActiveProcessor() noexcept { + return context_->GetActiveProcessor(); + } + + + // Note: Test only + Sampler& GetSampler() { return context_->GetSampler(); } + private: - opentelemetry::sdk::common::AtomicSharedPtr processor_; - const std::shared_ptr sampler_; - const opentelemetry::sdk::resource::Resource &resource_; + std::shared_ptr context_; }; } // namespace trace } // namespace sdk diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_context.h b/sdk/include/opentelemetry/sdk/trace/tracer_context.h new file mode 100644 index 0000000000..a25bbdc056 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/trace/tracer_context.h @@ -0,0 +1,79 @@ +#pragma once + +#include "opentelemetry/sdk/common/atomic_unique_ptr.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/samplers/always_on.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace trace +{ + +/** + * A class which stores the TracerProvider context. + * + * This class meets the following design criteria: + * - A shared reference between TracerProvider and Tracers instantiated. + * - A thread-safe class that allows updating/altering processor/exporter pipelines + * and sampling config. + * - The owner/destroyer of Processors/Exporters. These will remain active until + * this class is destroyed. I.e. Sampling, Exporting, flushing etc. are all ok if this + * object is alive, and they willl work together. If this object is destroyed, then + * no shared references to Processor, Exporter, Recordable etc. should exist, and all + * associated pipelines will have been flushed. + */ +class TracerContext +{ +public: + explicit TracerContext(std::unique_ptr processor, + opentelemetry::sdk::resource::Resource resource = + opentelemetry::sdk::resource::Resource::Create({}), + std::unique_ptr sampler = + std::unique_ptr(new AlwaysOnSampler)) noexcept; + /** + * Attaches a span processor to this tracer context. + * + * @param processor The new span processor for this tracer. This must not be + * a nullptr. Ownership is given to the `TracerContext`. + */ + void RegisterPipeline(std::unique_ptr processor) noexcept; + + /** + * Obtain the sampler associated with this tracer. + * @return The sampler for this tracer. + */ + Sampler &GetSampler() const noexcept; + + /** + * Obtain the (conceptual) active processor. + * + * Note: When more than one processor is active, this will + * return an "aggregate" processor + */ + SpanProcessor& GetActiveProcessor() const noexcept; + + /** + * Obtain the resource associated with this tracer context. + * @return The resource for this tracer context. + */ + const opentelemetry::sdk::resource::Resource &GetResource() const noexcept; + + /** + * Force all active SpanProcessors to flush any buffered spans + * within the given timeout. + */ + void ForceFlushWithMicroseconds(uint64_t timeout) noexcept; + +private: + // This is an atomic pointer so we can adapt the processor pipeline dynamically. + opentelemetry::sdk::common::AtomicUniquePtr processor_; + opentelemetry::sdk::resource::Resource resource_; + std::unique_ptr sampler_; +}; + +} // namespace trace +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h index f56a0fdab6..978ed0a7dc 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h @@ -10,6 +10,7 @@ #include "opentelemetry/sdk/trace/samplers/always_on.h" #include "opentelemetry/sdk/trace/tracer.h" #include "opentelemetry/trace/tracer_provider.h" +#include "opentelemetry/sdk/trace/tracer_context.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -26,34 +27,30 @@ class TracerProvider final : public opentelemetry::trace::TracerProvider * @param sampler The sampler for this tracer provider. This must * not be a nullptr. */ - explicit TracerProvider( - std::shared_ptr processor, - opentelemetry::sdk::resource::Resource &&resource = - opentelemetry::sdk::resource::Resource::Create({}), - std::shared_ptr sampler = std::make_shared()) noexcept; + explicit TracerProvider(std::unique_ptr processor, + opentelemetry::sdk::resource::Resource resource = + opentelemetry::sdk::resource::Resource::Create({}), + std::unique_ptr sampler = + std::unique_ptr(new AlwaysOnSampler)) noexcept; + + /** + * Initialize a new tracer provider with a specified context + * @param context The shared tracer configuration/pipeline for this provider. + */ + explicit TracerProvider(std::shared_ptr context) noexcept; opentelemetry::nostd::shared_ptr GetTracer( nostd::string_view library_name, nostd::string_view library_version = "") noexcept override; /** - * Set the span processor associated with this tracer provider. + * Attaches a span processor to this tracer provider. * @param processor The new span processor for this tracer provider. This * must not be a nullptr. + * + * Note: This process may not receive any in-flight spans, but will get newly created spans. */ - void SetProcessor(std::shared_ptr processor) noexcept; - - /** - * Obtain the span processor associated with this tracer provider. - * @return The span processor for this tracer provider. - */ - std::shared_ptr GetProcessor() const noexcept; - - /** - * Obtain the sampler associated with this tracer provider. - * @return The sampler for this tracer provider. - */ - std::shared_ptr GetSampler() const noexcept; + void RegisterProcessor(std::unique_ptr processor) noexcept; /** * Obtain the resource associated with this tracer provider. @@ -72,10 +69,8 @@ class TracerProvider final : public opentelemetry::trace::TracerProvider bool ForceFlush(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept; private: - opentelemetry::sdk::common::AtomicSharedPtr processor_; + std::shared_ptr context_; std::shared_ptr tracer_; - const std::shared_ptr sampler_; - const opentelemetry::sdk::resource::Resource resource_; }; } // namespace trace } // namespace sdk diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 576d54f38c..00c73378cb 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -58,18 +58,15 @@ trace_api::SpanId GenerateRandomSpanId() } Span::Span(std::shared_ptr &&tracer, - std::shared_ptr processor, nostd::string_view name, const opentelemetry::common::KeyValueIterable &attributes, const trace_api::SpanContextKeyValueIterable &links, const trace_api::StartSpanOptions &options, const trace_api::SpanContext &parent_span_context, - const opentelemetry::sdk::resource::Resource &resource, const nostd::shared_ptr trace_state, const bool sampled) noexcept : tracer_{std::move(tracer)}, - processor_{processor}, - recordable_{processor_->MakeRecordable()}, + recordable_{tracer_->GetActiveProcessor().MakeRecordable()}, start_steady_time{options.start_steady_time}, has_ended_{false} { @@ -118,8 +115,9 @@ Span::Span(std::shared_ptr &&tracer, recordable_->SetSpanKind(options.kind); recordable_->SetStartTime(NowOr(options.start_system_time)); start_steady_time = NowOr(options.start_steady_time); - // recordable_->SetResource(resource_); TODO - processor_->OnStart(*recordable_, parent_span_context); + // recordable_->SetResource(tracer_->GetResoource()); TODO + // recordable_->SetResource(tracer_->GetInstrumentationLibrary()); TODO + tracer_->GetActiveProcessor().OnStart(*recordable_, parent_span_context); } Span::~Span() @@ -206,7 +204,7 @@ void Span::End(const trace_api::EndSpanOptions &options) noexcept recordable_->SetDuration(std::chrono::steady_clock::time_point(end_steady_time) - std::chrono::steady_clock::time_point(start_steady_time)); - processor_->OnEnd(std::move(recordable_)); + tracer_->GetActiveProcessor().OnEnd(std::move(recordable_)); recordable_.reset(); } diff --git a/sdk/src/trace/span.h b/sdk/src/trace/span.h index 01fb995517..efc16d6c59 100644 --- a/sdk/src/trace/span.h +++ b/sdk/src/trace/span.h @@ -16,13 +16,11 @@ class Span final : public trace_api::Span { public: Span(std::shared_ptr &&tracer, - std::shared_ptr processor, nostd::string_view name, const opentelemetry::common::KeyValueIterable &attributes, const trace_api::SpanContextKeyValueIterable &links, const trace_api::StartSpanOptions &options, const trace_api::SpanContext &parent_span_context, - const opentelemetry::sdk::resource::Resource &resource, const nostd::shared_ptr trace_state = trace_api::TraceState::GetDefault(), const bool sampled = false) noexcept; @@ -52,8 +50,7 @@ class Span final : public trace_api::Span trace_api::SpanContext GetContext() const noexcept override { return *span_context_.get(); } private: - std::shared_ptr tracer_; - std::shared_ptr processor_; + std::shared_ptr tracer_; mutable std::mutex mu_; std::unique_ptr recordable_; opentelemetry::core::SteadyTimestamp start_steady_time; diff --git a/sdk/src/trace/tracer.cc b/sdk/src/trace/tracer.cc index 93fdc6f680..c7214a803c 100644 --- a/sdk/src/trace/tracer.cc +++ b/sdk/src/trace/tracer.cc @@ -10,26 +10,8 @@ namespace sdk { namespace trace { -Tracer::Tracer(std::shared_ptr processor, - const opentelemetry::sdk::resource::Resource &resource, - std::shared_ptr sampler) noexcept - : processor_{processor}, sampler_{sampler}, resource_{resource} -{} -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_; -} +Tracer::Tracer(std::shared_ptr context) noexcept : context_{context} {} trace_api::SpanContext GetCurrentSpanContext(const trace_api::SpanContext &explicit_parent) { @@ -61,7 +43,7 @@ nostd::shared_ptr Tracer::StartSpan( trace_api::SpanContext parent = GetCurrentSpanContext(options.parent); auto sampling_result = - sampler_->ShouldSample(parent, parent.trace_id(), name, options.kind, attributes, links); + context_->GetSampler().ShouldSample(parent, parent.trace_id(), name, options.kind, attributes, links); if (sampling_result.decision == Decision::DROP) { // Don't allocate a no-op span for every DROP decision, but use a static @@ -74,8 +56,8 @@ nostd::shared_ptr Tracer::StartSpan( else { auto span = nostd::shared_ptr{new (std::nothrow) Span{ - this->shared_from_this(), processor_.load(), name, attributes, links, options, parent, - resource_, sampling_result.trace_state, true}}; + this->shared_from_this(), name, attributes, links, options, parent, + sampling_result.trace_state, true}}; // if the attributes is not nullptr, add attributes to the span. if (sampling_result.attributes) diff --git a/sdk/src/trace/tracer_context.cc b/sdk/src/trace/tracer_context.cc new file mode 100644 index 0000000000..8384d4d2a5 --- /dev/null +++ b/sdk/src/trace/tracer_context.cc @@ -0,0 +1,40 @@ +#include "opentelemetry/sdk/trace/tracer_context.h" +#include "opentelemetry/sdk/trace/processor.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace trace +{ + +TracerContext::TracerContext(std::unique_ptr processor, + opentelemetry::sdk::resource::Resource resource, + std::unique_ptr sampler) noexcept + : processor_(std::move(processor)), resource_(resource), sampler_(std::move(sampler)) +{} + +Sampler &TracerContext::GetSampler() const noexcept +{ + return *sampler_.get(); +} + +const opentelemetry::sdk::resource::Resource &TracerContext::GetResource() const noexcept +{ + return resource_; +} + +void TracerContext::RegisterPipeline(std::unique_ptr processor) noexcept +{ + // TODO(jsuereth): Implement + // 1. If existing processor is an "AggregateProcessor" append the new processor to it. + // 2. If the existing processor is NOT an "AggregateProcessor", create a new Aggregate of this and the other, + // then replace our atomic ptr with the new aggregate. +} + +SpanProcessor& TracerContext::GetActiveProcessor() const noexcept { + return *processor_; +} + +} // namespace trace +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/tracer_provider.cc b/sdk/src/trace/tracer_provider.cc index cc236292a2..cb1fd0327a 100644 --- a/sdk/src/trace/tracer_provider.cc +++ b/sdk/src/trace/tracer_provider.cc @@ -5,13 +5,14 @@ namespace sdk { namespace trace { -TracerProvider::TracerProvider(std::shared_ptr processor, - opentelemetry::sdk::resource::Resource &&resource, - std::shared_ptr sampler) noexcept - : processor_{processor}, - tracer_(new Tracer(std::move(processor), resource, sampler)), - sampler_(sampler), - resource_(resource) +TracerProvider::TracerProvider(std::shared_ptr context) noexcept + : context_{context}, tracer_(new Tracer(context)) +{} + +TracerProvider::TracerProvider(std::unique_ptr processor, + opentelemetry::sdk::resource::Resource resource, + std::unique_ptr sampler) noexcept + : TracerProvider(std::make_shared(std::move(processor), resource, std::move(sampler))) {} opentelemetry::nostd::shared_ptr TracerProvider::GetTracer( @@ -21,38 +22,26 @@ opentelemetry::nostd::shared_ptr TracerProvider::G return opentelemetry::nostd::shared_ptr(tracer_); } -void TracerProvider::SetProcessor(std::shared_ptr processor) noexcept -{ - processor_.store(processor); - - auto sdkTracer = static_cast(tracer_.get()); - sdkTracer->SetProcessor(processor); -} - -std::shared_ptr TracerProvider::GetProcessor() const noexcept +void TracerProvider::RegisterProcessor(std::unique_ptr processor) noexcept { - return processor_.load(); -} - -std::shared_ptr TracerProvider::GetSampler() const noexcept -{ - return sampler_; + return context_->RegisterPipeline(std::move(processor)); } const opentelemetry::sdk::resource::Resource &TracerProvider::GetResource() const noexcept { - return resource_; + return context_->GetResource(); } bool TracerProvider::Shutdown() noexcept { - return GetProcessor()->Shutdown(); + return context_->GetActiveProcessor().Shutdown(); } bool TracerProvider::ForceFlush(std::chrono::microseconds timeout) noexcept { - return GetProcessor()->ForceFlush(timeout); + return context_->GetActiveProcessor().ForceFlush(timeout); } + } // namespace trace } // namespace sdk OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/test/trace/sampler_benchmark.cc b/sdk/test/trace/sampler_benchmark.cc index 5606206ce6..90a07adc77 100644 --- a/sdk/test/trace/sampler_benchmark.cc +++ b/sdk/test/trace/sampler_benchmark.cc @@ -118,10 +118,10 @@ BENCHMARK(BM_TraceIdRatioBasedSamplerShouldSample); void BenchmarkSpanCreation(std::shared_ptr sampler, benchmark::State &state) { std::unique_ptr exporter(new InMemorySpanExporter()); - auto processor = std::make_shared(std::move(exporter)); + auto processor = std::unique_ptr(new SimpleSpanProcessor(std::move(exporter))); + auto context = std::make_shared(std::move(processor)); auto resource = opentelemetry::sdk::resource::Resource::Create({}); - auto tracer = - std::shared_ptr(new Tracer(processor, resource, sampler)); + auto tracer = std::shared_ptr(new Tracer(context)); while (state.KeepRunning()) { diff --git a/sdk/test/trace/tracer_provider_test.cc b/sdk/test/trace/tracer_provider_test.cc index 7cfe306278..55a5a9be44 100644 --- a/sdk/test/trace/tracer_provider_test.cc +++ b/sdk/test/trace/tracer_provider_test.cc @@ -12,9 +12,9 @@ using namespace opentelemetry::sdk::resource; TEST(TracerProvider, GetTracer) { - std::shared_ptr processor(new SimpleSpanProcessor(nullptr)); + std::unique_ptr processor(new SimpleSpanProcessor(nullptr)); - TracerProvider tp1(processor, Resource::Create({})); + TracerProvider tp1(std::make_shared(std::move(processor), Resource::Create({}))); auto t1 = tp1.GetTracer("test"); auto t2 = tp1.GetTracer("test"); auto t3 = tp1.GetTracer("different", "1.0.0"); @@ -24,58 +24,34 @@ TEST(TracerProvider, GetTracer) // Should return the same instance each time. ASSERT_EQ(t1, t2); + // TODO: t3 should be a different instance. ASSERT_EQ(t1, t3); // Should be an sdk::trace::Tracer with the processor attached. auto sdkTracer1 = dynamic_cast(t1.get()); ASSERT_NE(nullptr, sdkTracer1); - ASSERT_EQ(processor, sdkTracer1->GetProcessor()); - ASSERT_EQ("AlwaysOnSampler", sdkTracer1->GetSampler()->GetDescription()); - - TracerProvider tp2(processor, Resource::Create({}), std::make_shared()); + ASSERT_EQ("AlwaysOnSampler", sdkTracer1->GetSampler().GetDescription()); + TracerProvider tp2(std::make_shared( + std::unique_ptr(new SimpleSpanProcessor(nullptr)), Resource::Create({}), + std::unique_ptr(new AlwaysOffSampler()))); auto sdkTracer2 = dynamic_cast(tp2.GetTracer("test").get()); - ASSERT_EQ("AlwaysOffSampler", sdkTracer2->GetSampler()->GetDescription()); -} - -TEST(TracerProvider, GetSampler) -{ - std::shared_ptr processor1(new SimpleSpanProcessor(nullptr)); - - // Create a TracerProvicer with a default AlwaysOnSampler. - TracerProvider tp1(processor1); - auto t1 = tp1.GetSampler(); - auto t2 = tp1.GetSampler(); - ASSERT_NE(nullptr, t1); - ASSERT_NE(nullptr, t2); - - // Should return the same sampler each time. - ASSERT_EQ(t1, t2); - - // Should be AlwaysOnSampler - ASSERT_EQ("AlwaysOnSampler", t2->GetDescription()); - - // Create a TracerProvicer with a custom AlwaysOffSampler. - std::shared_ptr processor2(new SimpleSpanProcessor(nullptr)); - TracerProvider tp2(processor2, Resource::Create({}), std::make_shared()); - auto t3 = tp2.GetSampler(); - - ASSERT_EQ("AlwaysOffSampler", t3->GetDescription()); + ASSERT_EQ("AlwaysOffSampler", sdkTracer2->GetSampler().GetDescription()); } TEST(TracerProvider, Shutdown) { - std::shared_ptr processor1(new SimpleSpanProcessor(nullptr)); + std::unique_ptr processor1(new SimpleSpanProcessor(nullptr)); - TracerProvider tp1(processor1); + TracerProvider tp1(std::make_shared(std::move(processor1))); EXPECT_TRUE(tp1.Shutdown()); } TEST(TracerProvider, ForceFlush) { - std::shared_ptr processor1(new SimpleSpanProcessor(nullptr)); + std::unique_ptr processor1(new SimpleSpanProcessor(nullptr)); - TracerProvider tp1(processor1); + TracerProvider tp1(std::move(processor1)); EXPECT_TRUE(tp1.ForceFlush()); -} +} \ No newline at end of file diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index 60544f6fdc..176a949670 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -19,7 +19,6 @@ using opentelemetry::common::KeyValueIterableView; using opentelemetry::exporter::memory::InMemorySpanData; using opentelemetry::exporter::memory::InMemorySpanExporter; using opentelemetry::trace::SpanContext; -using opentelemetry::trace::TraceFlags; /** * A mock sampler that returns non-empty sampling results attributes. @@ -48,22 +47,23 @@ class MockSampler final : public Sampler namespace { -std::shared_ptr initTracer( - std::unique_ptr &&exporter) +std::shared_ptr initTracer(std::unique_ptr &&exporter) { - auto processor = std::make_shared(std::move(exporter)); - auto resource = Resource::Create({}); - return std::shared_ptr(new Tracer(processor, resource)); + auto processor = std::unique_ptr(new SimpleSpanProcessor(std::move(exporter))); + auto context = std::make_shared(std::move(processor)); + return std::shared_ptr(new Tracer(context)); } std::shared_ptr initTracer( - std::unique_ptr &&exporter, - std::shared_ptr sampler) + std::unique_ptr &&exporter, + // For testing, just shove a pointer over, we'll take it over. + Sampler *sampler) { - auto processor = std::make_shared(std::move(exporter)); + auto processor = std::unique_ptr(new SimpleSpanProcessor(std::move(exporter))); auto resource = Resource::Create({}); - - return std::shared_ptr(new Tracer(processor, resource, sampler)); + auto context = std::make_shared(std::move(processor), resource, + std::unique_ptr(sampler)); + return std::shared_ptr(new Tracer(context)); } } // namespace @@ -122,7 +122,7 @@ TEST(Tracer, StartSpanSampleOff) { std::unique_ptr exporter(new InMemorySpanExporter()); std::shared_ptr span_data = exporter->GetData(); - auto tracer_off = initTracer(std::move(exporter), std::make_shared()); + auto tracer_off = initTracer(std::move(exporter), new AlwaysOffSampler()); // This span will not be recorded. tracer_off->StartSpan("span 2")->End(); @@ -283,19 +283,16 @@ TEST(Tracer, GetSampler) { auto resource = Resource::Create({}); // Create a Tracer with a default AlwaysOnSampler - std::shared_ptr processor_1(new SimpleSpanProcessor(nullptr)); - std::shared_ptr tracer_on(new Tracer(std::move(processor_1), resource)); + auto tracer_on = initTracer(nullptr); - auto t1 = tracer_on->GetSampler(); - ASSERT_EQ("AlwaysOnSampler", t1->GetDescription()); + auto &t1 = std::dynamic_pointer_cast(tracer_on)->GetSampler(); + ASSERT_EQ("AlwaysOnSampler", t1.GetDescription()); // Create a Tracer with a AlwaysOffSampler - std::shared_ptr processor_2(new SimpleSpanProcessor(nullptr)); - std::shared_ptr tracer_off( - new Tracer(std::move(processor_2), resource, std::make_shared())); + auto tracer_off = initTracer(nullptr, new AlwaysOffSampler()); - auto t2 = tracer_off->GetSampler(); - ASSERT_EQ("AlwaysOffSampler", t2->GetDescription()); + auto &t2 = std::dynamic_pointer_cast(tracer_off)->GetSampler(); + ASSERT_EQ("AlwaysOffSampler", t2.GetDescription()); } TEST(Tracer, SpanSetAttribute) @@ -441,7 +438,7 @@ TEST(Tracer, TestAlwaysOffSampler) { std::unique_ptr exporter(new InMemorySpanExporter()); std::shared_ptr span_data = exporter->GetData(); - auto tracer_off = initTracer(std::move(exporter), std::make_shared()); + auto tracer_off = initTracer(std::move(exporter), new AlwaysOffSampler()); auto span_off_1 = tracer_off->StartSpan("span 1"); auto span_off_2 = tracer_off->StartSpan("span 2"); @@ -461,8 +458,7 @@ TEST(Tracer, TestParentBasedSampler) std::unique_ptr exporter(new InMemorySpanExporter()); std::shared_ptr span_data_parent_on = exporter->GetData(); auto tracer_parent_on = - initTracer(std::move(exporter), - std::make_shared(std::make_shared())); + initTracer(std::move(exporter), new ParentBasedSampler(std::make_shared())); auto span_parent_on_1 = tracer_parent_on->StartSpan("span 1"); auto span_parent_on_2 = tracer_parent_on->StartSpan("span 2"); @@ -481,9 +477,8 @@ TEST(Tracer, TestParentBasedSampler) // so this sampler will work as an AlwaysOnSampler. std::unique_ptr exporter2(new InMemorySpanExporter()); std::shared_ptr span_data_parent_off = exporter2->GetData(); - auto tracer_parent_off = - initTracer(std::move(exporter2), - std::make_shared(std::make_shared())); + auto tracer_parent_off = initTracer(std::move(exporter2), + new ParentBasedSampler(std::make_shared())); auto span_parent_off_1 = tracer_parent_off->StartSpan("span 1"); auto span_parent_off_2 = tracer_parent_off->StartSpan("span 2"); @@ -563,52 +558,4 @@ TEST(Tracer, ExpectParent) EXPECT_EQ(spandata_first->GetSpanId(), spandata_second->GetParentSpanId()); EXPECT_EQ(spandata_second->GetSpanId(), spandata_third->GetParentSpanId()); -} - -TEST(Tracer, ExpectParentWithValidSpanContext) -{ - std::unique_ptr exporter(new InMemorySpanExporter()); - std::shared_ptr span_data = exporter->GetData(); - auto tracer = initTracer(std::move(exporter)); - auto spans = span_data.get()->GetSpans(); - - ASSERT_EQ(0, spans.size()); - - // produce valid SpanContext with pseudo span and trace Id. - uint8_t span_id_buf[trace_api::SpanId::kSize] = { - 1, - }; - trace_api::SpanId span_id{span_id_buf}; - uint8_t trace_id_buf[trace_api::TraceId::kSize] = { - 2, - }; - trace_api::TraceId trace_id{trace_id_buf}; - - trace_api::StartSpanOptions options; - options.parent = SpanContext(trace_id, span_id, TraceFlags{TraceFlags::kIsSampled}, true); - - auto span_first = tracer->StartSpan("span 1", options); - - EXPECT_EQ(span_first->GetContext().trace_flags().IsSampled(), true); - - options.parent = span_first->GetContext(); - auto span_second = tracer->StartSpan("span 2", options); - EXPECT_EQ(span_second->GetContext().trace_flags().IsSampled(), true); - - options.parent = span_second->GetContext(); - auto span_third = tracer->StartSpan("span 3", options); - EXPECT_EQ(span_third->GetContext().trace_flags().IsSampled(), true); - - span_third->End(); - span_second->End(); - span_first->End(); - - spans = span_data->GetSpans(); - ASSERT_EQ(3, spans.size()); - auto spandata_first = std::move(spans.at(2)); - auto spandata_second = std::move(spans.at(1)); - auto spandata_third = std::move(spans.at(0)); - - EXPECT_EQ(spandata_first->GetSpanId(), spandata_second->GetParentSpanId()); - EXPECT_EQ(spandata_second->GetSpanId(), spandata_third->GetParentSpanId()); -} +} \ No newline at end of file From 7a65e53508ff64365a95a4c5b427b0554f1d17e8 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Mon, 5 Apr 2021 16:12:54 -0400 Subject: [PATCH 02/17] Fix build for non-SDK directories. --- examples/batch/main.cc | 4 ++-- examples/multithreaded/main.cc | 4 ++-- examples/otlp/main.cc | 4 ++-- examples/simple/main.cc | 5 ++--- exporters/otlp/test/otlp_exporter_test.cc | 4 ++-- ext/include/opentelemetry/ext/zpages/zpages.h | 4 +--- ext/test/w3c_tracecontext_test/main.cc | 5 +++-- ext/test/zpages/tracez_data_aggregator_test.cc | 6 ++++-- ext/test/zpages/tracez_processor_test.cc | 7 ++++++- 9 files changed, 24 insertions(+), 19 deletions(-) diff --git a/examples/batch/main.cc b/examples/batch/main.cc index 36372d0eb3..32e285d344 100644 --- a/examples/batch/main.cc +++ b/examples/batch/main.cc @@ -28,11 +28,11 @@ void initTracer() // We export `kNumSpans` after every `schedule_delay_millis` milliseconds. options.max_export_batch_size = kNumSpans; - auto processor = std::shared_ptr( + auto processor = std::unique_ptr( new sdktrace::BatchSpanProcessor(std::move(exporter), options)); auto provider = nostd::shared_ptr( - new sdktrace::TracerProvider(processor)); + new sdktrace::TracerProvider(std::move(processor))); // Set the global trace provider. opentelemetry::trace::Provider::SetTracerProvider(provider); } diff --git a/examples/multithreaded/main.cc b/examples/multithreaded/main.cc index 1a756c973b..c4d20b2924 100644 --- a/examples/multithreaded/main.cc +++ b/examples/multithreaded/main.cc @@ -16,10 +16,10 @@ void initTracer() { auto exporter = std::unique_ptr( new opentelemetry::exporter::trace::OStreamSpanExporter); - auto processor = std::shared_ptr( + auto processor = std::unique_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); auto provider = nostd::shared_ptr( - new sdktrace::TracerProvider(processor, opentelemetry::sdk::resource::Resource::Create({}))); + new sdktrace::TracerProvider(std::move(processor), opentelemetry::sdk::resource::Resource::Create({}))); // Set the global trace provider opentelemetry::trace::Provider::SetTracerProvider(provider); } diff --git a/examples/otlp/main.cc b/examples/otlp/main.cc index 00a557c1ff..de43ad1be5 100644 --- a/examples/otlp/main.cc +++ b/examples/otlp/main.cc @@ -17,9 +17,9 @@ void InitTracer() { // Create OTLP exporter instance auto exporter = std::unique_ptr(new otlp::OtlpExporter(opts)); - auto processor = std::shared_ptr( + auto processor = std::unique_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); - auto provider = nostd::shared_ptr(new sdktrace::TracerProvider(processor)); + auto provider = nostd::shared_ptr(new sdktrace::TracerProvider(std::move(processor))); // Set the global trace provider trace::Provider::SetTracerProvider(provider); } diff --git a/examples/simple/main.cc b/examples/simple/main.cc index 5d22c6b155..28d9196dd6 100644 --- a/examples/simple/main.cc +++ b/examples/simple/main.cc @@ -12,11 +12,10 @@ void initTracer() { auto exporter = std::unique_ptr( new opentelemetry::exporter::trace::OStreamSpanExporter); - auto processor = std::shared_ptr( + auto processor = std::unique_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); auto provider = nostd::shared_ptr( - new sdktrace::TracerProvider(processor, opentelemetry::sdk::resource::Resource::Create({}), - std::make_shared())); + new sdktrace::TracerProvider(std::move(processor))); // Set the global trace provider opentelemetry::trace::Provider::SetTracerProvider(provider); diff --git a/exporters/otlp/test/otlp_exporter_test.cc b/exporters/otlp/test/otlp_exporter_test.cc index f23696ddad..3d474c6d03 100644 --- a/exporters/otlp/test/otlp_exporter_test.cc +++ b/exporters/otlp/test/otlp_exporter_test.cc @@ -67,10 +67,10 @@ TEST_F(OtlpExporterTestPeer, ExportIntegrationTest) auto exporter = GetExporter(stub_interface); - auto processor = std::shared_ptr( + auto processor = std::unique_ptr( new sdk::trace::SimpleSpanProcessor(std::move(exporter))); auto provider = - nostd::shared_ptr(new sdk::trace::TracerProvider(processor)); + nostd::shared_ptr(new sdk::trace::TracerProvider(std::move(processor))); auto tracer = provider->GetTracer("test"); EXPECT_CALL(*mock_stub, Export(_, _, _)) diff --git a/ext/include/opentelemetry/ext/zpages/zpages.h b/ext/include/opentelemetry/ext/zpages/zpages.h index a32b2bf161..49f5bb7f94 100644 --- a/ext/include/opentelemetry/ext/zpages/zpages.h +++ b/ext/include/opentelemetry/ext/zpages/zpages.h @@ -51,10 +51,8 @@ class ZPages /** Replaces the global tracer provider with an instance that exports to tracez. */ void ReplaceGlobalProvider() { - std::shared_ptr tracez_processor( - MakeSpanProcessor().release()); auto tracez_provider_ = opentelemetry::nostd::shared_ptr( - new opentelemetry::sdk::trace::TracerProvider(tracez_processor)); + new opentelemetry::sdk::trace::TracerProvider(MakeSpanProcessor())); opentelemetry::trace::Provider::SetTracerProvider(tracez_provider_); } diff --git a/ext/test/w3c_tracecontext_test/main.cc b/ext/test/w3c_tracecontext_test/main.cc index 7ec727957f..fc26801079 100644 --- a/ext/test/w3c_tracecontext_test/main.cc +++ b/ext/test/w3c_tracecontext_test/main.cc @@ -38,10 +38,11 @@ void initTracer() { auto exporter = std::unique_ptr( new opentelemetry::exporter::trace::OStreamSpanExporter); - auto processor = std::shared_ptr( + auto processor = std::unique_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); + auto context = std::make_shared(std::move(processor)); auto provider = nostd::shared_ptr( - new sdktrace::TracerProvider(processor)); + new sdktrace::TracerProvider(context)); // Set the global trace provider opentelemetry::trace::Provider::SetTracerProvider(provider); } diff --git a/ext/test/zpages/tracez_data_aggregator_test.cc b/ext/test/zpages/tracez_data_aggregator_test.cc index 82af11a274..3cfd98b54a 100644 --- a/ext/test/zpages/tracez_data_aggregator_test.cc +++ b/ext/test/zpages/tracez_data_aggregator_test.cc @@ -35,9 +35,11 @@ class TracezDataAggregatorTest : public ::testing::Test void SetUp() override { std::shared_ptr shared_data(new TracezSharedData()); - std::shared_ptr processor(new TracezSpanProcessor(shared_data)); auto resource = opentelemetry::sdk::resource::Resource::Create({}); - tracer = std::shared_ptr(new Tracer(processor, resource)); + auto context = std::make_shared( + std::unique_ptr(new TracezSpanProcessor(shared_data)), + resource); + tracer = std::shared_ptr(new Tracer(context)); tracez_data_aggregator = std::unique_ptr( new TracezDataAggregator(shared_data, milliseconds(10))); } diff --git a/ext/test/zpages/tracez_processor_test.cc b/ext/test/zpages/tracez_processor_test.cc index c0ec2dde39..22c09efaf1 100644 --- a/ext/test/zpages/tracez_processor_test.cc +++ b/ext/test/zpages/tracez_processor_test.cc @@ -178,8 +178,13 @@ class TracezProcessor : public ::testing::Test shared_data = std::shared_ptr(new TracezSharedData()); processor = std::shared_ptr(new TracezSpanProcessor(shared_data)); auto resource = opentelemetry::sdk::resource::Resource::Create({}); + // Note: we make a *different* processor for the tracercontext. THis is because + // all the tests use shared data, and we want to make sure this works correctly. + auto context = std::make_shared( + std::unique_ptr(new TracezSpanProcessor(shared_data)), + resource); - tracer = std::shared_ptr(new Tracer(processor, resource)); + tracer = std::shared_ptr(new Tracer(context)); auto spans = shared_data->GetSpanSnapshot(); running = spans.running; completed = std::move(spans.completed); From 0e69d1d17913f062f04f3ef04beb0efbb8ae458e Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Mon, 5 Apr 2021 16:17:27 -0400 Subject: [PATCH 03/17] Fix cmake. --- sdk/src/trace/CMakeLists.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sdk/src/trace/CMakeLists.txt b/sdk/src/trace/CMakeLists.txt index d4ff82f63e..e3d3e0afec 100644 --- a/sdk/src/trace/CMakeLists.txt +++ b/sdk/src/trace/CMakeLists.txt @@ -1,7 +1,12 @@ add_library( opentelemetry_trace - tracer_provider.cc tracer.cc span.cc batch_span_processor.cc - samplers/parent.cc samplers/trace_id_ratio.cc) + tracer_context.cc + tracer_provider.cc + tracer.cc + span.cc + batch_span_processor.cc + samplers/parent.cc + samplers/trace_id_ratio.cc) set_target_properties(opentelemetry_trace PROPERTIES EXPORT_NAME trace) From 7849f77443ea3d3e33fba518da0d070c352ac270 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Mon, 5 Apr 2021 16:26:34 -0400 Subject: [PATCH 04/17] Run formatter. --- examples/multithreaded/main.cc | 5 +++-- examples/otlp/main.cc | 3 ++- ext/test/zpages/tracez_data_aggregator_test.cc | 5 ++--- ext/test/zpages/tracez_processor_test.cc | 5 ++--- sdk/include/opentelemetry/sdk/trace/tracer.h | 8 ++------ sdk/include/opentelemetry/sdk/trace/tracer_context.h | 6 +++--- sdk/include/opentelemetry/sdk/trace/tracer_provider.h | 4 ++-- sdk/src/trace/span.cc | 6 +++--- sdk/src/trace/tracer.cc | 10 +++++----- sdk/src/trace/tracer_context.cc | 6 ++++-- sdk/src/trace/tracer_provider.cc | 3 ++- 11 files changed, 30 insertions(+), 31 deletions(-) diff --git a/examples/multithreaded/main.cc b/examples/multithreaded/main.cc index c4d20b2924..309d7ff19a 100644 --- a/examples/multithreaded/main.cc +++ b/examples/multithreaded/main.cc @@ -18,8 +18,9 @@ void initTracer() new opentelemetry::exporter::trace::OStreamSpanExporter); auto processor = std::unique_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); - auto provider = nostd::shared_ptr( - new sdktrace::TracerProvider(std::move(processor), opentelemetry::sdk::resource::Resource::Create({}))); + auto provider = + nostd::shared_ptr(new sdktrace::TracerProvider( + std::move(processor), opentelemetry::sdk::resource::Resource::Create({}))); // Set the global trace provider opentelemetry::trace::Provider::SetTracerProvider(provider); } diff --git a/examples/otlp/main.cc b/examples/otlp/main.cc index de43ad1be5..f2ec3c3edd 100644 --- a/examples/otlp/main.cc +++ b/examples/otlp/main.cc @@ -19,7 +19,8 @@ void InitTracer() auto exporter = std::unique_ptr(new otlp::OtlpExporter(opts)); auto processor = std::unique_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); - auto provider = nostd::shared_ptr(new sdktrace::TracerProvider(std::move(processor))); + auto provider = + nostd::shared_ptr(new sdktrace::TracerProvider(std::move(processor))); // Set the global trace provider trace::Provider::SetTracerProvider(provider); } diff --git a/ext/test/zpages/tracez_data_aggregator_test.cc b/ext/test/zpages/tracez_data_aggregator_test.cc index 3cfd98b54a..324cf0c612 100644 --- a/ext/test/zpages/tracez_data_aggregator_test.cc +++ b/ext/test/zpages/tracez_data_aggregator_test.cc @@ -37,9 +37,8 @@ class TracezDataAggregatorTest : public ::testing::Test std::shared_ptr shared_data(new TracezSharedData()); auto resource = opentelemetry::sdk::resource::Resource::Create({}); auto context = std::make_shared( - std::unique_ptr(new TracezSpanProcessor(shared_data)), - resource); - tracer = std::shared_ptr(new Tracer(context)); + std::unique_ptr(new TracezSpanProcessor(shared_data)), resource); + tracer = std::shared_ptr(new Tracer(context)); tracez_data_aggregator = std::unique_ptr( new TracezDataAggregator(shared_data, milliseconds(10))); } diff --git a/ext/test/zpages/tracez_processor_test.cc b/ext/test/zpages/tracez_processor_test.cc index 22c09efaf1..7ea4063d60 100644 --- a/ext/test/zpages/tracez_processor_test.cc +++ b/ext/test/zpages/tracez_processor_test.cc @@ -180,9 +180,8 @@ class TracezProcessor : public ::testing::Test auto resource = opentelemetry::sdk::resource::Resource::Create({}); // Note: we make a *different* processor for the tracercontext. THis is because // all the tests use shared data, and we want to make sure this works correctly. - auto context = std::make_shared( - std::unique_ptr(new TracezSpanProcessor(shared_data)), - resource); + auto context = std::make_shared( + std::unique_ptr(new TracezSpanProcessor(shared_data)), resource); tracer = std::shared_ptr(new Tracer(context)); auto spans = shared_data->GetSpanSnapshot(); diff --git a/sdk/include/opentelemetry/sdk/trace/tracer.h b/sdk/include/opentelemetry/sdk/trace/tracer.h index 4e31c2c204..f764c48478 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer.h @@ -32,15 +32,11 @@ class Tracer final : public trace_api::Tracer, public std::enable_shared_from_th void CloseWithMicroseconds(uint64_t timeout) noexcept override; - /** Returns the currently active span processor. */ - SpanProcessor& GetActiveProcessor() noexcept { - return context_->GetActiveProcessor(); - } - + SpanProcessor &GetActiveProcessor() noexcept { return context_->GetActiveProcessor(); } // Note: Test only - Sampler& GetSampler() { return context_->GetSampler(); } + Sampler &GetSampler() { return context_->GetSampler(); } private: std::shared_ptr context_; diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_context.h b/sdk/include/opentelemetry/sdk/trace/tracer_context.h index a25bbdc056..963d010316 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_context.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_context.h @@ -35,7 +35,7 @@ class TracerContext std::unique_ptr(new AlwaysOnSampler)) noexcept; /** * Attaches a span processor to this tracer context. - * + * * @param processor The new span processor for this tracer. This must not be * a nullptr. Ownership is given to the `TracerContext`. */ @@ -49,11 +49,11 @@ class TracerContext /** * Obtain the (conceptual) active processor. - * + * * Note: When more than one processor is active, this will * return an "aggregate" processor */ - SpanProcessor& GetActiveProcessor() const noexcept; + SpanProcessor &GetActiveProcessor() const noexcept; /** * Obtain the resource associated with this tracer context. diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h index 978ed0a7dc..2e56bf7019 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h @@ -9,8 +9,8 @@ #include "opentelemetry/sdk/trace/processor.h" #include "opentelemetry/sdk/trace/samplers/always_on.h" #include "opentelemetry/sdk/trace/tracer.h" -#include "opentelemetry/trace/tracer_provider.h" #include "opentelemetry/sdk/trace/tracer_context.h" +#include "opentelemetry/trace/tracer_provider.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -47,7 +47,7 @@ class TracerProvider final : public opentelemetry::trace::TracerProvider * Attaches a span processor to this tracer provider. * @param processor The new span processor for this tracer provider. This * must not be a nullptr. - * + * * Note: This process may not receive any in-flight spans, but will get newly created spans. */ void RegisterProcessor(std::unique_ptr processor) noexcept; diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 00c73378cb..adcc858b6d 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -96,9 +96,9 @@ Span::Span(std::shared_ptr &&tracer, trace_id, span_id, sampled ? trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled} : trace_api::TraceFlags{}, false, - trace_state ? trace_state - : is_parent_span_valid ? parent_span_context.trace_state() - : trace_api::TraceState::GetDefault())); + trace_state ? trace_state + : is_parent_span_valid ? parent_span_context.trace_state() + : trace_api::TraceState::GetDefault())); attributes.ForEachKeyValue( [&](nostd::string_view key, opentelemetry::common::AttributeValue value) noexcept { diff --git a/sdk/src/trace/tracer.cc b/sdk/src/trace/tracer.cc index c7214a803c..2d67321d83 100644 --- a/sdk/src/trace/tracer.cc +++ b/sdk/src/trace/tracer.cc @@ -42,8 +42,8 @@ nostd::shared_ptr Tracer::StartSpan( { trace_api::SpanContext parent = GetCurrentSpanContext(options.parent); - auto sampling_result = - context_->GetSampler().ShouldSample(parent, parent.trace_id(), name, options.kind, attributes, links); + auto sampling_result = context_->GetSampler().ShouldSample(parent, parent.trace_id(), name, + options.kind, attributes, links); if (sampling_result.decision == Decision::DROP) { // Don't allocate a no-op span for every DROP decision, but use a static @@ -55,9 +55,9 @@ nostd::shared_ptr Tracer::StartSpan( } else { - auto span = nostd::shared_ptr{new (std::nothrow) Span{ - this->shared_from_this(), name, attributes, links, options, parent, - sampling_result.trace_state, true}}; + auto span = nostd::shared_ptr{ + new (std::nothrow) Span{this->shared_from_this(), name, attributes, links, options, parent, + sampling_result.trace_state, true}}; // if the attributes is not nullptr, add attributes to the span. if (sampling_result.attributes) diff --git a/sdk/src/trace/tracer_context.cc b/sdk/src/trace/tracer_context.cc index 8384d4d2a5..88afa8331a 100644 --- a/sdk/src/trace/tracer_context.cc +++ b/sdk/src/trace/tracer_context.cc @@ -27,11 +27,13 @@ void TracerContext::RegisterPipeline(std::unique_ptr processor) n { // TODO(jsuereth): Implement // 1. If existing processor is an "AggregateProcessor" append the new processor to it. - // 2. If the existing processor is NOT an "AggregateProcessor", create a new Aggregate of this and the other, + // 2. If the existing processor is NOT an "AggregateProcessor", create a new Aggregate of this and + // the other, // then replace our atomic ptr with the new aggregate. } -SpanProcessor& TracerContext::GetActiveProcessor() const noexcept { +SpanProcessor &TracerContext::GetActiveProcessor() const noexcept +{ return *processor_; } diff --git a/sdk/src/trace/tracer_provider.cc b/sdk/src/trace/tracer_provider.cc index cb1fd0327a..cc4822a724 100644 --- a/sdk/src/trace/tracer_provider.cc +++ b/sdk/src/trace/tracer_provider.cc @@ -12,7 +12,8 @@ TracerProvider::TracerProvider(std::shared_ptr contex TracerProvider::TracerProvider(std::unique_ptr processor, opentelemetry::sdk::resource::Resource resource, std::unique_ptr sampler) noexcept - : TracerProvider(std::make_shared(std::move(processor), resource, std::move(sampler))) + : TracerProvider( + std::make_shared(std::move(processor), resource, std::move(sampler))) {} opentelemetry::nostd::shared_ptr TracerProvider::GetTracer( From 664299e9082429654b3e16a42d12fc7204c41000 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Mon, 5 Apr 2021 18:38:10 -0400 Subject: [PATCH 05/17] Fixes from latest clang format. --- sdk/src/trace/span.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index adcc858b6d..439de4e704 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -97,8 +97,8 @@ Span::Span(std::shared_ptr &&tracer, sampled ? trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled} : trace_api::TraceFlags{}, false, trace_state ? trace_state - : is_parent_span_valid ? parent_span_context.trace_state() - : trace_api::TraceState::GetDefault())); + : is_parent_span_valid ? parent_span_context.trace_state() + : trace_api::TraceState::GetDefault())); attributes.ForEachKeyValue( [&](nostd::string_view key, opentelemetry::common::AttributeValue value) noexcept { From 0dde5c46fb978f770404ea22a15d90ae11988dfc Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Mon, 5 Apr 2021 18:54:23 -0400 Subject: [PATCH 06/17] Add bazel build for http example and fix compilation. --- examples/http/BUILD | 28 ++++++++++++++++++++++++++++ examples/http/tracer_common.hpp | 9 +++++---- 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 examples/http/BUILD diff --git a/examples/http/BUILD b/examples/http/BUILD new file mode 100644 index 0000000000..f06d1ee7c7 --- /dev/null +++ b/examples/http/BUILD @@ -0,0 +1,28 @@ +cc_binary( + name = "example_http_client", + srcs = [ + "tracer_common.hpp", + "client.cc", + ], + deps = [ + "//api", + "//ext/src/http/client/curl:http_client_curl", + "//exporters/ostream:ostream_span_exporter", + "//sdk/src/trace", + ], +) + +cc_binary( + name = "example_http_server", + srcs = [ + "server.cc", + "tracer_common.hpp", + "server.hpp", + ], + deps = [ + "//api", + "//ext:headers", + "//exporters/ostream:ostream_span_exporter", + "//sdk/src/trace", + ], +) diff --git a/examples/http/tracer_common.hpp b/examples/http/tracer_common.hpp index b45102ac9e..19239890c6 100644 --- a/examples/http/tracer_common.hpp +++ b/examples/http/tracer_common.hpp @@ -11,11 +11,12 @@ namespace { void initTracer() { auto exporter = std::unique_ptr( new opentelemetry::exporter::trace::OStreamSpanExporter); - auto processor = std::shared_ptr( + auto processor = std::unique_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); - auto provider = nostd::shared_ptr( - new sdktrace::TracerProvider(processor, opentelemetry::sdk::resource::Resource::Create({}), - std::make_shared())); + // Default is an always-on sampler. + auto context = std::make_shared(std::move(processor)); + auto provider = nostd::shared_ptr( + new sdktrace::TracerProvider(context)); // Set the global trace provider opentelemetry::trace::Provider::SetTracerProvider(provider); } From 1e746e21945b96694bd374fb59aaeb9129fc3246 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Wed, 7 Apr 2021 11:19:18 -0400 Subject: [PATCH 07/17] Fixes from review and gcc 4.8 --- ext/include/opentelemetry/ext/zpages/zpages.h | 4 +++- sdk/include/opentelemetry/sdk/trace/tracer_context.h | 8 +++++++- sdk/src/trace/tracer_context.cc | 10 ++++++++++ sdk/src/trace/tracer_provider.cc | 4 ++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ext/include/opentelemetry/ext/zpages/zpages.h b/ext/include/opentelemetry/ext/zpages/zpages.h index 49f5bb7f94..ca09ac65a6 100644 --- a/ext/include/opentelemetry/ext/zpages/zpages.h +++ b/ext/include/opentelemetry/ext/zpages/zpages.h @@ -51,8 +51,10 @@ class ZPages /** Replaces the global tracer provider with an instance that exports to tracez. */ void ReplaceGlobalProvider() { + // GCC 4.8 can't infer the type coercion. + std::unique_ptr processor(MakeSpanProcessor().release()); auto tracez_provider_ = opentelemetry::nostd::shared_ptr( - new opentelemetry::sdk::trace::TracerProvider(MakeSpanProcessor())); + new opentelemetry::sdk::trace::TracerProvider(std::move(MakeSpanProcessor()))); opentelemetry::trace::Provider::SetTracerProvider(tracez_provider_); } diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_context.h b/sdk/include/opentelemetry/sdk/trace/tracer_context.h index 963d010316..596ccc473c 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_context.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_context.h @@ -65,7 +65,13 @@ class TracerContext * Force all active SpanProcessors to flush any buffered spans * within the given timeout. */ - void ForceFlushWithMicroseconds(uint64_t timeout) noexcept; + bool ForceFlush( + std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept; + + /** + * Shutdown the span processor associated with this tracer provider. + */ + bool Shutdown() noexcept; private: // This is an atomic pointer so we can adapt the processor pipeline dynamically. diff --git a/sdk/src/trace/tracer_context.cc b/sdk/src/trace/tracer_context.cc index 88afa8331a..a463ec81d4 100644 --- a/sdk/src/trace/tracer_context.cc +++ b/sdk/src/trace/tracer_context.cc @@ -37,6 +37,16 @@ SpanProcessor &TracerContext::GetActiveProcessor() const noexcept return *processor_; } +bool TracerContext::ForceFlush(std::chrono::microseconds timeout) noexcept +{ + return processor_->ForceFlush(timeout); +} + +bool TracerContext::Shutdown() noexcept +{ + return processor_->Shutdown(); +} + } // namespace trace } // namespace sdk OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/trace/tracer_provider.cc b/sdk/src/trace/tracer_provider.cc index cc4822a724..39018653b7 100644 --- a/sdk/src/trace/tracer_provider.cc +++ b/sdk/src/trace/tracer_provider.cc @@ -35,12 +35,12 @@ const opentelemetry::sdk::resource::Resource &TracerProvider::GetResource() cons bool TracerProvider::Shutdown() noexcept { - return context_->GetActiveProcessor().Shutdown(); + return context_->Shutdown(); } bool TracerProvider::ForceFlush(std::chrono::microseconds timeout) noexcept { - return context_->GetActiveProcessor().ForceFlush(timeout); + return context_->ForceFlush(timeout); } } // namespace trace From d0ea2969c5f341d063e3ef308c1c8fb8bc3a5a83 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Wed, 7 Apr 2021 11:21:03 -0400 Subject: [PATCH 08/17] Fix typo. --- sdk/include/opentelemetry/sdk/trace/tracer_context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_context.h b/sdk/include/opentelemetry/sdk/trace/tracer_context.h index 596ccc473c..42a067d20f 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_context.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_context.h @@ -21,7 +21,7 @@ namespace trace * and sampling config. * - The owner/destroyer of Processors/Exporters. These will remain active until * this class is destroyed. I.e. Sampling, Exporting, flushing etc. are all ok if this - * object is alive, and they willl work together. If this object is destroyed, then + * object is alive, and they will work together. If this object is destroyed, then * no shared references to Processor, Exporter, Recordable etc. should exist, and all * associated pipelines will have been flushed. */ From 576cf7c7c76e02c8a0a8d7ebb5eea97fd90df534 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Wed, 7 Apr 2021 11:27:39 -0400 Subject: [PATCH 09/17] Fix bazel build for http-client windows. --- examples/http/BUILD | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/examples/http/BUILD b/examples/http/BUILD index f06d1ee7c7..9c05b08d7d 100644 --- a/examples/http/BUILD +++ b/examples/http/BUILD @@ -10,6 +10,19 @@ cc_binary( "//exporters/ostream:ostream_span_exporter", "//sdk/src/trace", ], + # TODO: Move copts/linkopts for static CURL usage into shared bzl file. + copts = [ + "-DCURL_STATICLIB", + "-DWITH_CURL", + ], + linkopts = select({ + "//bazel:windows": [ + "-DEFAULTLIB:advapi32.lib", + "-DEFAULTLIB:crypt32.lib", + "-DEFAULTLIB:Normaliz.lib", + ], + "//conditions:default": [], + }), ) cc_binary( From cb5dfdb851a7dde115c4573b16d66ece0e70793d Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Wed, 7 Apr 2021 12:41:38 -0400 Subject: [PATCH 10/17] Take 2 at fixing the builds. --- examples/http/BUILD | 1 + ext/include/opentelemetry/ext/zpages/zpages.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/http/BUILD b/examples/http/BUILD index 9c05b08d7d..758a6af069 100644 --- a/examples/http/BUILD +++ b/examples/http/BUILD @@ -6,6 +6,7 @@ cc_binary( ], deps = [ "//api", + "//ext:headers", "//ext/src/http/client/curl:http_client_curl", "//exporters/ostream:ostream_span_exporter", "//sdk/src/trace", diff --git a/ext/include/opentelemetry/ext/zpages/zpages.h b/ext/include/opentelemetry/ext/zpages/zpages.h index ca09ac65a6..12b0fdb5ec 100644 --- a/ext/include/opentelemetry/ext/zpages/zpages.h +++ b/ext/include/opentelemetry/ext/zpages/zpages.h @@ -54,7 +54,7 @@ class ZPages // GCC 4.8 can't infer the type coercion. std::unique_ptr processor(MakeSpanProcessor().release()); auto tracez_provider_ = opentelemetry::nostd::shared_ptr( - new opentelemetry::sdk::trace::TracerProvider(std::move(MakeSpanProcessor()))); + new opentelemetry::sdk::trace::TracerProvider(std::move(processor))); opentelemetry::trace::Provider::SetTracerProvider(tracez_provider_); } From 2620a96a61a66be1dbe2c91064a26073831b9d11 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Wed, 7 Apr 2021 13:03:51 -0400 Subject: [PATCH 11/17] Another attempt to get windows to build (define curl things prior to building client lib. --- ext/src/http/client/curl/BUILD | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ext/src/http/client/curl/BUILD b/ext/src/http/client/curl/BUILD index e01988a388..e01a087762 100644 --- a/ext/src/http/client/curl/BUILD +++ b/ext/src/http/client/curl/BUILD @@ -7,6 +7,11 @@ cc_library( "http_client_factory_curl.cc", ], include_prefix = "src/http/client/curl", + # TODO: Move copts/linkopts for static CURL usage into shared bzl file. + copts = [ + "-DCURL_STATICLIB", + "-DWITH_CURL", + ], deps = [ "//api", "//ext:headers", From 9d506f18f26c4bb8bacbd77efa953e0163bf5d33 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Wed, 7 Apr 2021 17:29:50 -0400 Subject: [PATCH 12/17] Fix windows build Migrate needed windows staitc libs to the curl client library and do minor cleanup to builds. --- ext/src/http/client/curl/BUILD | 9 +++++++++ ext/test/http/BUILD | 13 ------------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/ext/src/http/client/curl/BUILD b/ext/src/http/client/curl/BUILD index e01a087762..40cd547595 100644 --- a/ext/src/http/client/curl/BUILD +++ b/ext/src/http/client/curl/BUILD @@ -12,6 +12,15 @@ cc_library( "-DCURL_STATICLIB", "-DWITH_CURL", ], + linkopts = select({ + "//bazel:windows": [ + "-DEFAULTLIB:advapi32.lib", + "-DEFAULTLIB:crypt32.lib", + "-DEFAULTLIB:Normaliz.lib", + "-DEFAULTLIB:Ws2_32.lib", + ], + "//conditions:default": [], + }), deps = [ "//api", "//ext:headers", diff --git a/ext/test/http/BUILD b/ext/test/http/BUILD index 7251c0fde6..c2d24c6e77 100644 --- a/ext/test/http/BUILD +++ b/ext/test/http/BUILD @@ -3,19 +3,6 @@ cc_test( srcs = [ "curl_http_test.cc", ], - # TODO: Move copts/linkopts for static CURL usage into shared bzl file. - copts = [ - "-DCURL_STATICLIB", - "-DWITH_CURL", - ], - linkopts = select({ - "//bazel:windows": [ - "-DEFAULTLIB:advapi32.lib", - "-DEFAULTLIB:crypt32.lib", - "-DEFAULTLIB:Normaliz.lib", - ], - "//conditions:default": [], - }), deps = [ "//ext:headers", "//ext/src/http/client/curl:http_client_curl", From 6bc5f2a43efa4f56bd9a2b5d63ac2466546d172b Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Fri, 16 Apr 2021 10:12:20 -0400 Subject: [PATCH 13/17] Fixes from review. --- sdk/include/opentelemetry/sdk/trace/tracer_context.h | 2 +- sdk/include/opentelemetry/sdk/trace/tracer_provider.h | 4 ++-- sdk/src/trace/tracer_provider.cc | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_context.h b/sdk/include/opentelemetry/sdk/trace/tracer_context.h index 42a067d20f..c613fd37e4 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_context.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_context.h @@ -37,7 +37,7 @@ class TracerContext * Attaches a span processor to this tracer context. * * @param processor The new span processor for this tracer. This must not be - * a nullptr. Ownership is given to the `TracerContext`. + * a nullptr. Ownership is given to the `TracerContext`. */ void RegisterPipeline(std::unique_ptr processor) noexcept; diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h index 2e56bf7019..0301aa7e44 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h @@ -44,13 +44,13 @@ class TracerProvider final : public opentelemetry::trace::TracerProvider nostd::string_view library_version = "") noexcept override; /** - * Attaches a span processor to this tracer provider. + * Attaches a span processor pipeline to this tracer provider. * @param processor The new span processor for this tracer provider. This * must not be a nullptr. * * Note: This process may not receive any in-flight spans, but will get newly created spans. */ - void RegisterProcessor(std::unique_ptr processor) noexcept; + void RegisterPipeline(std::unique_ptr processor) noexcept; /** * Obtain the resource associated with this tracer provider. diff --git a/sdk/src/trace/tracer_provider.cc b/sdk/src/trace/tracer_provider.cc index 39018653b7..0eaf6782f2 100644 --- a/sdk/src/trace/tracer_provider.cc +++ b/sdk/src/trace/tracer_provider.cc @@ -23,7 +23,7 @@ opentelemetry::nostd::shared_ptr TracerProvider::G return opentelemetry::nostd::shared_ptr(tracer_); } -void TracerProvider::RegisterProcessor(std::unique_ptr processor) noexcept +void TracerProvider::RegisterPipeline(std::unique_ptr processor) noexcept { return context_->RegisterPipeline(std::move(processor)); } From 50339431b6c5e548efbe3bbe063bc6ec425cd3cc Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Fri, 16 Apr 2021 10:16:42 -0400 Subject: [PATCH 14/17] Ran local code format. --- exporters/otlp/test/otlp_exporter_test.cc | 4 ++-- ext/include/opentelemetry/ext/zpages/zpages.h | 3 ++- sdk/include/opentelemetry/sdk/trace/tracer_context.h | 3 +-- sdk/src/trace/span.cc | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/exporters/otlp/test/otlp_exporter_test.cc b/exporters/otlp/test/otlp_exporter_test.cc index 28aacbd72c..c5a6098a02 100644 --- a/exporters/otlp/test/otlp_exporter_test.cc +++ b/exporters/otlp/test/otlp_exporter_test.cc @@ -75,8 +75,8 @@ TEST_F(OtlpExporterTestPeer, ExportIntegrationTest) auto processor = std::unique_ptr( new sdk::trace::SimpleSpanProcessor(std::move(exporter))); - auto provider = - nostd::shared_ptr(new sdk::trace::TracerProvider(std::move(processor))); + auto provider = nostd::shared_ptr( + new sdk::trace::TracerProvider(std::move(processor))); auto tracer = provider->GetTracer("test"); EXPECT_CALL(*mock_stub, Export(_, _, _)) diff --git a/ext/include/opentelemetry/ext/zpages/zpages.h b/ext/include/opentelemetry/ext/zpages/zpages.h index 12b0fdb5ec..b1e3606277 100644 --- a/ext/include/opentelemetry/ext/zpages/zpages.h +++ b/ext/include/opentelemetry/ext/zpages/zpages.h @@ -52,7 +52,8 @@ class ZPages void ReplaceGlobalProvider() { // GCC 4.8 can't infer the type coercion. - std::unique_ptr processor(MakeSpanProcessor().release()); + std::unique_ptr processor( + MakeSpanProcessor().release()); auto tracez_provider_ = opentelemetry::nostd::shared_ptr( new opentelemetry::sdk::trace::TracerProvider(std::move(processor))); opentelemetry::trace::Provider::SetTracerProvider(tracez_provider_); diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_context.h b/sdk/include/opentelemetry/sdk/trace/tracer_context.h index c613fd37e4..e5af3a87ba 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_context.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_context.h @@ -65,8 +65,7 @@ class TracerContext * Force all active SpanProcessors to flush any buffered spans * within the given timeout. */ - bool ForceFlush( - std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept; + bool ForceFlush(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept; /** * Shutdown the span processor associated with this tracer provider. diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 338d8c4b36..7d0896b1ec 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -97,8 +97,8 @@ Span::Span(std::shared_ptr &&tracer, sampled ? trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled} : trace_api::TraceFlags{}, false, trace_state ? trace_state - : is_parent_span_valid ? parent_span_context.trace_state() - : trace_api::TraceState::GetDefault())); + : is_parent_span_valid ? parent_span_context.trace_state() + : trace_api::TraceState::GetDefault())); recordable_->SetIdentity(*span_context_, parent_span_id); From 01bc7c7ef271572a7b4440bb0ef60fa1ae24e218 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Fri, 16 Apr 2021 10:22:23 -0400 Subject: [PATCH 15/17] Manually fix style from remote tool. --- examples/http/BUILD | 8 ++++---- ext/src/http/client/curl/BUILD | 2 +- sdk/src/trace/span.cc | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/http/BUILD b/examples/http/BUILD index 758a6af069..29cde19b30 100644 --- a/examples/http/BUILD +++ b/examples/http/BUILD @@ -1,14 +1,14 @@ cc_binary( name = "example_http_client", srcs = [ - "tracer_common.hpp", "client.cc", + "tracer_common.hpp", ], deps = [ "//api", + "//exporters/ostream:ostream_span_exporter", "//ext:headers", "//ext/src/http/client/curl:http_client_curl", - "//exporters/ostream:ostream_span_exporter", "//sdk/src/trace", ], # TODO: Move copts/linkopts for static CURL usage into shared bzl file. @@ -30,13 +30,13 @@ cc_binary( name = "example_http_server", srcs = [ "server.cc", - "tracer_common.hpp", "server.hpp", + "tracer_common.hpp", ], deps = [ "//api", - "//ext:headers", "//exporters/ostream:ostream_span_exporter", + "//ext:headers", "//sdk/src/trace", ], ) diff --git a/ext/src/http/client/curl/BUILD b/ext/src/http/client/curl/BUILD index 40cd547595..6d484d3770 100644 --- a/ext/src/http/client/curl/BUILD +++ b/ext/src/http/client/curl/BUILD @@ -6,12 +6,12 @@ cc_library( "http_client_curl.cc", "http_client_factory_curl.cc", ], - include_prefix = "src/http/client/curl", # TODO: Move copts/linkopts for static CURL usage into shared bzl file. copts = [ "-DCURL_STATICLIB", "-DWITH_CURL", ], + include_prefix = "src/http/client/curl", linkopts = select({ "//bazel:windows": [ "-DEFAULTLIB:advapi32.lib", diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 7d0896b1ec..388d0ab923 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -96,9 +96,9 @@ Span::Span(std::shared_ptr &&tracer, trace_id, span_id, sampled ? trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled} : trace_api::TraceFlags{}, false, - trace_state ? trace_state - : is_parent_span_valid ? parent_span_context.trace_state() - : trace_api::TraceState::GetDefault())); + trace_state ? trace_state + : is_parent_span_valid ? parent_span_context.trace_state() + : trace_api::TraceState::GetDefault())); recordable_->SetIdentity(*span_context_, parent_span_id); From ec4c83de6d1c9093877eee1f49a1851a3fe07fe8 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Fri, 16 Apr 2021 10:26:00 -0400 Subject: [PATCH 16/17] Last manual style fix. --- examples/http/BUILD | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/http/BUILD b/examples/http/BUILD index 29cde19b30..89fffa2676 100644 --- a/examples/http/BUILD +++ b/examples/http/BUILD @@ -4,6 +4,11 @@ cc_binary( "client.cc", "tracer_common.hpp", ], + # TODO: Move copts/linkopts for static CURL usage into shared bzl file. + copts = [ + "-DCURL_STATICLIB", + "-DWITH_CURL", + ], deps = [ "//api", "//exporters/ostream:ostream_span_exporter", @@ -11,11 +16,6 @@ cc_binary( "//ext/src/http/client/curl:http_client_curl", "//sdk/src/trace", ], - # TODO: Move copts/linkopts for static CURL usage into shared bzl file. - copts = [ - "-DCURL_STATICLIB", - "-DWITH_CURL", - ], linkopts = select({ "//bazel:windows": [ "-DEFAULTLIB:advapi32.lib", From a0999fcb1f9448b0a5beb6303b4199adace4b36f Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Fri, 16 Apr 2021 10:32:14 -0400 Subject: [PATCH 17/17] one last fix... --- examples/http/BUILD | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/http/BUILD b/examples/http/BUILD index 89fffa2676..4fce0a2e27 100644 --- a/examples/http/BUILD +++ b/examples/http/BUILD @@ -9,13 +9,6 @@ cc_binary( "-DCURL_STATICLIB", "-DWITH_CURL", ], - deps = [ - "//api", - "//exporters/ostream:ostream_span_exporter", - "//ext:headers", - "//ext/src/http/client/curl:http_client_curl", - "//sdk/src/trace", - ], linkopts = select({ "//bazel:windows": [ "-DEFAULTLIB:advapi32.lib", @@ -24,6 +17,13 @@ cc_binary( ], "//conditions:default": [], }), + deps = [ + "//api", + "//exporters/ostream:ostream_span_exporter", + "//ext:headers", + "//ext/src/http/client/curl:http_client_curl", + "//sdk/src/trace", + ], ) cc_binary(