Java Code Examples for brave.propagation.TraceContextOrSamplingFlags#EMPTY

The following examples show how to use brave.propagation.TraceContextOrSamplingFlags#EMPTY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BraveTracer.java    From brave-opentracing with Apache License 2.0 5 votes vote down vote up
@Override public TraceContextOrSamplingFlags extract(BinaryExtract binaryExtract) {
  try {
    return B3SingleFormat.parseB3SingleFormat(ascii.decode(binaryExtract.extractionBuffer()));
  } catch (RuntimeException e) {
    return TraceContextOrSamplingFlags.EMPTY;
  }
}
 
Example 2
Source File: BraveSpanBuilder.java    From brave-opentracing with Apache License 2.0 5 votes vote down vote up
static TraceContextOrSamplingFlags flagsFromSamplingPriority(String samplingPriorityString) {
  if (samplingPriorityString == null) return TraceContextOrSamplingFlags.EMPTY;
  try {
    int samplingPriority = Integer.parseInt(samplingPriorityString);
    if (samplingPriority == 0) {
      return TraceContextOrSamplingFlags.NOT_SAMPLED;
    } else if (samplingPriority > 0) {
      return TraceContextOrSamplingFlags.SAMPLED;
    }
  } catch (NumberFormatException ex) {
    // ignore
  }
  return TraceContextOrSamplingFlags.EMPTY;
}
 
Example 3
Source File: XCloudTraceContextExtractor.java    From zipkin-gcp with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a tracing context if the extracted string follows the "x-cloud-trace-context: TRACE_ID"
 * or "x-cloud-trace-context: TRACE_ID/SPAN_ID" format; or the "x-cloud-trace-context:
 * TRACE_ID/SPAN_ID;o=TRACE_TRUE" format and {@code TRACE_TRUE}'s value is {@code 1}.
 */
@Override public TraceContextOrSamplingFlags extract(R request) {
  if (request == null) throw new NullPointerException("request == null");
  TraceContextOrSamplingFlags context = primary.extract(request);
  if (context != TraceContextOrSamplingFlags.EMPTY) return context;

  TraceContextOrSamplingFlags result = TraceContextOrSamplingFlags.EMPTY;

  String xCloudTraceContext = getter.get(request, StackdriverTracePropagation.TRACE_ID_NAME);

  if (xCloudTraceContext != null) {
    String[] tokens = xCloudTraceContext.split("/");

    long[] traceId = convertHexTraceIdToLong(tokens[0]);

    // traceId is null if invalid
    if (traceId != null) {
      long spanId = 0; // 0 indicates no span ID is set by the user
      Boolean traceTrue = null; // null means to defer trace decision to sampler

      // A span ID exists. A TRACE_TRUE flag also possibly exists.
      if (tokens.length >= 2) {
        String[] traceOptionTokens = tokens[1].split(";");

        if (traceOptionTokens.length >= 1
            && !traceOptionTokens[0].isEmpty()) {
          spanId = parseUnsignedLong(traceOptionTokens[0]);
        }

        if (traceOptionTokens.length >= 2) {
          traceTrue = extractTraceTrueFromToken(traceOptionTokens[1]);
        }
      }

      if (spanId == 0) {
        result = TraceContextOrSamplingFlags.create(
            TraceIdContext.newBuilder()
                .traceIdHigh(traceId[0])
                .traceId(traceId[1])
                .sampled(traceTrue)
                .build());
      } else {
        result = TraceContextOrSamplingFlags.create(
            TraceContext.newBuilder()
                .traceIdHigh(traceId[0])
                .traceId(traceId[1])
                .spanId(spanId)
                .sampled(traceTrue)
                .build());
      }
    }
  }

  return result;
}
 
Example 4
Source File: TracerTest.java    From brave with Apache License 2.0 4 votes vote down vote up
@Test public void localRootId_nextSpan_flags_empty() {
  TraceContextOrSamplingFlags flags = TraceContextOrSamplingFlags.EMPTY;
  localRootId(flags, flags, ctx -> tracer.nextSpan(ctx));
}