-
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
Conversation
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use SpanContext::GetInvalid()
as the default way to create an invalid SpanContext
. Having both SpanContext()
and SpanContext::GetInvalid()
returning an invalid SpanContext
is somewhat confusing.
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.
Explicit delete as SpanContext() = delete;
?
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.
Good call, I made it explicit.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the const
enables us to use default (and hopefully optimized) copy constructors and assignment operators.
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.
nit: We can bring back const-ness if we delete assignment operator ? const
varaibles have its own level of optimization
Codecov Report
@@ Coverage Diff @@
## master #349 +/- ##
==========================================
+ Coverage 94.71% 94.73% +0.01%
==========================================
Files 154 154
Lines 6847 6871 +24
==========================================
+ Hits 6485 6509 +24
Misses 362 362
|
// | ||
// 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 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). So SpanContext::GetInvalid()::IsValid() == true
I think is more idiomatic than SpanContext::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()
and GetInvalid()
returning invalid span context is more confusing to me.
// this = spn_ctx; | ||
// return *this; | ||
// }; | ||
SpanContext &operator=(const SpanContext &ctx) = default; |
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.
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 comment
The 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 StartSpanOptions
struct:
trace_api::StartSpanOptions options;
options.parent = span_first->GetContext();
Without an assignment operator, we'd need to resort to a pointer (a heap allocated SpanContext
object), which is more inefficient (as it requires a heap allocation/deallocation).
The SpanContext
is immutable in the sense, that it has no setters (span id, trace id and flags cannot be changed independently of each other), and the SpanContext
assigned to a Span
cannot change either.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
nit: We can bring back const-ness if we delete assignment operator ? const
varaibles have its own level of optimization
// | ||
// 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 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()
and GetInvalid()
returning invalid span context is more confusing to me.
// | ||
// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering if it would be more optimized to have SpanContext::GetInvalid()
method returning a static instance of invalid context ( using c++11 local atomic static ). Although, Can be part of separate PR.
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.
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.
This PR extends the
StartSpanOptions
struct by aparent
SpanContext. If this is given, it will be used as a parent for a given span.While I was at it, I cleaned up some things in the
SpanContext
implementation.Closes #318.