Add functionality to explicitely specify a span parent#349
Conversation
| { | ||
| public: | ||
| // An invalid SpanContext. | ||
| SpanContext() noexcept |
There was a problem hiding this comment.
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.
Explicit delete as SpanContext() = delete;?
There was a problem hiding this comment.
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.
Removing the const enables us to use default (and hopefully optimized) copy constructors and assignment operators.
There was a problem hiding this comment.
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.
Defaults to invalid value may look a little weird, would GetEmpty() be a better name?
There was a problem hiding this comment.
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.
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.
Span context should be immutable as per specs. Just wondering if we need to have assignment operator ?
There was a problem hiding this comment.
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.
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.
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.
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.
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.
Update dependency civetweb to v1.16.bcr.2
This PR extends the
StartSpanOptionsstruct by aparentSpanContext. 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
SpanContextimplementation.Closes #318.