Search in sources :

Example 31 with Span

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

the class BasicOperationsBenchmark method createSpanWithExplicitParent.

/**
 * Create a child span.
 */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Span createSpanWithExplicitParent(Data data) {
    Span span = data.tracer.spanBuilderWithExplicitParent("ChildSpan", data.span).setRecordEvents(data.recorded).setSampler(data.sampled ? Samplers.alwaysSample() : Samplers.neverSample()).startSpan();
    span.end();
    return span;
}
Also used : Span(io.opencensus.trace.Span) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

Example 32 with Span

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

the class BasicOperationsBenchmark method createSpanWithRemoteParent.

/**
 * Create a child span with a remote parent.
 */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Span createSpanWithRemoteParent(Data data) {
    Span span = data.tracer.spanBuilderWithRemoteParent("ChildSpanFromRemoteParent", data.span.getContext()).setRecordEvents(data.recorded).setSampler(data.sampled ? Samplers.alwaysSample() : Samplers.neverSample()).startSpan();
    span.end();
    return span;
}
Also used : Span(io.opencensus.trace.Span) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

Example 33 with Span

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

the class BasicOperationsBenchmark method createRootSpan.

/**
 * Create a root span.
 */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Span createRootSpan(Data data) {
    Span span = data.tracer.spanBuilderWithExplicitParent("RootSpan", null).setRecordEvents(data.recorded).setSampler(data.sampled ? Samplers.alwaysSample() : Samplers.neverSample()).startSpan();
    span.end();
    return span;
}
Also used : Span(io.opencensus.trace.Span) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

Example 34 with Span

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

the class ContextUtilsTest method testGetCurrentSpan_DefaultContext.

@Test
public void testGetCurrentSpan_DefaultContext() {
    Span span = ContextHandleUtils.getValue(ContextHandleUtils.currentContext());
    assertThat(span).isEqualTo(BlankSpan.INSTANCE);
}
Also used : BlankSpan(io.opencensus.trace.BlankSpan) Span(io.opencensus.trace.Span) Test(org.junit.Test)

Example 35 with Span

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

the class MultiSpansContextTracing method doSomeMoreWork.

private static void doSomeMoreWork() {
    // Create a child Span of the current Span.
    Span span = tracer.spanBuilder("MyChildSpan").startSpan();
    try (Scope ws = tracer.withSpan(span)) {
        doSomeOtherWork();
    }
    span.end();
}
Also used : Scope(io.opencensus.common.Scope) 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