@Override public String toString() { return "SamplingFlags(sampled=" + sampled() + ", sampledLocal=" + sampledLocal() + ", debug=" + debug() + ")"; }
/** This ensures constants are always used, in order to reduce allocation overhead */ static SamplingFlags toSamplingFlags(int flags) { switch (flags) { case 0: return EMPTY; case FLAG_SAMPLED_SET: return NOT_SAMPLED; case FLAG_SAMPLED_SET | FLAG_SAMPLED: return SAMPLED; case FLAG_SAMPLED_SET | FLAG_SAMPLED | FLAG_DEBUG: return DEBUG; case FLAG_SAMPLED_LOCAL: return EMPTY_SAMPLED_LOCAL; case FLAG_SAMPLED_LOCAL | FLAG_SAMPLED_SET: return NOT_SAMPLED_SAMPLED_LOCAL; case FLAG_SAMPLED_LOCAL | FLAG_SAMPLED_SET | FLAG_SAMPLED: return SAMPLED_SAMPLED_LOCAL; case FLAG_SAMPLED_LOCAL | FLAG_SAMPLED_SET | FLAG_SAMPLED | FLAG_DEBUG: return DEBUG_SAMPLED_LOCAL; default: assert false; // programming error, but build anyway return new SamplingFlags(flags); } } }
public SamplingFlags build() { return toSamplingFlags(flags); } }
@Override public boolean isSampled(long traceId) { Boolean decision = sample(method).sampled(); return decision != null ? decision : false; } };
/** @see TraceIdContext#debug() */ public Builder debug(boolean debug) { flags = SamplingFlags.debug(debug, flags); return this; }
/** Returns {@link SamplingFlags#sampled()}, regardless of subtype. */ @Nullable public Boolean sampled() { return value.sampled(); }
/** * True implies {@link #sampled()}, and is additionally a request to override any storage or * collector layer sampling. Defaults to false. */ public final boolean debug() { return debug(flags); }
@Override public String toString() { return "SamplingFlags(sampled=" + sampled() + ", sampledLocal=" + sampledLocal() + ", debug=" + debug() + ")"; }
@Override public boolean isSampled(long traceId) { Boolean decision = sample(method).sampled(); if (decision == null) return fallback.isSampled(traceId); return decision; } };
/** @see TraceContext#debug() */ public Builder debug(boolean debug) { flags = SamplingFlags.debug(debug, flags); return this; }
static TraceContextOrSamplingFlags tryParseSamplingFlags(CharSequence b3, int pos) { int flags = parseFlags(b3, pos); if (flags == 0) return null; return TraceContextOrSamplingFlags.create(SamplingFlags.toSamplingFlags(flags)); }
/** This ensures constants are always used, in order to reduce allocation overhead */ static SamplingFlags toSamplingFlags(int flags) { switch (flags) { case 0: return EMPTY; case FLAG_SAMPLED_SET: return NOT_SAMPLED; case FLAG_SAMPLED_SET | FLAG_SAMPLED: return SAMPLED; case FLAG_SAMPLED_SET | FLAG_SAMPLED | FLAG_DEBUG: return DEBUG; case FLAG_SAMPLED_LOCAL: return EMPTY_SAMPLED_LOCAL; case FLAG_SAMPLED_LOCAL | FLAG_SAMPLED_SET: return NOT_SAMPLED_SAMPLED_LOCAL; case FLAG_SAMPLED_LOCAL | FLAG_SAMPLED_SET | FLAG_SAMPLED: return SAMPLED_SAMPLED_LOCAL; case FLAG_SAMPLED_LOCAL | FLAG_SAMPLED_SET | FLAG_SAMPLED | FLAG_DEBUG: return DEBUG_SAMPLED_LOCAL; default: assert false; // programming error, but build anyway return new SamplingFlags(flags); } } }
@Override public <Req> Boolean trySample(HttpAdapter<Req, ?> adapter, Req request) { String method = adapter.method(request); String path = adapter.path(request); if (method == null || path == null) return null; // use default if we couldn't parse return sampler.sample(new MethodAndPath(method, path)).sampled(); }
/** * Setting debug to true also sets sampled to true. * * @see SamplingFlags#debug() */ public Builder debug(boolean debug) { flags = SamplingFlags.debug(debug, flags); return this; }
TraceContextOrSamplingFlags withFlags(int flags) { switch (type) { case 1: TraceContext context = InternalPropagation.instance.withFlags((TraceContext) value, flags); return new TraceContextOrSamplingFlags(type, context, extra); case 2: TraceIdContext traceIdContext = idContextWithFlags(flags); return new TraceContextOrSamplingFlags(type, traceIdContext, extra); case 3: SamplingFlags samplingFlags = SamplingFlags.toSamplingFlags(flags); if (extra.isEmpty()) return create(samplingFlags); return new TraceContextOrSamplingFlags(type, samplingFlags, extra); } throw new AssertionError("programming error"); }
@Override public boolean isSampled(long traceId) { Boolean decision = sample(method).sampled(); return decision != null ? decision : false; } };
/** @see TraceIdContext#debug() */ public Builder debug(boolean debug) { flags = SamplingFlags.debug(debug, flags); return this; }
public SamplingFlags build() { return toSamplingFlags(flags); } }
/** Returns {@link SamplingFlags#sampled()}, regardless of subtype. */ @Nullable public Boolean sampled() { return value.sampled(); }
/** * True implies {@link #sampled()}, and is additionally a request to override any storage or * collector layer sampling. Defaults to false. */ public final boolean debug() { return debug(flags); }