Package io.opencensus.implcore.trace
Class SpanBuilderImpl
- java.lang.Object
-
- io.opencensus.trace.SpanBuilder
-
- io.opencensus.implcore.trace.SpanBuilderImpl
-
final class SpanBuilderImpl extends SpanBuilder
Implementation of theSpanBuilder
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
SpanBuilderImpl.Options
-
Field Summary
Fields Modifier and Type Field Description private Span.Kind
kind
private java.lang.String
name
private static TraceOptions
NOT_SAMPLED_TRACE_OPTIONS
private SpanBuilderImpl.Options
options
private Span
parent
private java.util.List<Span>
parentLinks
private java.lang.Boolean
recordEvents
private SpanContext
remoteParentSpanContext
private static TraceOptions
SAMPLED_TRACE_OPTIONS
private Sampler
sampler
private static Tracestate
TRACESTATE_DEFAULT
-
Constructor Summary
Constructors Modifier Constructor Description private
SpanBuilderImpl(java.lang.String name, SpanContext remoteParentSpanContext, Span parent, SpanBuilderImpl.Options options)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static SpanBuilderImpl
createWithParent(java.lang.String spanName, Span parent, SpanBuilderImpl.Options options)
(package private) static SpanBuilderImpl
createWithRemoteParent(java.lang.String spanName, SpanContext remoteParentSpanContext, SpanBuilderImpl.Options options)
private static boolean
isAnyParentLinkSampled(java.util.List<Span> parentLinks)
private static void
linkSpans(Span span, java.util.List<Span> parentLinks)
private static boolean
makeSamplingDecision(SpanContext parent, java.lang.Boolean hasRemoteParent, java.lang.String name, Sampler sampler, java.util.List<Span> parentLinks, TraceId traceId, SpanId spanId, TraceParams activeTraceParams)
SpanBuilderImpl
setParentLinks(java.util.List<Span> parentLinks)
Sets theList
of parent links.SpanBuilderImpl
setRecordEvents(boolean recordEvents)
Sets the optionSpan.Options.RECORD_EVENTS
for the newly createdSpan
.SpanBuilderImpl
setSampler(Sampler sampler)
Sets theSampler
to use.SpanBuilderImpl
setSpanKind(Span.Kind kind)
Sets theSpan.Kind
for the newly createdSpan
.Span
startSpan()
Starts a newSpan
.private Span
startSpanInternal(SpanContext parentContext, java.lang.Boolean hasRemoteParent, java.lang.String name, Sampler sampler, java.util.List<Span> parentLinks, java.lang.Boolean recordEvents, Span.Kind kind, Span parentSpan)
-
Methods inherited from class io.opencensus.trace.SpanBuilder
startScopedSpan, startSpanAndCall, startSpanAndRun
-
-
-
-
Field Detail
-
TRACESTATE_DEFAULT
private static final Tracestate TRACESTATE_DEFAULT
-
SAMPLED_TRACE_OPTIONS
private static final TraceOptions SAMPLED_TRACE_OPTIONS
-
NOT_SAMPLED_TRACE_OPTIONS
private static final TraceOptions NOT_SAMPLED_TRACE_OPTIONS
-
options
private final SpanBuilderImpl.Options options
-
name
private final java.lang.String name
-
parent
@Nullable private final Span parent
-
remoteParentSpanContext
@Nullable private final SpanContext remoteParentSpanContext
-
sampler
@Nullable private Sampler sampler
-
parentLinks
private java.util.List<Span> parentLinks
-
recordEvents
@Nullable private java.lang.Boolean recordEvents
-
kind
@Nullable private Span.Kind kind
-
-
Constructor Detail
-
SpanBuilderImpl
private SpanBuilderImpl(java.lang.String name, @Nullable SpanContext remoteParentSpanContext, @Nullable Span parent, SpanBuilderImpl.Options options)
-
-
Method Detail
-
startSpanInternal
private Span startSpanInternal(@Nullable SpanContext parentContext, @Nullable java.lang.Boolean hasRemoteParent, java.lang.String name, @Nullable Sampler sampler, java.util.List<Span> parentLinks, @Nullable java.lang.Boolean recordEvents, @Nullable Span.Kind kind, @Nullable Span parentSpan)
-
makeSamplingDecision
private static boolean makeSamplingDecision(@Nullable SpanContext parent, @Nullable java.lang.Boolean hasRemoteParent, java.lang.String name, @Nullable Sampler sampler, java.util.List<Span> parentLinks, TraceId traceId, SpanId spanId, TraceParams activeTraceParams)
-
isAnyParentLinkSampled
private static boolean isAnyParentLinkSampled(java.util.List<Span> parentLinks)
-
createWithParent
static SpanBuilderImpl createWithParent(java.lang.String spanName, @Nullable Span parent, SpanBuilderImpl.Options options)
-
createWithRemoteParent
static SpanBuilderImpl createWithRemoteParent(java.lang.String spanName, @Nullable SpanContext remoteParentSpanContext, SpanBuilderImpl.Options options)
-
startSpan
public Span startSpan()
Description copied from class:SpanBuilder
Starts a newSpan
.Users must manually call
Span.end()
orSpan.end(EndSpanOptions)
to end thisSpan
.Does not install the newly created
Span
to the current Context.Example of usage:
class MyClass { private static final Tracer tracer = Tracing.getTracer(); void DoWork(Span parent) { Span childSpan = tracer.spanBuilderWithExplicitParent("MyChildSpan", parent).startSpan(); childSpan.addAnnotation("my annotation"); try { doSomeWork(childSpan); // Manually propagate the new span down the stack. } finally { // To make sure we end the span even in case of an exception. childSpan.end(); // Manually end the span. } } }
- Specified by:
startSpan
in classSpanBuilder
- Returns:
- the newly created
Span
.
-
setSampler
public SpanBuilderImpl setSampler(Sampler sampler)
Description copied from class:SpanBuilder
Sets theSampler
to use. If not set, the implementation will provide a default.- Specified by:
setSampler
in classSpanBuilder
- Parameters:
sampler
- theSampler
to use when determining sampling for aSpan
.- Returns:
- this.
-
setParentLinks
public SpanBuilderImpl setParentLinks(java.util.List<Span> parentLinks)
Description copied from class:SpanBuilder
Sets theList
of parent links. Links are used to linkSpan
s in different traces. Used (for example) in batching operations, where a single batch handler processes multiple requests from different traces.- Specified by:
setParentLinks
in classSpanBuilder
- Parameters:
parentLinks
- new links to be added.- Returns:
- this.
-
setRecordEvents
public SpanBuilderImpl setRecordEvents(boolean recordEvents)
Description copied from class:SpanBuilder
Sets the optionSpan.Options.RECORD_EVENTS
for the newly createdSpan
. If not called, the implementation will provide a default.- Specified by:
setRecordEvents
in classSpanBuilder
- Parameters:
recordEvents
- new value determining if thisSpan
should have events recorded.- Returns:
- this.
-
setSpanKind
public SpanBuilderImpl setSpanKind(@Nullable Span.Kind kind)
Description copied from class:SpanBuilder
Sets theSpan.Kind
for the newly createdSpan
. If not called, the implementation will provide a default.- Overrides:
setSpanKind
in classSpanBuilder
- Parameters:
kind
- the kind of the newly createdSpan
.- Returns:
- this.
-
-