Class SpanBuilderImpl

    • 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
      • 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
    • 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)
      • linkSpans

        private static void linkSpans​(Span span,
                                      java.util.List<Span> parentLinks)
      • startSpan

        public Span startSpan()
        Description copied from class: SpanBuilder
        Starts a new Span.

        Users must manually call Span.end() or Span.end(EndSpanOptions) to end this Span.

        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 class SpanBuilder
        Returns:
        the newly created Span.
      • setSampler

        public SpanBuilderImpl setSampler​(Sampler sampler)
        Description copied from class: SpanBuilder
        Sets the Sampler to use. If not set, the implementation will provide a default.
        Specified by:
        setSampler in class SpanBuilder
        Parameters:
        sampler - the Sampler to use when determining sampling for a Span.
        Returns:
        this.
      • setParentLinks

        public SpanBuilderImpl setParentLinks​(java.util.List<Span> parentLinks)
        Description copied from class: SpanBuilder
        Sets the List of parent links. Links are used to link Spans in different traces. Used (for example) in batching operations, where a single batch handler processes multiple requests from different traces.
        Specified by:
        setParentLinks in class SpanBuilder
        Parameters:
        parentLinks - new links to be added.
        Returns:
        this.
      • setRecordEvents

        public SpanBuilderImpl setRecordEvents​(boolean recordEvents)
        Description copied from class: SpanBuilder
        Sets the option Span.Options.RECORD_EVENTS for the newly created Span. If not called, the implementation will provide a default.
        Specified by:
        setRecordEvents in class SpanBuilder
        Parameters:
        recordEvents - new value determining if this Span should have events recorded.
        Returns:
        this.
      • setSpanKind

        public SpanBuilderImpl setSpanKind​(@Nullable
                                           Span.Kind kind)
        Description copied from class: SpanBuilder
        Sets the Span.Kind for the newly created Span. If not called, the implementation will provide a default.
        Overrides:
        setSpanKind in class SpanBuilder
        Parameters:
        kind - the kind of the newly created Span.
        Returns:
        this.