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