-
Notifications
You must be signed in to change notification settings - Fork 449
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
Add functionality to explicitely specify a span parent #349
Changes from 6 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,8 +43,13 @@ struct StartSpanOptions | |
core::SystemTimestamp start_system_time; | ||
core::SteadyTimestamp start_steady_time; | ||
|
||
// Explicitely set the parent of a Span. | ||
// | ||
// This defaults to an invalid span context. In this case, the Span is | ||
// automatically parented to the currently active span. | ||
SpanContext parent = SpanContext::GetInvalid(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wondering if it would be more optimized to have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be more efficient if we'd return a pointer, but as we return by value here this involves a copy anyway, and we wouldn't gain much by having a static singleton. |
||
|
||
// TODO: | ||
// Span(Context?) parent; | ||
// SpanContext remote_parent; | ||
// Links | ||
SpanKind kind = SpanKind::kInternal; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,10 +33,6 @@ namespace trace_api = opentelemetry::trace; | |
class SpanContext final | ||
{ | ||
public: | ||
// An invalid SpanContext. | ||
SpanContext() noexcept | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explicit delete as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call, I made it explicit. |
||
: trace_flags_(trace::TraceFlags((uint8_t) false)), remote_parent_(false){}; | ||
|
||
/* A temporary constructor for an invalid SpanContext. | ||
* Trace id and span id are set to invalid (all zeros). | ||
* | ||
|
@@ -71,31 +67,9 @@ class SpanContext final | |
remote_parent_(has_remote_parent) | ||
{} | ||
|
||
SpanContext(SpanContext &&ctx) | ||
: trace_id_(ctx.trace_id()), span_id_(ctx.span_id()), trace_flags_(ctx.trace_flags()) | ||
{} | ||
SpanContext(const SpanContext &ctx) = default; | ||
|
||
SpanContext(const SpanContext &ctx) | ||
: trace_id_(ctx.trace_id()), span_id_(ctx.span_id()), trace_flags_(ctx.trace_flags()) | ||
{} | ||
// | ||
// SpanContext &operator=(const SpanContext &ctx) | ||
// { | ||
// SpanContext *spn_ctx = | ||
// new SpanContext(ctx.trace_id(), ctx.span_id(), ctx.trace_flags(), | ||
// ctx.HasRemoteParent()); | ||
// this = spn_ctx; | ||
// return *this; | ||
// }; | ||
// | ||
// SpanContext &operator=(SpanContext &&ctx) | ||
// { | ||
// SpanContext *spn_ctx = | ||
// new SpanContext(ctx.trace_id(), ctx.span_id(), ctx.trace_flags(), | ||
// ctx.HasRemoteParent()); | ||
// this = spn_ctx; | ||
// return *this; | ||
// }; | ||
SpanContext &operator=(const SpanContext &ctx) = default; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Span context should be immutable as per specs. Just wondering if we need to have assignment operator ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having an assignment operator makes it easier and more efficient to specify a parent context in the trace_api::StartSpanOptions options;
options.parent = span_first->GetContext(); Without an assignment operator, we'd need to resort to a pointer (a heap allocated The |
||
|
||
bool operator==(const SpanContext &that) const noexcept | ||
{ | ||
|
@@ -110,10 +84,10 @@ class SpanContext final | |
bool IsSampled() const noexcept { return trace_flags_.IsSampled(); } | ||
|
||
private: | ||
const trace_api::TraceId trace_id_; | ||
const trace_api::SpanId span_id_; | ||
const trace_api::TraceFlags trace_flags_; | ||
const bool remote_parent_ = false; | ||
trace_api::TraceId trace_id_; | ||
trace_api::SpanId span_id_; | ||
trace_api::TraceFlags trace_flags_; | ||
bool remote_parent_ = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: We can bring back const-ness if we delete assignment operator ? |
||
}; | ||
} // namespace trace | ||
OPENTELEMETRY_END_NAMESPACE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defaults to invalid value may look a little weird, would
GetEmpty()
be a better name?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about that, but then decided against introducing an empty span context. In the current terminology, a span context can either be valid or invalid (it has an
IsValid
method). SoSpanContext::GetInvalid()::IsValid() == true
I think is more idiomatic thanSpanContext::GetEmpty()::IsValid() == true
. And here, an invalid span context is used like a null pointer (indicating that no parent span context is set).But I don't have a very strong opinion on that, I'd be willing to go with
GetEmpty()
if folks feel that's clearer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I too don't have strong opinion on this, although having two different methods
GetEmpty()
andGetInvalid()
returning invalid span context is more confusing to me.