Search in sources :

Example 6 with TraceConfig

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

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

the class TraceProtoUtilsTest method applyUpdatedConfig.

@Test
public void applyUpdatedConfig() {
    TraceConfig configProto = TraceConfig.newBuilder().setProbabilitySampler(ProbabilitySampler.newBuilder().setSamplingProbability(0.01).build()).build();
    UpdatedLibraryConfig updatedLibraryConfig = UpdatedLibraryConfig.newBuilder().setConfig(configProto).build();
    TraceParams traceParams = TraceProtoUtils.getUpdatedTraceParams(updatedLibraryConfig, mockTraceConfig);
    TraceParams expectedParams = DEFAULT_PARAMS.toBuilder().setSampler(Samplers.probabilitySampler(0.01)).build();
    Mockito.verify(mockTraceConfig, Mockito.times(1)).getActiveTraceParams();
    assertThat(traceParams).isEqualTo(expectedParams);
}
Also used : UpdatedLibraryConfig(io.opencensus.proto.agent.trace.v1.UpdatedLibraryConfig) TraceConfig(io.opencensus.proto.trace.v1.TraceConfig) TraceParams(io.opencensus.trace.config.TraceParams) Test(org.junit.Test)

Example 8 with TraceConfig

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

the class TraceProtoUtilsTest method fromTraceConfigProto_ProbabilitySampler.

@Test
public void fromTraceConfigProto_ProbabilitySampler() {
    TraceConfig traceConfig = TraceConfig.newBuilder().setProbabilitySampler(ProbabilitySampler.newBuilder().setSamplingProbability(0.01).build()).build();
    assertThat(TraceProtoUtils.fromTraceConfigProto(traceConfig, DEFAULT_PARAMS).getSampler()).isEqualTo(Samplers.probabilitySampler(0.01));
}
Also used : TraceConfig(io.opencensus.proto.trace.v1.TraceConfig) Test(org.junit.Test)

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