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