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);
}
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;
}
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);
}
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();
}
});
}
Aggregations