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

Fixes bug where debug did not imply sampled #663

Merged
merged 1 commit into from
Mar 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions brave-tests/src/test/java/brave/propagation/B3PropagationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,16 @@ public class B3PropagationTest extends PropagationTest<String> {
assertThat(result)
.isEqualTo(SamplingFlags.EMPTY);
}

@Test public void extractTraceContext_debug_with_ids() {
MapEntry mapEntry = new MapEntry();
map.put("X-B3-TraceId", "463ac35c9f6413ad48485a3953bb6124"); // ok
map.put("X-B3-SpanId", "48485a3953bb6124"); // ok
map.put("X-B3-Flags", "1"); // accidentally missing sampled flag

TraceContext result = propagation().extractor(mapEntry).extract(map).context();

assertThat(result.sampled())
.isTrue();
}
}
3 changes: 3 additions & 0 deletions brave/src/main/java/brave/propagation/TraceIdContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,12 @@ InternalBuilder sampled(@Nullable Boolean sampled) {
return this;
}

/** Ensures sampled is set when debug is */
InternalBuilder debug(boolean debug) {
if (debug) {
flags |= FLAG_DEBUG;
flags |= FLAG_SAMPLED_SET;
flags |= FLAG_SAMPLED;
} else {
flags &= ~FLAG_DEBUG;
}
Expand Down
14 changes: 14 additions & 0 deletions brave/src/test/java/brave/propagation/TraceIdContextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ public class TraceIdContextTest {
.isEqualTo("00000000000000de000000000000014d");
}

@Test public void debugImpliesSampled() {
TraceIdContext primitives = context.toBuilder()
.debug(true)
.build();

TraceIdContext objects = context.toBuilder()
.sampled(Boolean.TRUE)
.debug(Boolean.TRUE)
.build();

assertThat(primitives)
.isEqualToComparingFieldByField(objects);
}

@Test public void canUsePrimitiveOverloads() {
TraceIdContext primitives = context.toBuilder()
.sampled(true)
Expand Down