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

Simplify propagators #608

Merged
merged 9 commits into from
Mar 18, 2021
Merged

Conversation

seemk
Copy link
Contributor

@seemk seemk commented Mar 12, 2021

Changes

  • Remove code duplication (make hex string related stuff use methods in detail namespace)
  • Clean up headers
  • Remove use of cout (should not pollute stdout, some programs send their data over it).
  • Add missing b3 propagator to Bazel tests.

I'd also like to rename the propagator files for consistency:

  • propagation/b3_propagator.h -> propagation/b3.h
  • propagation/http_trace_context -> propagation/w3c.h
  • propagation/jaeger.h will stay as is

What do you think?

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@seemk seemk requested a review from a team March 12, 2021 20:23
@codecov
Copy link

codecov bot commented Mar 12, 2021

Codecov Report

Merging #608 (f8f17d2) into main (fdd6303) will increase coverage by 0.05%.
The diff coverage is 94.31%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #608      +/-   ##
==========================================
+ Coverage   94.45%   94.51%   +0.05%     
==========================================
  Files         197      197              
  Lines        9183     9101      -82     
==========================================
- Hits         8674     8602      -72     
+ Misses        509      499      -10     
Impacted Files Coverage Δ
...entelemetry/trace/propagation/http_trace_context.h 93.44% <90.90%> (+7.58%) ⬆️
...de/opentelemetry/trace/propagation/b3_propagator.h 96.49% <96.77%> (-1.24%) ⬇️
...clude/opentelemetry/trace/propagation/detail/hex.h 100.00% <100.00%> (ø)
api/test/trace/propagation/b3_propagation_test.cc 100.00% <100.00%> (ø)
...pi/test/trace/propagation/http_text_format_test.cc 100.00% <100.00%> (ø)


TraceFlags() noexcept : rep_{0} {}

explicit TraceFlags(uint8_t flags) noexcept : rep_(flags) {}

bool IsSampled() const noexcept { return rep_ & kIsSampled; }

bool IsValid() const noexcept { return rep_ != kForbidden; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is it specified that 0xff is an invalid value for trace state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah my bad, thanks! 0xFF was an invalid marker for the version not trace flags. Will fix in the morning, not at the computer atm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed - it now checks the version for 0xFF not trace flags 🤦

Comment on lines 131 to 132
TraceId trace_id = TraceIdFromHex(trace_id_hex);
SpanId span_id = SpanIdFromHex(span_id_hex);
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't test it, but it seems to me this wouldn't catch too short trace and span ids. Like when parsing a header 00-1-1-00.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added more checks and additional test cases for w3c propagation.

@@ -43,13 +43,13 @@ bool IsValidHex(nostd::string_view s)
*/
bool HexToBinary(nostd::string_view hex, uint8_t *buffer, size_t buffer_size)
{
std::memset(buffer, 0, buffer_size);
Copy link
Contributor

Choose a reason for hiding this comment

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

Also check the input hex is empty, as it cannot be handled in below code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is handled - nothing is written to the buffer if hex is empty.

Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for refactoring this.

@lalitb lalitb requested review from pyohannes and ThomsonTan March 17, 2021 08:54
@lalitb
Copy link
Member

lalitb commented Mar 18, 2021

quick validated these changes against w3c tracecontext tests (https://github.com/open-telemetry/opentelemetry-cpp/tree/main/ext/test/w3c_tracecontext_test), and don't see any new failure (other than existing trace-state failures). Will go ahead and merge them now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants