Search in sources :

Example 1 with ProbabilitySampler

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();
}
Also used : ConstantSampler(io.opencensus.proto.trace.v1.ConstantSampler) ProbabilitySampler(io.opencensus.proto.trace.v1.ProbabilitySampler) Sampler(io.opencensus.trace.Sampler) TraceConfig(io.opencensus.proto.trace.v1.TraceConfig)

Example 2 with ProbabilitySampler

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));
}
Also used : ByteString(com.google.protobuf.ByteString) TruncatableString(io.opencensus.proto.trace.v1.TruncatableString)

Aggregations

ByteString (com.google.protobuf.ByteString)1 ConstantSampler (io.opencensus.proto.trace.v1.ConstantSampler)1 ProbabilitySampler (io.opencensus.proto.trace.v1.ProbabilitySampler)1 TraceConfig (io.opencensus.proto.trace.v1.TraceConfig)1 TruncatableString (io.opencensus.proto.trace.v1.TruncatableString)1 Sampler (io.opencensus.trace.Sampler)1