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

Fix B3 propagator and add tests #882

Merged
merged 38 commits into from
Jul 7, 2020

Conversation

MrAlias
Copy link
Contributor

@MrAlias MrAlias commented Jul 1, 2020

The existing implementation of the B3 propagator does not fully implement the HTTP B3 specification. This changes the propagator to closer match the specification. The remaining non-compliance issue is the lack of injecting ParentSpanID to outgoing requests.

Fixed

  • The B3 propagator now correctly supports sampling only values (b3: 0, b3: 1, or b3: d) for a Single B3 Header.
  • The B3 propagator now propagates the debug flag. This removes the behavior of changing the debug flag into a set sampling bit. Instead, this now follow the B3 specification and omits the X-B3-Sampling header.
  • The B3 propagator now tracks "unset" sampling state (meaning "defer the decision") and does not set the X-B3-Sampling header when injecting.

Added

  • The B3Encoding type to represent the B3 encoding(s) the B3 propagator can inject. A value for HTTP supported encodings (Multiple Header: MultipleHeader, Single Header: SingleHeader) are included.
  • The FlagsDeferred trace flag to indicate if the trace sampling decision has been deferred.
  • The FlagsDebug trace flag to indicate if the trace is a debug trace.

Removed

  • The FlagsUnused trace flag is removed. The purpose of this flag was to act as the inverse of FlagsSampled, the inverse of FlagsSampled is used instead.

Changed

  • The B3 propagator SingleHeader field has been replaced with InjectEncoding. This new field can be set to combinations of the B3Encoding bitmasks and will inject trace information in these encodings. If no encoding is set, the propagator will default to MultipleHeader encoding.
  • The B3 propagator now extracts from either HTTP encoding of B3 (Single Header or Multiple Header) based on what is contained in the header. Preference is given to Single Header encoding with Multiple Header being the fallback if Single Header is not found or is invalid. This behavior change is made to dynamically support all correctly encoded traces received instead of having to guess the expected encoding prior to receiving.

References:

@MrAlias MrAlias added pkg:testing Related to testing or a testing package area:propagators Part of OpenTelemetry context propagation labels Jul 1, 2020
@MrAlias MrAlias self-assigned this Jul 1, 2020
@MrAlias MrAlias marked this pull request as draft July 1, 2020 01:41
CHANGELOG.md Outdated Show resolved Hide resolved
api/trace/b3_propagator.go Outdated Show resolved Hide resolved
api/trace/b3_propagator.go Outdated Show resolved Hide resolved
api/trace/b3_propagator.go Outdated Show resolved Hide resolved
api/trace/b3_propagator.go Show resolved Hide resolved
api/trace/b3_propagator_integration_test.go Outdated Show resolved Hide resolved
MrAlias and others added 14 commits July 1, 2020 10:20
Add a new "not sampled" mask to complement the existing "sampled" one.

Rename `FlagsUnused` to `FlagsUnset`.

Add documentation for each of the flags to help understand their
purpose.
The B3 specification states "Debug is encoded as `X-B3-Flags: 1`. Absent
or any other values can be ignored", so testing of other values should
not result in an error.
Remove test cases that would fail if the fallback header format was
expected to not be used.
Add the B3Encoding and valid HTTP based values. Change the B3 propagator
to use these bitmask fields to specify the inject encoding it will
propagate.
Add a FlagsDebug and FlagsDeferred to track the B3 trace state.

Add helper methods to the SpanContext to check the debug and deferred
bit of the trace flags.

Update SpanContext.IsSampled to return if the sampling decision is to
sample rather than if the sample bit is set. This means that if the
debug bit is also set it will return true.
@MrAlias MrAlias marked this pull request as ready for review July 2, 2020 16:51
@MrAlias MrAlias added the pkg:API Related to an API package label Jul 2, 2020
This check makes sample only headers not propagate.
Use the passed SpanContext and check directly the span ID.
Run update checked SpanID to match sent.

Add tests to validate sample only transmissions and debug flag support.
This is no longer the parent.
api/trace/b3_propagator.go Outdated Show resolved Hide resolved
api/trace/b3_propagator.go Outdated Show resolved Hide resolved
api/trace/span_context_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@jmacd jmacd left a comment

Choose a reason for hiding this comment

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

Thanks.

The B3SingleHeader name will conflict with the upcoming change to prefix
the SingleHeader encoding with "B3". There are a few options to address
this conflict, but in the end we do not need to be exporting these
values. They are duplicates of the OpenZipkin package and users should
use those.
Include a `B3` prefix to scope the encoding names.

Move the related support method to the B3Encoding itself, instead of the
B3 propagator.

Add tests to provide a sanity check for encoding bitmasks.
Update test name to better describe how unused bits have no affect on
the sampling decision. Include the inverse of this test as well: not
sampled but has unused bits.
api/trace/b3_propagator.go Outdated Show resolved Hide resolved
@MrAlias MrAlias merged commit c506e99 into open-telemetry:master Jul 7, 2020
@MrAlias MrAlias deleted the b3-header-tests branch July 7, 2020 23:38
@MrAlias MrAlias mentioned this pull request Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:propagators Part of OpenTelemetry context propagation pkg:API Related to an API package pkg:testing Related to testing or a testing package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants