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 issue #661 - debug trace not sampled #662

Closed
Closed
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
6 changes: 5 additions & 1 deletion brave/src/main/java/brave/propagation/SamplingFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static final class SamplingFlagsImpl extends SamplingFlags {
}

@Override public Boolean sampled() {
return sampled;
return debug ? Boolean.TRUE : sampled;
}

@Override public boolean debug() {
Expand All @@ -81,6 +81,10 @@ static final class SamplingFlagsImpl extends SamplingFlags {
static final int FLAG_DEBUG = 1 << 3;

static Boolean sampled(int flags) {

// FLAG_DEBUG implies sampled
if ((flags & FLAG_DEBUG) == FLAG_DEBUG) return true;

return (flags & FLAG_SAMPLED_SET) == FLAG_SAMPLED_SET
? (flags & FLAG_SAMPLED) == FLAG_SAMPLED
: null;
Expand Down
11 changes: 9 additions & 2 deletions brave/src/test/java/brave/propagation/SamplingFlagsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ public class SamplingFlagsTest {
}

@Test public void debugImpliesSampled() {
SamplingFlags flags = new SamplingFlags.Builder().debug(true).build();
SamplingFlags flags = new SamplingFlags.SamplingFlagsImpl(null, true);

assertThat(flags).isSameAs(SamplingFlags.DEBUG);
assertThat(flags.sampled()).isTrue();
assertThat(flags.debug()).isTrue();
}
Expand All @@ -41,4 +40,12 @@ public class SamplingFlagsTest {
assertThat(flags.sampled()).isFalse();
assertThat(flags.debug()).isFalse();
}

@Test public void sampledFlags() {
assertThat(SamplingFlags.sampled(0)).isNull();
assertThat(SamplingFlags.sampled(SamplingFlags.FLAG_SAMPLED)).isNull();
assertThat(SamplingFlags.sampled(SamplingFlags.FLAG_SAMPLED_SET)).isFalse();
assertThat(SamplingFlags.sampled(SamplingFlags.FLAG_SAMPLED | SamplingFlags.FLAG_SAMPLED_SET)).isTrue();
assertThat(SamplingFlags.sampled(SamplingFlags.FLAG_DEBUG)).isTrue();
}
}