Skip to content

Commit

Permalink
Passing parent context to SpanProcessor::OnStart() (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Feb 3, 2021
1 parent 92f0533 commit 74ad7b1
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion ext/include/opentelemetry/ext/zpages/tracez_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ 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) noexcept override;

/*
* OnEnd is called when a span ends; that span_data is moved from running_spans to
Expand Down
3 changes: 2 additions & 1 deletion ext/src/zpages/tracez_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> lock(mtx_);
spans_.running.insert(static_cast<ThreadsafeSpanData *>(&span));
Expand Down
4 changes: 3 additions & 1 deletion sdk/include/opentelemetry/sdk/trace/batch_span_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ 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) noexcept override;

/**
* Called when a span ends.
Expand Down
4 changes: 3 additions & 1 deletion sdk/include/opentelemetry/sdk/trace/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ 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) noexcept = 0;

/**
* OnEnd is called when a span is ended.
Expand Down
4 changes: 3 additions & 1 deletion sdk/include/opentelemetry/sdk/trace/simple_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class SimpleSpanProcessor : public SpanProcessor
return exporter_->MakeRecordable();
}

void OnStart(Recordable &span) noexcept override {}
void OnStart(Recordable &span,
const opentelemetry::trace::SpanContext &parent_context) noexcept override
{}

void OnEnd(std::unique_ptr<Recordable> &&span) noexcept override
{
Expand Down
3 changes: 2 additions & 1 deletion sdk/src/trace/batch_span_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,7 +26,7 @@ std::unique_ptr<Recordable> BatchSpanProcessor::MakeRecordable() noexcept
return exporter_->MakeRecordable();
}

void BatchSpanProcessor::OnStart(Recordable &) noexcept
void BatchSpanProcessor::OnStart(Recordable &, const SpanContext &) noexcept
{
// no-op
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/trace/span.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Span::Span(std::shared_ptr<Tracer> &&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()
Expand Down
3 changes: 2 additions & 1 deletion sdk/test/trace/simple_processor_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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());

Expand Down

0 comments on commit 74ad7b1

Please sign in to comment.