Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing parent context to SpanProcessor::OnStart() #552

Merged
merged 5 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 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,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
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for having a default value here? According to the spec this parameter is required, so I think we shouldn't make it easy to omit it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes right, it should be required parameter. I have modified the function prototype accordingly.


/**
* Called when a span ends.
Expand Down
5 changes: 4 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,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.
Expand Down
5 changes: 4 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,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<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