Class SpanContext


  • @Immutable
    public abstract class SpanContext
    extends Object
    A class that represents a span context. A span context contains the state that must propagate to child Spans and across process boundaries. It contains the identifiers (a trace_id and span_id) associated with the Span and a set of options (currently only whether the context is sampled or not), as well as the traceState and the remote flag.
    • Constructor Detail

      • SpanContext

        public SpanContext()
    • Method Detail

      • getInvalid

        public static SpanContext getInvalid()
        Returns the invalid SpanContext that can be used for no-op operations.
        Returns:
        the invalid SpanContext.
      • create

        public static SpanContext create​(String traceIdHex,
                                         String spanIdHex,
                                         byte traceFlags,
                                         TraceState traceState)
        Creates a new SpanContext with the given identifiers and options.
        Parameters:
        traceIdHex - the trace identifier of the span context.
        spanIdHex - the span identifier of the span context.
        traceFlags - the byte representation of the TraceFlags
        traceState - the trace state for the span context.
        Returns:
        a new SpanContext with the given identifiers and options.
      • createFromRemoteParent

        public static SpanContext createFromRemoteParent​(String traceIdHex,
                                                         String spanIdHex,
                                                         byte traceFlags,
                                                         TraceState traceState)
        Creates a new SpanContext that was propagated from a remote parent, with the given identifiers and options.
        Parameters:
        traceIdHex - the trace identifier of the span context.
        spanIdHex - the span identifier of the span context.
        traceFlags - the byte representation of the TraceFlags
        traceState - the trace state for the span context.
        Returns:
        a new SpanContext with the given identifiers and options.
      • getTraceIdAsHexString

        public String getTraceIdAsHexString()
        Returns the trace identifier associated with this SpanContext.
        Returns:
        the trace identifier associated with this SpanContext.
      • getTraceIdBytes

        @Memoized
        public byte[] getTraceIdBytes()
        Returns the byte[] representation of the trace identifier associated with this SpanContext.
      • getSpanIdAsHexString

        public String getSpanIdAsHexString()
        Returns the span identifier associated with this SpanContext.
        Returns:
        the span identifier associated with this SpanContext.
      • getSpanIdBytes

        @Memoized
        public byte[] getSpanIdBytes()
        Returns the byte[] representation of the span identifier associated with this SpanContext.
      • isSampled

        public boolean isSampled()
        Whether the span in this context is sampled.
      • getTraceFlags

        public abstract byte getTraceFlags()
        The byte-representation of TraceFlags.
      • copyTraceFlagsHexTo

        public void copyTraceFlagsHexTo​(char[] dest,
                                        int destOffset)
      • getTraceState

        public abstract TraceState getTraceState()
        Returns the TraceState associated with this SpanContext.
        Returns:
        the TraceState associated with this SpanContext.
      • isValid

        @Memoized
        public boolean isValid()
        Returns true if this SpanContext is valid.
        Returns:
        true if this SpanContext is valid.
      • isRemote

        public abstract boolean isRemote()
        Returns true if the SpanContext was propagated from a remote parent.
        Returns:
        true if the SpanContext was propagated from a remote parent.