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();
}
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);
}
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));
}
Aggregations