use of io.opencensus.trace.Span in project instrumentation-java by census-instrumentation.
the class SpanBuilderImplTest method startRemoteChildSpan_WithoutSpecifiedSampler.
@Test
public void startRemoteChildSpan_WithoutSpecifiedSampler() {
Span rootSpan = SpanBuilderImpl.createWithParent(SPAN_NAME, null, spanBuilderOptions).setSampler(Samplers.neverSample()).startSpan();
assertThat(rootSpan.getContext().isValid()).isTrue();
assertThat(rootSpan.getContext().getTraceOptions().isSampled()).isFalse();
// Apply default sampler (always true in the tests) for spans with remote parent.
Span childSpan = SpanBuilderImpl.createWithRemoteParent(SPAN_NAME, rootSpan.getContext(), spanBuilderOptions).startSpan();
assertThat(childSpan.getContext().isValid()).isTrue();
assertThat(childSpan.getContext().getTraceId()).isEqualTo(rootSpan.getContext().getTraceId());
assertThat(childSpan.getContext().getTraceOptions().isSampled()).isTrue();
}
use of io.opencensus.trace.Span in project instrumentation-java by census-instrumentation.
the class SpanBuilderImplTest method startChildSpan_WithoutSpecifiedSampler.
@Test
public void startChildSpan_WithoutSpecifiedSampler() {
Span rootSpan = SpanBuilderImpl.createWithParent(SPAN_NAME, null, spanBuilderOptions).setSampler(Samplers.neverSample()).startSpan();
assertThat(rootSpan.getContext().isValid()).isTrue();
assertThat(rootSpan.getContext().getTraceOptions().isSampled()).isFalse();
// Don't apply the default sampler (always true) for child spans.
Span childSpan = SpanBuilderImpl.createWithParent(SPAN_NAME, rootSpan, spanBuilderOptions).startSpan();
assertThat(childSpan.getContext().isValid()).isTrue();
assertThat(childSpan.getContext().getTraceId()).isEqualTo(rootSpan.getContext().getTraceId());
assertThat(childSpan.getContext().getTraceOptions().isSampled()).isFalse();
}
use of io.opencensus.trace.Span in project instrumentation-java by census-instrumentation.
the class SpanBuilderImplTest method startChildSpan.
@Test
public void startChildSpan() {
Span rootSpan = SpanBuilderImpl.createWithParent(SPAN_NAME, null, spanBuilderOptions).startSpan();
assertThat(rootSpan.getContext().isValid()).isTrue();
assertThat(rootSpan.getOptions().contains(Options.RECORD_EVENTS)).isTrue();
assertThat(rootSpan.getContext().getTraceOptions().isSampled()).isTrue();
assertThat(((RecordEventsSpanImpl) rootSpan).toSpanData().getHasRemoteParent()).isNull();
Span childSpan = SpanBuilderImpl.createWithParent(SPAN_NAME, rootSpan, spanBuilderOptions).startSpan();
assertThat(childSpan.getContext().isValid()).isTrue();
assertThat(childSpan.getContext().getTraceId()).isEqualTo(rootSpan.getContext().getTraceId());
assertThat(((RecordEventsSpanImpl) childSpan).toSpanData().getParentSpanId()).isEqualTo(rootSpan.getContext().getSpanId());
assertThat(((RecordEventsSpanImpl) childSpan).toSpanData().getHasRemoteParent()).isFalse();
assertThat(((RecordEventsSpanImpl) childSpan).getTimestampConverter()).isEqualTo(((RecordEventsSpanImpl) rootSpan).getTimestampConverter());
}
use of io.opencensus.trace.Span in project instrumentation-java by census-instrumentation.
the class SpanBuilderImplTest method startRemoteChildSpan_WithProbabilitySamplerDefaultSampler.
@Test
public void startRemoteChildSpan_WithProbabilitySamplerDefaultSampler() {
when(traceConfig.getActiveTraceParams()).thenReturn(TraceParams.DEFAULT);
// This traceId will not be sampled by the ProbabilitySampler because the first 8 bytes as long
// is not less than probability * Long.MAX_VALUE;
TraceId traceId = TraceId.fromBytes(new byte[] { (byte) 0x8F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 0, 0, 0, 0, 0, 0, 0, 0 });
// If parent is sampled then the remote child must be sampled.
Span childSpan = SpanBuilderImpl.createWithRemoteParent(SPAN_NAME, SpanContext.create(traceId, SpanId.generateRandomId(randomHandler.current()), TraceOptions.builder().setIsSampled(true).build()), spanBuilderOptions).startSpan();
assertThat(childSpan.getContext().isValid()).isTrue();
assertThat(childSpan.getContext().getTraceId()).isEqualTo(traceId);
assertThat(childSpan.getContext().getTraceOptions().isSampled()).isTrue();
childSpan.end();
assertThat(traceConfig.getActiveTraceParams()).isEqualTo(TraceParams.DEFAULT);
// If parent is not sampled then the remote child must be not sampled.
childSpan = SpanBuilderImpl.createWithRemoteParent(SPAN_NAME, SpanContext.create(traceId, SpanId.generateRandomId(randomHandler.current()), TraceOptions.DEFAULT), spanBuilderOptions).startSpan();
assertThat(childSpan.getContext().isValid()).isTrue();
assertThat(childSpan.getContext().getTraceId()).isEqualTo(traceId);
assertThat(childSpan.getContext().getTraceOptions().isSampled()).isFalse();
childSpan.end();
}
use of io.opencensus.trace.Span in project instrumentation-java by census-instrumentation.
the class InProcessSampledSpanStoreImplTest method addSpanNameToAllErrorBuckets.
private void addSpanNameToAllErrorBuckets(String spanName) {
for (CanonicalCode code : CanonicalCode.values()) {
if (code != CanonicalCode.OK) {
Span sampledSpan = createSampledSpan(spanName);
Span notSampledSpan = createNotSampledSpan(spanName);
testClock.advanceTime(Duration.create(0, 1000));
sampledSpan.end(EndSpanOptions.builder().setStatus(code.toStatus()).build());
notSampledSpan.end(EndSpanOptions.builder().setStatus(code.toStatus()).build());
}
}
}
Aggregations