From 23155f7caac2c6e21bb7bf4906ef858f93a3e120 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 2 Feb 2021 01:20:17 +0530 Subject: [PATCH 1/2] add parent context --- ext/include/opentelemetry/ext/zpages/tracez_processor.h | 4 +++- ext/src/zpages/tracez_processor.cc | 3 ++- sdk/include/opentelemetry/sdk/trace/batch_span_processor.h | 5 ++++- sdk/include/opentelemetry/sdk/trace/processor.h | 5 ++++- sdk/include/opentelemetry/sdk/trace/simple_processor.h | 5 ++++- sdk/src/trace/batch_span_processor.cc | 3 ++- sdk/src/trace/span.cc | 2 +- 7 files changed, 20 insertions(+), 7 deletions(-) diff --git a/ext/include/opentelemetry/ext/zpages/tracez_processor.h b/ext/include/opentelemetry/ext/zpages/tracez_processor.h index 3291a573cc..3fb8db03b8 100644 --- a/ext/include/opentelemetry/ext/zpages/tracez_processor.h +++ b/ext/include/opentelemetry/ext/zpages/tracez_processor.h @@ -48,7 +48,9 @@ class TracezSpanProcessor : public opentelemetry::sdk::trace::SpanProcessor * running_spans. * @param span a recordable for a span that was just started */ - void OnStart(opentelemetry::sdk::trace::Recordable &span) noexcept override; + void OnStart(opentelemetry::sdk::trace::Recordable &span, + const opentelemetry::trace::SpanContext &parent_context = + opentelemetry::trace::SpanContext::GetInvalid()) noexcept override; /* * OnEnd is called when a span ends; that span_data is moved from running_spans to diff --git a/ext/src/zpages/tracez_processor.cc b/ext/src/zpages/tracez_processor.cc index 779f6fd061..1f88884a5f 100644 --- a/ext/src/zpages/tracez_processor.cc +++ b/ext/src/zpages/tracez_processor.cc @@ -6,7 +6,8 @@ namespace ext namespace zpages { -void TracezSpanProcessor::OnStart(opentelemetry::sdk::trace::Recordable &span) noexcept +void TracezSpanProcessor::OnStart(opentelemetry::sdk::trace::Recordable &span, + const opentelemetry::trace::SpanContext &parent_context) noexcept { std::lock_guard lock(mtx_); spans_.running.insert(static_cast(&span)); diff --git a/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h b/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h index b410ee16af..00ed986873 100644 --- a/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h +++ b/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h @@ -52,8 +52,11 @@ class BatchSpanProcessor : public SpanProcessor * NOTE: This method is a no-op. * * @param span - The span that just started + * @param parent_context - The parent context of the span that just started */ - void OnStart(Recordable &span) noexcept override; + void OnStart(Recordable &span, + const opentelemetry::trace::SpanContext &parent_context = + opentelemetry::trace::SpanContext::GetInvalid()) noexcept override; /** * Called when a span ends. diff --git a/sdk/include/opentelemetry/sdk/trace/processor.h b/sdk/include/opentelemetry/sdk/trace/processor.h index f1ef6ca6d0..676ccf01ed 100644 --- a/sdk/include/opentelemetry/sdk/trace/processor.h +++ b/sdk/include/opentelemetry/sdk/trace/processor.h @@ -32,8 +32,11 @@ class SpanProcessor /** * OnStart is called when a span is started. * @param span a recordable for a span that was just started + * @param parent_context The parent context of the span that just started */ - virtual void OnStart(Recordable &span) noexcept = 0; + virtual void OnStart(Recordable &span, + const opentelemetry::trace::SpanContext &parent_context = + opentelemetry::trace::SpanContext::GetInvalid()) noexcept = 0; /** * OnEnd is called when a span is ended. diff --git a/sdk/include/opentelemetry/sdk/trace/simple_processor.h b/sdk/include/opentelemetry/sdk/trace/simple_processor.h index 739c541866..f0ea1b56ba 100644 --- a/sdk/include/opentelemetry/sdk/trace/simple_processor.h +++ b/sdk/include/opentelemetry/sdk/trace/simple_processor.h @@ -37,7 +37,10 @@ class SimpleSpanProcessor : public SpanProcessor return exporter_->MakeRecordable(); } - void OnStart(Recordable &span) noexcept override {} + void OnStart(Recordable &span, + const opentelemetry::trace::SpanContext &parent_context = + opentelemetry::trace::SpanContext::GetInvalid()) noexcept override + {} void OnEnd(std::unique_ptr &&span) noexcept override { diff --git a/sdk/src/trace/batch_span_processor.cc b/sdk/src/trace/batch_span_processor.cc index 84d45bc6aa..80b5c337e2 100644 --- a/sdk/src/trace/batch_span_processor.cc +++ b/sdk/src/trace/batch_span_processor.cc @@ -4,6 +4,7 @@ using opentelemetry::sdk::common::AtomicUniquePtr; using opentelemetry::sdk::common::CircularBuffer; using opentelemetry::sdk::common::CircularBufferRange; +using opentelemetry::trace::SpanContext; OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -27,7 +28,7 @@ std::unique_ptr BatchSpanProcessor::MakeRecordable() noexcept return exporter_->MakeRecordable(); } -void BatchSpanProcessor::OnStart(Recordable &) noexcept +void BatchSpanProcessor::OnStart(Recordable &, const SpanContext &) noexcept { // no-op } diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 1edf6d14fa..bcadef775d 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -110,7 +110,7 @@ Span::Span(std::shared_ptr &&tracer, recordable_->SetStartTime(NowOr(options.start_system_time)); start_steady_time = NowOr(options.start_steady_time); // recordable_->SetResource(resource_); TODO - processor_->OnStart(*recordable_); + processor_->OnStart(*recordable_, parent_span_context); } Span::~Span() From bd581eebdca9bfca7c5443d567af7f2bfb1cb062 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 2 Feb 2021 20:48:41 +0530 Subject: [PATCH 2/2] fix review comments --- ext/include/opentelemetry/ext/zpages/tracez_processor.h | 3 +-- sdk/include/opentelemetry/sdk/trace/batch_span_processor.h | 3 +-- sdk/include/opentelemetry/sdk/trace/processor.h | 3 +-- sdk/include/opentelemetry/sdk/trace/simple_processor.h | 3 +-- sdk/test/trace/simple_processor_test.cc | 3 ++- 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/ext/include/opentelemetry/ext/zpages/tracez_processor.h b/ext/include/opentelemetry/ext/zpages/tracez_processor.h index 3fb8db03b8..d0c8692a8c 100644 --- a/ext/include/opentelemetry/ext/zpages/tracez_processor.h +++ b/ext/include/opentelemetry/ext/zpages/tracez_processor.h @@ -49,8 +49,7 @@ class TracezSpanProcessor : public opentelemetry::sdk::trace::SpanProcessor * @param span a recordable for a span that was just started */ void OnStart(opentelemetry::sdk::trace::Recordable &span, - const opentelemetry::trace::SpanContext &parent_context = - opentelemetry::trace::SpanContext::GetInvalid()) noexcept override; + const opentelemetry::trace::SpanContext &parent_context) noexcept override; /* * OnEnd is called when a span ends; that span_data is moved from running_spans to diff --git a/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h b/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h index 00ed986873..78bff416ed 100644 --- a/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h +++ b/sdk/include/opentelemetry/sdk/trace/batch_span_processor.h @@ -55,8 +55,7 @@ class BatchSpanProcessor : public SpanProcessor * @param parent_context - The parent context of the span that just started */ void OnStart(Recordable &span, - const opentelemetry::trace::SpanContext &parent_context = - opentelemetry::trace::SpanContext::GetInvalid()) noexcept override; + const opentelemetry::trace::SpanContext &parent_context) noexcept override; /** * Called when a span ends. diff --git a/sdk/include/opentelemetry/sdk/trace/processor.h b/sdk/include/opentelemetry/sdk/trace/processor.h index 676ccf01ed..e46cc6ac9c 100644 --- a/sdk/include/opentelemetry/sdk/trace/processor.h +++ b/sdk/include/opentelemetry/sdk/trace/processor.h @@ -35,8 +35,7 @@ class SpanProcessor * @param parent_context The parent context of the span that just started */ virtual void OnStart(Recordable &span, - const opentelemetry::trace::SpanContext &parent_context = - opentelemetry::trace::SpanContext::GetInvalid()) noexcept = 0; + const opentelemetry::trace::SpanContext &parent_context) noexcept = 0; /** * OnEnd is called when a span is ended. diff --git a/sdk/include/opentelemetry/sdk/trace/simple_processor.h b/sdk/include/opentelemetry/sdk/trace/simple_processor.h index f0ea1b56ba..92612ae800 100644 --- a/sdk/include/opentelemetry/sdk/trace/simple_processor.h +++ b/sdk/include/opentelemetry/sdk/trace/simple_processor.h @@ -38,8 +38,7 @@ class SimpleSpanProcessor : public SpanProcessor } void OnStart(Recordable &span, - const opentelemetry::trace::SpanContext &parent_context = - opentelemetry::trace::SpanContext::GetInvalid()) noexcept override + const opentelemetry::trace::SpanContext &parent_context) noexcept override {} void OnEnd(std::unique_ptr &&span) noexcept override diff --git a/sdk/test/trace/simple_processor_test.cc b/sdk/test/trace/simple_processor_test.cc index cdf544e79c..0e86ac2471 100644 --- a/sdk/test/trace/simple_processor_test.cc +++ b/sdk/test/trace/simple_processor_test.cc @@ -9,6 +9,7 @@ using namespace opentelemetry::sdk::trace; using opentelemetry::exporter::memory::InMemorySpanData; using opentelemetry::exporter::memory::InMemorySpanExporter; +using opentelemetry::trace::SpanContext; TEST(SimpleProcessor, ToInMemorySpanExporter) { @@ -18,7 +19,7 @@ TEST(SimpleProcessor, ToInMemorySpanExporter) auto recordable = processor.MakeRecordable(); - processor.OnStart(*recordable); + processor.OnStart(*recordable, SpanContext::GetInvalid()); ASSERT_EQ(0, span_data->GetSpans().size());