use of io.opencensus.trace.Span in project instrumentation-java by census-instrumentation.
the class SpanBuilderImplTest method startChildSpan_WithSpecifiedSampler.
@Test
public void startChildSpan_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 the given sampler for child spans.
Span childSpan = SpanBuilderImpl.createWithParent(SPAN_NAME, rootSpan, spanBuilderOptions).setSampler(Samplers.neverSample()).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 HttpClientHandler method handleStart.
/**
* Instrument a request for tracing and stats before it is sent.
*
* <p>This method will create a span in current context to represent the HTTP call. The created
* span will be serialized and propagated to the server.
*
* <p>The generated span will NOT be set as current context. User can control when to enter the
* scope of this span. Use {@link AbstractHttpHandler#getSpanFromContext} to retrieve the span.
*
* @param parent the parent {@link Span}. {@code null} indicates using current span.
* @param carrier the entity that holds the HTTP information.
* @param request the request entity.
* @return the {@link HttpRequestContext} that contains stats and trace data associated with the
* request.
* @since 0.19
*/
public HttpRequestContext handleStart(@Nullable Span parent, C carrier, Q request) {
checkNotNull(carrier, "carrier");
checkNotNull(request, "request");
if (parent == null) {
parent = tracer.getCurrentSpan();
}
String spanName = getSpanName(request, extractor);
SpanBuilder builder = tracer.spanBuilderWithExplicitParent(spanName, parent);
Span span = builder.setSpanKind(Kind.CLIENT).startSpan();
if (span.getOptions().contains(Options.RECORD_EVENTS)) {
addSpanRequestAttributes(span, request, extractor);
}
// inject propagation header
SpanContext spanContext = span.getContext();
if (!spanContext.equals(SpanContext.INVALID)) {
textFormat.inject(spanContext, carrier, setter);
}
return getNewContext(span, tagger.getCurrentTagContext());
}
use of io.opencensus.trace.Span in project instrumentation-java by census-instrumentation.
the class StartEndSpanBenchmark method startEndSampledChildSpan.
/**
* This benchmark attempts to measure performance of start/end for a sampled child {@code Span}.
*/
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Span startEndSampledChildSpan(Data data) {
Span span = data.tracer.spanBuilderWithExplicitParent(SPAN_NAME, data.rootSpan).setSampler(Samplers.alwaysSample()).startSpan();
span.end();
return span;
}
use of io.opencensus.trace.Span in project instrumentation-java by census-instrumentation.
the class StartEndSpanBenchmark method startEndSampledRootSpan.
/**
* This benchmark attempts to measure performance of start/end for a sampled root {@code Span}.
*/
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Span startEndSampledRootSpan(Data data) {
Span span = data.tracer.spanBuilder(SPAN_NAME).setSampler(Samplers.alwaysSample()).startSpan();
span.end();
return span;
}
use of io.opencensus.trace.Span in project instrumentation-java by census-instrumentation.
the class StartEndSpanBenchmark method startEndNonSampledChildSpan.
/**
* This benchmark attempts to measure performance of start/end for a non-sampled child {@code
* Span}.
*/
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Span startEndNonSampledChildSpan(Data data) {
Span span = data.tracer.spanBuilderWithExplicitParent(SPAN_NAME, data.rootSpan).setSampler(Samplers.neverSample()).startSpan();
span.end();
return span;
}
Aggregations