Search in sources :

Example 41 with Span

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();
}
Also used : Span(io.opencensus.trace.Span) Test(org.junit.Test)

Example 42 with Span

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();
}
Also used : Span(io.opencensus.trace.Span) Test(org.junit.Test)

Example 43 with Span

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());
}
Also used : Span(io.opencensus.trace.Span) Test(org.junit.Test)

Example 44 with Span

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();
}
Also used : TraceId(io.opencensus.trace.TraceId) Span(io.opencensus.trace.Span) Test(org.junit.Test)

Example 45 with Span

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());
        }
    }
}
Also used : CanonicalCode(io.opencensus.trace.Status.CanonicalCode) Span(io.opencensus.trace.Span)

Aggregations

Span (io.opencensus.trace.Span)47 Test (org.junit.Test)17 Benchmark (org.openjdk.jmh.annotations.Benchmark)14 BenchmarkMode (org.openjdk.jmh.annotations.BenchmarkMode)14 OutputTimeUnit (org.openjdk.jmh.annotations.OutputTimeUnit)14 Scope (io.opencensus.common.Scope)8 BlankSpan (io.opencensus.trace.BlankSpan)8 ArrayList (java.util.ArrayList)4 SpanBuilder (io.opencensus.trace.SpanBuilder)3 SpanContext (io.opencensus.trace.SpanContext)3 ApiException (com.google.api.gax.rpc.ApiException)2 ByteString (com.google.protobuf.ByteString)2 HttpRequestContext (io.opencensus.contrib.http.HttpRequestContext)2 Metric (io.opencensus.metrics.export.Metric)2 TagContext (io.opencensus.tags.TagContext)2 AttributeValue (io.opencensus.trace.AttributeValue)2 SpanId (io.opencensus.trace.SpanId)2 TraceId (io.opencensus.trace.TraceId)2 TraceConfig (io.opencensus.trace.config.TraceConfig)2 TraceParams (io.opencensus.trace.config.TraceParams)2