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

Added Http Trace Context #143

Merged
merged 944 commits into from
Aug 26, 2020

Conversation

Tianlin-Zhao
Copy link
Contributor

@Tianlin-Zhao Tianlin-Zhao commented Jun 30, 2020

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.

@Tianlin-Zhao Tianlin-Zhao requested a review from a team June 30, 2020 21:43
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jun 30, 2020

CLA Check
The committers are authorized under a signed CLA.

@codecov
Copy link

codecov bot commented Jun 30, 2020

Codecov Report

Merging #143 into master will increase coverage by 0.11%.
The diff coverage is 94.73%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
api/include/opentelemetry/trace/span.h 100.00% <ø> (ø)
sdk/src/trace/span.h 0.00% <0.00%> (ø)
api/include/opentelemetry/trace/noop.h 85.18% <100.00%> (+25.92%) ⬆️
api/include/opentelemetry/trace/span_context.h 100.00% <100.00%> (ø)
api/test/trace/noop_test.cc 100.00% <100.00%> (ø)
sdk/test/trace/span_data_test.cc 100.00% <0.00%> (ø)

.gitignore Outdated
@@ -34,3 +34,8 @@

# Bazel files
/bazel-*
/.idea/
Copy link
Member

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)?

Copy link
Contributor Author

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?

#129

It contains the header I'd like to merge into while this PR is more about consulting about some of the coding details.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

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?

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/
Copy link
Contributor

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/default_span.cc Outdated Show resolved Hide resolved
@Tianlin-Zhao
Copy link
Contributor Author

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/default_span.h Outdated Show resolved Hide resolved
api/include/opentelemetry/trace/default_span.h Outdated Show resolved Hide resolved
api/include/opentelemetry/trace/trace_id.h Outdated Show resolved Hide resolved
api/include/opentelemetry/trace/trace_state.h Outdated Show resolved Hide resolved
api/test/trace/propagation/httptextformat_test.cc Outdated Show resolved Hide resolved
api/test/trace/propagation/httptextformat_test.cc Outdated Show resolved Hide resolved
@0x4b 0x4b mentioned this pull request Jul 10, 2020
api/test/trace/propagation/http_text_format_test.cc Outdated Show resolved Hide resolved
api/test/trace/propagation/http_text_format_test.cc Outdated Show resolved Hide resolved
api/test/trace/propagation/http_text_format_test.cc Outdated Show resolved Hide resolved
api/test/trace/propagation/http_text_format_test.cc Outdated Show resolved Hide resolved
api/test/trace/propagation/http_text_format_test.cc Outdated Show resolved Hide resolved
}
}

static void GenerateBuffer(nostd::string_view string, int bytes, uint8_t *buf)
Copy link
Member

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.

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)
Copy link
Member

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.

Choose a reason for hiding this comment

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

Changed name to GenerateHexFromString

@@ -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_;
Copy link
Member

@lalitb lalitb Aug 25, 2020

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.

Copy link
Member

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.

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
{
Copy link
Member

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.

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
Copy link
Member

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.

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_;
Copy link
Member

@lalitb lalitb Aug 25, 2020

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 ?

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)
Copy link
Member

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 ?

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)
Copy link
Member

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.

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};
Copy link
Member

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 ?

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.

Copy link

@0x4b 0x4b Aug 25, 2020

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.

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
Copy link
Member

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).

Copy link

@ZhaoTianlin990121 ZhaoTianlin990121 Aug 25, 2020

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;
Copy link
Member

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?

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.

Copy link
Member

@reyang reyang left a 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.

@reyang reyang added the pr:please-merge This PR is ready to be merged by a Maintainer (rebased, CI passed, has enough valid approvals, etc.) label Aug 25, 2020
@reyang reyang merged commit 09983ab into open-telemetry:master Aug 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:please-merge This PR is ready to be merged by a Maintainer (rebased, CI passed, has enough valid approvals, etc.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants