io.opentracing.propagation.BinaryExtract Java Examples

The following examples show how to use io.opentracing.propagation.BinaryExtract. 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
/**
 * Extracts the underlying context using B3 encoding by default. Null is returned when there is no
 * encoded context in the carrier, or upon error extracting it.
 */
@Nullable @Override public <C> BraveSpanContext extract(Format<C> format, C carrier) {
  TraceContextOrSamplingFlags extractionResult;
  if (carrier instanceof BinaryExtract) {
    extractionResult = BinaryCodec.INSTANCE.extract((BinaryExtract) carrier);
  } else {
    Extractor<C> extractor = (Extractor<C>) formatToExtractor.get(format);
    if (extractor == null) {
      throw new UnsupportedOperationException(format + " not in " + formatToExtractor.keySet());
    }
    extractionResult = extractor.extract(carrier);
  }
  if (emptyExtractions.contains(extractionResult)) return null;
  return BraveSpanContext.create(extractionResult);
}
 
Example #2
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 #3
Source File: MockTracerTest.java    From opentracing-java with Apache License 2.0 5 votes vote down vote up
@Test(expected = RuntimeException.class)
public void testBinaryPropagatorExtractError() {
    MockTracer tracer = new MockTracer(MockTracer.Propagator.BINARY);
    {
        BinaryExtract binary = BinaryAdapters.extractionCarrier(ByteBuffer.allocate(4));
        tracer.extract(Format.Builtin.BINARY_EXTRACT, binary);
    }
}