Search in sources :

Example 6 with Span

use of io.opencensus.trace.Span in project instrumentation-java by census-instrumentation.

the class HelloWorldServer method performWork.

// A helper function that performs some work in its own Span.
private static void performWork(Span parent) {
    SpanBuilder spanBuilder = tracer.spanBuilderWithExplicitParent("internal_work", parent).setRecordEvents(true);
    try (Scope scope = spanBuilder.startScopedSpan()) {
        Span span = tracer.getCurrentSpan();
        span.putAttribute("my_attribute", AttributeValue.stringAttributeValue("blue"));
        span.addAnnotation("Performing work.");
        // Working hard here.
        sleepFor(20);
        span.addAnnotation("Done work.");
    }
}
Also used : SpanBuilder(io.opencensus.trace.SpanBuilder) Scope(io.opencensus.common.Scope) Span(io.opencensus.trace.Span)

Example 7 with Span

use of io.opencensus.trace.Span in project instrumentation-java by census-instrumentation.

the class SpanBuilderImplTest method startRootSpan_WithoutSpecifiedSampler.

@Test
public void startRootSpan_WithoutSpecifiedSampler() {
    // Apply default sampler (always true in the tests) for root spans.
    Span rootSpan = SpanBuilderImpl.createWithParent(SPAN_NAME, null, spanBuilderOptions).startSpan();
    assertThat(rootSpan.getContext().isValid()).isTrue();
    assertThat(rootSpan.getContext().getTraceOptions().isSampled()).isTrue();
}
Also used : Span(io.opencensus.trace.Span) Test(org.junit.Test)

Example 8 with Span

use of io.opencensus.trace.Span in project instrumentation-java by census-instrumentation.

the class SpanBuilderImplTest method startSpanNullParentNoRecordOptions.

@Test
public void startSpanNullParentNoRecordOptions() {
    Span span = SpanBuilderImpl.createWithParent(SPAN_NAME, null, spanBuilderOptions).setSampler(Samplers.neverSample()).startSpan();
    assertThat(span.getContext().isValid()).isTrue();
    assertThat(span.getOptions().contains(Options.RECORD_EVENTS)).isFalse();
    assertThat(span.getContext().getTraceOptions().isSampled()).isFalse();
}
Also used : Span(io.opencensus.trace.Span) Test(org.junit.Test)

Example 9 with Span

use of io.opencensus.trace.Span in project instrumentation-java by census-instrumentation.

the class SpanBuilderImplTest method startRootSpan_WithSpecifiedSampler.

@Test
public void startRootSpan_WithSpecifiedSampler() {
    // Apply given sampler before default sampler for root spans.
    Span rootSpan = SpanBuilderImpl.createWithParent(SPAN_NAME, null, spanBuilderOptions).setSampler(Samplers.neverSample()).startSpan();
    assertThat(rootSpan.getContext().isValid()).isTrue();
    assertThat(rootSpan.getContext().getTraceOptions().isSampled()).isFalse();
}
Also used : Span(io.opencensus.trace.Span) Test(org.junit.Test)

Example 10 with Span

use of io.opencensus.trace.Span in project instrumentation-java by census-instrumentation.

the class SpanBuilderImplTest method startRemoteChildSpan_WithSpecifiedSampler.

@Test
public void startRemoteChildSpan_WithSpecifiedSampler() {
    Span rootSpan = SpanBuilderImpl.createWithParent(SPAN_NAME, null, spanBuilderOptions).setSampler(Samplers.alwaysSample()).startSpan();
    assertThat(rootSpan.getContext().isValid()).isTrue();
    assertThat(rootSpan.getContext().getTraceOptions().isSampled()).isTrue();
    // Apply given sampler before default sampler for spans with remote parent.
    Span childSpan = SpanBuilderImpl.createWithRemoteParent(SPAN_NAME, rootSpan.getContext(), spanBuilderOptions).setSampler(Samplers.neverSample()).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)

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