diff --git a/brave/src/main/java/brave/propagation/SamplingFlags.java b/brave/src/main/java/brave/propagation/SamplingFlags.java index bffef2a3a0..6944694d53 100644 --- a/brave/src/main/java/brave/propagation/SamplingFlags.java +++ b/brave/src/main/java/brave/propagation/SamplingFlags.java @@ -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() { @@ -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; diff --git a/brave/src/test/java/brave/propagation/SamplingFlagsTest.java b/brave/src/test/java/brave/propagation/SamplingFlagsTest.java index 86ffd7f7c8..5ba3a7b78c 100644 --- a/brave/src/test/java/brave/propagation/SamplingFlagsTest.java +++ b/brave/src/test/java/brave/propagation/SamplingFlagsTest.java @@ -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(); } @@ -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(); + } }