Search in sources :

Example 26 with TextMap

use of io.opentracing.propagation.TextMap in project jaeger-client-java by jaegertracing.

the class TextMapCodec method extract.

@Override
public JaegerSpanContext extract(TextMap carrier) {
    JaegerSpanContext context = null;
    Map<String, String> baggage = null;
    String debugId = null;
    for (Map.Entry<String, String> entry : carrier) {
        String key = entry.getKey();
        if (key.equalsIgnoreCase(contextKey)) {
            context = contextFromString(decodedValue(entry.getValue()));
        } else if (key.equalsIgnoreCase(Constants.DEBUG_ID_HEADER_KEY)) {
            debugId = decodedValue(entry.getValue());
        } else if (key.regionMatches(true, 0, baggagePrefix, 0, baggagePrefix.length())) {
            if (baggage == null) {
                baggage = new HashMap<>();
            }
            baggage.put(keys.unprefixedKey(key.toLowerCase(Locale.ROOT), baggagePrefix), decodedValue(entry.getValue()));
        } else if (key.equalsIgnoreCase(Constants.BAGGAGE_HEADER_KEY)) {
            baggage = parseBaggageHeader(decodedValue(entry.getValue()), baggage);
        }
    }
    if (debugId == null && baggage == null) {
        return context;
    }
    return objectFactory.createSpanContext(context == null ? 0L : context.getTraceIdHigh(), context == null ? 0L : context.getTraceIdLow(), context == null ? 0L : context.getSpanId(), context == null ? 0L : context.getParentId(), context == null ? (byte) 0 : context.getFlags(), baggage, debugId);
}
Also used : HashMap(java.util.HashMap) TextMap(io.opentracing.propagation.TextMap) Map(java.util.Map) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext)

Example 27 with TextMap

use of io.opentracing.propagation.TextMap in project jaeger-client-java by jaegertracing.

the class B3TextMapCodecResiliencyTest method validHeaders.

private TextMap validHeaders() {
    TextMap maliciousCarrier = new B3TextMapCodecTest.DelegatingTextMap();
    String validInput = "ffffffffffffffffffffffffffffffff";
    maliciousCarrier.put(B3TextMapCodec.TRACE_ID_NAME, validInput);
    maliciousCarrier.put(B3TextMapCodec.SPAN_ID_NAME, validInput);
    maliciousCarrier.put(B3TextMapCodec.PARENT_SPAN_ID_NAME, validInput);
    return maliciousCarrier;
}
Also used : TextMap(io.opentracing.propagation.TextMap)

Example 28 with TextMap

use of io.opentracing.propagation.TextMap in project jaeger-client-java by jaegertracing.

the class B3TextMapCodecResiliencyTest method shouldFallbackWhenMaliciousInput.

@Test
@UseDataProvider("maliciousInputs")
public void shouldFallbackWhenMaliciousInput(String headerName, String maliciousInput) {
    TextMap maliciousCarrier = validHeaders();
    maliciousCarrier.put(headerName, maliciousInput);
    // when
    JaegerSpanContext extract = sut.extract(maliciousCarrier);
    // then
    assertNull(extract);
}
Also used : TextMap(io.opentracing.propagation.TextMap) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 29 with TextMap

use of io.opentracing.propagation.TextMap in project hono by eclipse.

the class TracingHelper method extractSpanContext.

/**
 * Extracts a {@code SpanContext} from given key-value pairs.
 * <p>
 * This provides a generic way to deserialize a span context from any kind of textual data.
 * See {@link #injectSpanContext(Tracer, SpanContext, BiConsumer)} for the corresponding method to
 * serialize the context in that data.
 *
 * @param tracer The Tracer to use for extracting the context.
 * @param keyValueIteratorSupplier The supplier that provides an iterator over key-values pairs representing the
 *            context.
 * @return The context or {@code null} if the given options do not contain a context.
 * @throws NullPointerException if any of the parameters is {@code null}.
 */
public static SpanContext extractSpanContext(final Tracer tracer, final Supplier<Iterator<Map.Entry<String, String>>> keyValueIteratorSupplier) {
    Objects.requireNonNull(tracer);
    Objects.requireNonNull(keyValueIteratorSupplier);
    return tracer.extract(Format.Builtin.TEXT_MAP, new TextMap() {

        @Override
        public Iterator<Map.Entry<String, String>> iterator() {
            return keyValueIteratorSupplier.get();
        }

        @Override
        public void put(final String key, final String value) {
            throw new UnsupportedOperationException();
        }
    });
}
Also used : Iterator(java.util.Iterator) TextMap(io.opentracing.propagation.TextMap) MultiMap(io.vertx.core.MultiMap) HashMap(java.util.HashMap) Map(java.util.Map) TextMap(io.opentracing.propagation.TextMap)

Aggregations

TextMap (io.opentracing.propagation.TextMap)29 Test (org.junit.Test)16 HashMap (java.util.HashMap)14 Map (java.util.Map)7 SpanContext (com.uber.jaeger.SpanContext)6 JaegerSpanContext (io.jaegertracing.internal.JaegerSpanContext)6 ConstSampler (com.uber.jaeger.samplers.ConstSampler)3 Format (io.opentracing.propagation.Format)3 TextMapAdapter (io.opentracing.propagation.TextMapAdapter)3 SpanId (com.github.kristofa.brave.SpanId)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Metrics (com.uber.jaeger.metrics.Metrics)2 InMemoryReporter (com.uber.jaeger.reporters.InMemoryReporter)2 RequestTraceSpanContext (fish.payara.notification.requesttracing.RequestTraceSpanContext)2 JaegerSpan (io.jaegertracing.internal.JaegerSpan)2 TextMapExtractAdapter (io.opentracing.propagation.TextMapExtractAdapter)2 MultiMap (io.vertx.core.MultiMap)2 ByteBuffer (java.nio.ByteBuffer)2 Iterator (java.util.Iterator)2 Entry (java.util.Map.Entry)2