use of io.opencensus.proto.trace.v1.ProbabilitySampler in project instrumentation-java by census-instrumentation.
the class TraceProtoUtils method toTraceConfigProto.
/**
* Converts {@link TraceParams} to {@link TraceConfig}.
*
* @param traceParams the {@code TraceParams}.
* @return {@code TraceConfig}.
*/
static TraceConfig toTraceConfigProto(TraceParams traceParams) {
TraceConfig.Builder traceConfigProtoBuilder = TraceConfig.newBuilder();
Sampler librarySampler = traceParams.getSampler();
if (Samplers.alwaysSample().equals(librarySampler)) {
traceConfigProtoBuilder.setConstantSampler(ConstantSampler.newBuilder().setDecision(ConstantDecision.ALWAYS_ON).build());
} else if (Samplers.neverSample().equals(librarySampler)) {
traceConfigProtoBuilder.setConstantSampler(ConstantSampler.newBuilder().setDecision(ConstantDecision.ALWAYS_OFF).build());
} else {
// TODO: consider exposing the sampling probability of ProbabilitySampler.
double samplingProbability = parseSamplingProbability(librarySampler);
traceConfigProtoBuilder.setProbabilitySampler(ProbabilitySampler.newBuilder().setSamplingProbability(samplingProbability).build());
}
return traceConfigProtoBuilder.build();
}
use of io.opencensus.proto.trace.v1.ProbabilitySampler in project instrumentation-java by census-instrumentation.
the class TraceProtoUtils method parseSamplingProbability.
private static double parseSamplingProbability(Sampler sampler) {
String description = sampler.getDescription();
// description follows format "ProbabilitySampler{%.6f}", samplingProbability.
int leftParenIndex = description.indexOf("{");
int rightParenIndex = description.indexOf("}");
return Double.parseDouble(description.substring(leftParenIndex + 1, rightParenIndex));
}
Aggregations