Class CloudTraceFormat

java.lang.Object
io.opencensus.trace.propagation.TextFormat
io.opencensus.contrib.http.util.CloudTraceFormat

final class CloudTraceFormat extends TextFormat
Implementation of the "X-Cloud-Trace-Context" format, defined by the Google Cloud Trace.

The supported format is the following:

 <TRACE_ID>/<SPAN_ID>[;o=<TRACE_OPTIONS>]
 
  • TRACE_ID is a 32-character hex value;
  • SPAN_ID is a decimal representation of a 64-bit unsigned long;
  • TRACE_OPTIONS is a decimal representation of a 32-bit unsigned integer. The least significant bit defines whether a request is traced (1 - enabled, 0 - disabled). Behaviors of other bits are currently undefined. This value is optional. Although upstream service may leave this value unset to leave the sampling decision up to downstream client, this utility will always default it to 0 if absent.

Valid values:

  • "105445aa7843bc8bf206b120001000/123;o=1"
  • "105445aa7843bc8bf206b120001000/123"
  • "105445aa7843bc8bf206b120001000/123;o=0"
  • Field Details

  • Constructor Details

    • CloudTraceFormat

      CloudTraceFormat()
  • Method Details

    • fields

      public List<String> fields()
      Description copied from class: TextFormat
      The propagation fields defined. If your carrier is reused, you should delete the fields here before calling TextFormat.inject(SpanContext, Object, Setter).

      For example, if the carrier is a single-use or immutable request object, you don't need to clear fields as they couldn't have been set before. If it is a mutable, retryable object, successive calls should clear these fields first.

      Specified by:
      fields in class TextFormat
    • inject

      public <C> void inject(SpanContext spanContext, C carrier, TextFormat.Setter<C> setter)
      Description copied from class: TextFormat
      Injects the span context downstream. For example, as http headers.
      Specified by:
      inject in class TextFormat
      Parameters:
      spanContext - possibly not sampled.
      carrier - holds propagation fields. For example, an outgoing message or http request.
      setter - invoked for each propagation key to add or remove.
    • extract

      public <C> SpanContext extract(C carrier, TextFormat.Getter<C> getter) throws SpanContextParseException
      Description copied from class: TextFormat
      Extracts the span context from upstream. For example, as http headers.
      Specified by:
      extract in class TextFormat
      Parameters:
      carrier - holds propagation fields. For example, an outgoing message or http request.
      getter - invoked for each propagation key to get.
      Throws:
      SpanContextParseException - if the input is invalid
    • longToSpanId

      private static SpanId longToSpanId(long x)
    • spanIdToLong

      private static long spanIdToLong(SpanId spanId)