Search in sources :

Example 1 with ConstantDecision

use of io.opencensus.proto.trace.v1.ConstantSampler.ConstantDecision in project instrumentation-java by census-instrumentation.

the class TraceProtoUtils method fromTraceConfigProto.

/**
 * Converts {@link TraceConfig} to {@link TraceParams}.
 *
 * @param traceConfigProto {@code TraceConfig}.
 * @param currentTraceParams current {@code TraceParams}.
 * @return updated {@code TraceParams}.
 * @since 0.17
 */
static TraceParams fromTraceConfigProto(TraceConfig traceConfigProto, TraceParams currentTraceParams) {
    TraceParams.Builder builder = currentTraceParams.toBuilder();
    if (traceConfigProto.hasConstantSampler()) {
        ConstantSampler constantSampler = traceConfigProto.getConstantSampler();
        ConstantDecision decision = constantSampler.getDecision();
        if (ConstantDecision.ALWAYS_ON.equals(decision)) {
            builder.setSampler(Samplers.alwaysSample());
        } else if (ConstantDecision.ALWAYS_OFF.equals(decision)) {
            builder.setSampler(Samplers.neverSample());
        }
    // else if (ConstantDecision.ALWAYS_PARENT.equals(decision)) {
    // For ALWAYS_PARENT, don't need to update configs since in Java by default parent sampling
    // decision always takes precedence.
    // }
    } else if (traceConfigProto.hasProbabilitySampler()) {
        builder.setSampler(Samplers.probabilitySampler(traceConfigProto.getProbabilitySampler().getSamplingProbability()));
    }
    // TODO: add support for RateLimitingSampler.
    return builder.build();
}
Also used : ConstantSampler(io.opencensus.proto.trace.v1.ConstantSampler) ConstantDecision(io.opencensus.proto.trace.v1.ConstantSampler.ConstantDecision) TraceParams(io.opencensus.trace.config.TraceParams)

Aggregations

ConstantSampler (io.opencensus.proto.trace.v1.ConstantSampler)1 ConstantDecision (io.opencensus.proto.trace.v1.ConstantSampler.ConstantDecision)1 TraceParams (io.opencensus.trace.config.TraceParams)1