-
Notifications
You must be signed in to change notification settings - Fork 451
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
Added Http Trace Context #143
Added Http Trace Context #143
Conversation
Codecov Report
@@ Coverage Diff @@
## master #143 +/- ##
==========================================
+ Coverage 94.43% 94.55% +0.11%
==========================================
Files 146 146
Lines 6597 6610 +13
==========================================
+ Hits 6230 6250 +20
+ Misses 367 360 -7
|
.gitignore
Outdated
@@ -34,3 +34,8 @@ | |||
|
|||
# Bazel files | |||
/bazel-* | |||
/.idea/ |
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.
This seems to be IDE specific files, would you put them in a separate section (and put a comment)?
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.
Yes, I'll do that right away. Actually, do you mind to see the other PR I've made sometime before?
It contains the header I'd like to merge into while this PR is more about consulting about some of the coding details.
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.
Why are the lines below needed? Isn't the whole .idea subdir ignored?
Also I'm not sure this belongs in the .gitignore file at all. I'd like to avoid e.g. every single IDE/editor being covered here.
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.
They should have been removed by now.
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.
Do you still plan to keep this line?
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've commited those changes to remove it.
.gitignore
Outdated
@@ -34,3 +34,8 @@ | |||
|
|||
# Bazel files | |||
/bazel-* | |||
/.idea/ |
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.
Why are the lines below needed? Isn't the whole .idea subdir ignored?
Also I'm not sure this belongs in the .gitignore file at all. I'd like to avoid e.g. every single IDE/editor being covered here.
api/include/opentelemetry/trace/propagation/HttpTraceContext.cc
Outdated
Show resolved
Hide resolved
api/include/opentelemetry/trace/propagation/HttpTraceContext.cc
Outdated
Show resolved
Hide resolved
Okay, so from today's meeting, I learned that I have to separate the code I made now into api and sdk folders. Could anyone specify more which should be in api and which should be in sdks? |
api/include/opentelemetry/trace/propagation/HttpTraceContext.cc
Outdated
Show resolved
Hide resolved
api/include/opentelemetry/trace/propagation/HttpTraceContext.cc
Outdated
Show resolved
Hide resolved
api/include/opentelemetry/trace/propagation/HttpTraceContext.cc
Outdated
Show resolved
Hide resolved
api/include/opentelemetry/trace/propagation/HttpTraceContext.cc
Outdated
Show resolved
Hide resolved
api/include/opentelemetry/trace/propagation/http_trace_context.h
Outdated
Show resolved
Hide resolved
api/include/opentelemetry/trace/propagation/http_trace_context.h
Outdated
Show resolved
Hide resolved
api/include/opentelemetry/trace/propagation/http_trace_context.h
Outdated
Show resolved
Hide resolved
api/include/opentelemetry/trace/propagation/http_trace_context.h
Outdated
Show resolved
Hide resolved
api/include/opentelemetry/propagators/composite_http_propagator.h
Outdated
Show resolved
Hide resolved
Origin/propagators
…propagators # Conflicts: # api/include/opentelemetry/trace/propagation/http_trace_context.h
Origin/propagators
} | ||
} | ||
|
||
static void GenerateBuffer(nostd::string_view string, int bytes, uint8_t *buf) |
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.
Where is the buffer limit? Consider adding comment to this function and explain what's the intended behavior.
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.
Added function comments
} | ||
} | ||
|
||
static void GenerateBuffer(nostd::string_view string, int bytes, uint8_t *buf) |
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.
The name GenerateBuffer
is misleading.
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.
Changed name to GenerateHexFromString
sdk/src/trace/span.h
Outdated
@@ -53,6 +53,7 @@ class Span final : public trace_api::Span | |||
mutable std::mutex mu_; | |||
std::unique_ptr<Recordable> recordable_; | |||
opentelemetry::core::SteadyTimestamp start_steady_time; | |||
std::shared_ptr<trace_api::SpanContext> span_context_; |
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.
Not sure if I am missing something, but how is SpanContext
going to be initialized. Don't see this passed in constructor.
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.
Also, see whether it need to be unique_ptr - ideally Span
should fully own it's context. <shared_ptr> have performance impact so should be avoided unless we can't.
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.
Changed to unique ptr
namespace trace | ||
{ | ||
class DefaultSpan : public Span | ||
{ |
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.
nitpik: Can we use override
keyword for the function which are virtually defined in Span
base class. Will make this class more readable.
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 just did it.
*/ | ||
nostd::unique_ptr<Span> StartSpan(nostd::string_view name, | ||
const KeyValueIterable &attributes, | ||
const StartSpanOptions &options = {}) 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.
nitpik: override this, and below two functions.
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.
Same as above
|
||
void SetToken(nostd::unique_ptr<context::Token> && /* token */) noexcept override {} | ||
|
||
private: | ||
std::shared_ptr<Tracer> tracer_; | ||
SpanContext span_context_; |
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.
how is this being initialized? should it be in constructor ?
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.
This is just a placeholder to conform to its parent class Span, I don't think it's being used.
return context.SetValue(span_key, sp); | ||
} | ||
|
||
static void GetCurrentSpan(const context::Context &context, SpanContext &span_context) |
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.
should this have public access ?
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.
Yes because it can be used elsewhere and so it is public in Python version I believe
setter(carrier, kTraceParent, hex_string); | ||
} | ||
|
||
static void InjectImpl(Setter setter, T &carrier, const SpanContext &span_context) |
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.
should this have public access ? please check this for all the member functions.
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 think all is cool except for the GenerateHexFromString, the rest are useful because they are useful functions outside of this class as well and they also need tests to make sure they are correct, although I have changed the GenerateHexFromString to private.
static const nostd::string_view kTraceParent = "traceparent"; | ||
static const nostd::string_view kTraceState = "tracestate"; | ||
static const int kTraceDelimiterBytes = 3; | ||
static const int kHeaderElementLengths[4] = {2, 32, 16, 2}; |
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.
This is confusing now. It's important to know what these numbers indicate - which is getting missed now. Better to have constants as defined earlier, and use them within kHeaderElementLengths
array. Also, size of trace_id is 16 bytes, and span_id is 8 bytes. Why are we using 32 bytes and 16 bytes here ?
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 just followed a recommendation to remove the definitions and convert them into this form though. I could provide comments on the size to bolster understanding.
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.
Assuming you're referring to #143 (comment), there wasn't a recommendation to remove the definitions. reyang pointed out that the numbers are repeated, but didn't say "get rid of the constants".
I agree with lalitb: the constants give useful mnemonics to the values.
Regarding why the values are {2,32,16,2} - these are characters in a hex string, which encode nibbles not bytes. The count is 2:1 with the byte size.
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.
So I just added those constants back but this time with those constants using the values stored in kHeadeElementLengths as definition.
}; | ||
} // namespace propagation | ||
} // 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.
nit: put a blank line before EOF (and change the other files).
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.
Fixed and just pushed
{ | ||
static const nostd::string_view kTraceParent = "traceparent"; | ||
static const nostd::string_view kTraceState = "tracestate"; | ||
static const int kTraceDelimiterBytes = 3; |
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.
Why do we need this? Should this be the number of components - 1?
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.
Yes right now it is the number of componets - 1, but this variable is used to calculate the length of a trace parent hence I think it might make more sense to refer to it as a length unit.
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.
LGTM, left some minor suggestions.
This PR is has the full implemented version of Http Text Format i.e. Http Trace Context without the Trace State. All Trace State related code are commented out for the sake of compilation.
Modification is made to span.h to remove tracer field from class Span because otherwise Span and Tracer would define upon each other.