Search in sources :

Example 1 with TraceConfig

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

the class TraceProtoUtilsTest method fromTraceConfigProto_NeverSampler.

@Test
public void fromTraceConfigProto_NeverSampler() {
    TraceConfig traceConfig = TraceConfig.newBuilder().setConstantSampler(ConstantSampler.newBuilder().setDecision(ConstantDecision.ALWAYS_OFF).build()).build();
    assertThat(TraceProtoUtils.fromTraceConfigProto(traceConfig, DEFAULT_PARAMS).getSampler()).isEqualTo(Samplers.neverSample());
}
Also used : TraceConfig(io.opencensus.proto.trace.v1.TraceConfig) Test(org.junit.Test)

Example 2 with TraceConfig

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

the class TraceProtoUtilsTest method fromTraceConfigProto_AlwaysSampler.

@Test
public void fromTraceConfigProto_AlwaysSampler() {
    TraceConfig traceConfig = TraceConfig.newBuilder().setConstantSampler(ConstantSampler.newBuilder().setDecision(ConstantDecision.ALWAYS_ON).build()).build();
    assertThat(TraceProtoUtils.fromTraceConfigProto(traceConfig, DEFAULT_PARAMS).getSampler()).isEqualTo(Samplers.alwaysSample());
}
Also used : TraceConfig(io.opencensus.proto.trace.v1.TraceConfig) Test(org.junit.Test)

Example 3 with TraceConfig

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

the class TraceProtoUtilsTest method getCurrentTraceConfig.

@Test
public void getCurrentTraceConfig() {
    TraceConfig configProto = TraceProtoUtils.toTraceConfigProto(DEFAULT_PARAMS);
    assertThat(TraceProtoUtils.getCurrentTraceConfig(mockTraceConfig)).isEqualTo(configProto);
    Mockito.verify(mockTraceConfig, Mockito.times(1)).getActiveTraceParams();
}
Also used : TraceConfig(io.opencensus.proto.trace.v1.TraceConfig) Test(org.junit.Test)

Example 4 with TraceConfig

use of io.opencensus.proto.trace.v1.TraceConfig 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)

Example 5 with TraceConfig

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

the class TraceProtoUtils method getUpdatedTraceParams.

// Creates an updated TraceParams with the given UpdatedLibraryConfig message and current
// TraceParams, then applies the updated TraceParams.
static TraceParams getUpdatedTraceParams(UpdatedLibraryConfig config, io.opencensus.trace.config.TraceConfig traceConfig) {
    TraceParams currentParams = traceConfig.getActiveTraceParams();
    TraceConfig traceConfigProto = config.getConfig();
    return fromTraceConfigProto(traceConfigProto, currentParams);
}
Also used : TraceConfig(io.opencensus.proto.trace.v1.TraceConfig) TraceParams(io.opencensus.trace.config.TraceParams)

Aggregations

TraceConfig (io.opencensus.proto.trace.v1.TraceConfig)7 Test (org.junit.Test)5 TraceParams (io.opencensus.trace.config.TraceParams)3 ConstantSampler (io.opencensus.proto.trace.v1.ConstantSampler)2 UpdatedLibraryConfig (io.opencensus.proto.agent.trace.v1.UpdatedLibraryConfig)1 ConstantDecision (io.opencensus.proto.trace.v1.ConstantSampler.ConstantDecision)1 ProbabilitySampler (io.opencensus.proto.trace.v1.ProbabilitySampler)1 Sampler (io.opencensus.trace.Sampler)1