Search in sources :

Example 6 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(TRACE_ID_NAME, validInput);
    maliciousCarrier.put(SPAN_ID_NAME, validInput);
    maliciousCarrier.put(PARENT_SPAN_ID_NAME, validInput);
    return maliciousCarrier;
}
Also used : TextMap(io.opentracing.propagation.TextMap)

Example 7 with TextMap

use of io.opentracing.propagation.TextMap in project incubator-skywalking by apache.

the class SkywalkingTracerExtractInterceptor method afterMethod.

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
    Format format = (Format) allArguments[0];
    if (Format.Builtin.TEXT_MAP.equals(format) || Format.Builtin.HTTP_HEADERS.equals(format)) {
        TextMap textMapCarrier = (TextMap) allArguments[1];
        ContextCarrier contextCarrier = new ContextCarrier();
        CarrierItem next = contextCarrier.items();
        while (next.hasNext()) {
            next = next.next();
            Iterator<Map.Entry<String, String>> iterator = textMapCarrier.iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, String> entry = iterator.next();
                if (next.getHeadKey().equals(entry.getKey())) {
                    next.setHeadValue(entry.getValue());
                    break;
                }
            }
        }
        ContextManager.extract(contextCarrier);
    }
    return new SkywalkingContext();
}
Also used : SkywalkingContext(org.apache.skywalking.apm.toolkit.opentracing.SkywalkingContext) ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) Format(io.opentracing.propagation.Format) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) TextMap(io.opentracing.propagation.TextMap) TextMap(io.opentracing.propagation.TextMap) Map(java.util.Map)

Example 8 with TextMap

use of io.opentracing.propagation.TextMap in project incubator-skywalking by apache.

the class SkywalkingSpanActivationTest method testExtractWithValidateContext.

@Test
public void testExtractWithValidateContext() throws Throwable {
    spanBuilder.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).withTag(Tags.PEER_HOST_IPV4.getKey(), "127.0.0.1").withTag(Tags.PEER_PORT.getKey(), 8080);
    startSpan();
    final Map<String, String> values = new HashMap<String, String>();
    TextMap carrier = new TextMap() {

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

        @Override
        public void put(String key, String value) {
            values.put(key, value);
        }
    };
    values.put(SW3CarrierItem.HEADER_NAME, "1.343.222|3|1|1|#127.0.0.1:8080|#/portal/|#/testEntrySpan|434.12.12123");
    extractInterceptor.afterMethod(enhancedInstance, null, new Object[] { Format.Builtin.TEXT_MAP, carrier }, new Class[] {}, null);
    stopSpan();
    TraceSegment tracingSegment = assertTraceSemgnets();
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(tracingSegment);
    assertThat(tracingSegment.getRefs().size(), is(1));
    TraceSegmentRef ref = tracingSegment.getRefs().get(0);
    SegmentRefAssert.assertSegmentId(ref, "1.343.222");
    SegmentRefAssert.assertSpanId(ref, 3);
    SegmentRefAssert.assertEntryApplicationInstanceId(ref, 1);
    SegmentRefAssert.assertPeerHost(ref, "127.0.0.1:8080");
    assertThat(spans.size(), is(1));
    assertSpanCommonsAttribute(spans.get(0));
}
Also used : HashMap(java.util.HashMap) TraceSegmentRef(org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TextMap(io.opentracing.propagation.TextMap) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 9 with TextMap

use of io.opentracing.propagation.TextMap in project incubator-skywalking by apache.

the class SkywalkingSpanActivationTest method testInject.

@Test
public void testInject() throws Throwable {
    spanBuilder.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).withTag(Tags.PEER_HOST_IPV4.getKey(), "127.0.0.1").withTag(Tags.PEER_PORT.getKey(), 8080);
    startSpan();
    final Map<String, String> values = new HashMap<String, String>();
    TextMap carrier = new TextMap() {

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

        @Override
        public void put(String key, String value) {
            values.put(key, value);
        }
    };
    injectInterceptor.afterMethod(enhancedInstance, null, new Object[] { new TextMapContext(), Format.Builtin.TEXT_MAP, carrier }, null, null);
    String[] parts = values.get(SW3CarrierItem.HEADER_NAME).split("\\|", 8);
    Assert.assertEquals("0", parts[1]);
    Assert.assertEquals("#127.0.0.1:8080", parts[4]);
    Assert.assertTrue(new ID(parts[7]).isValid());
    stopSpan();
}
Also used : HashMap(java.util.HashMap) TextMapContext(org.apache.skywalking.apm.toolkit.opentracing.TextMapContext) TextMap(io.opentracing.propagation.TextMap) ID(org.apache.skywalking.apm.agent.core.context.ids.ID) Test(org.junit.Test)

Example 10 with TextMap

use of io.opentracing.propagation.TextMap in project incubator-skywalking by apache.

the class SkywalkingSpanActivationTest method testExtractWithInValidateContext.

@Test
public void testExtractWithInValidateContext() throws Throwable {
    spanBuilder.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).withTag(Tags.PEER_HOST_IPV4.getKey(), "127.0.0.1").withTag(Tags.PEER_PORT.getKey(), 8080);
    startSpan();
    final Map<String, String> values = new HashMap<String, String>();
    TextMap carrier = new TextMap() {

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

        @Override
        public void put(String key, String value) {
            values.put(key, value);
        }
    };
    values.put(SW3CarrierItem.HEADER_NAME, "aaaaaaaa|3|#192.168.1.8:18002|#/portal/|#/testEntrySpan|1.234.444");
    extractInterceptor.afterMethod(enhancedInstance, null, new Object[] { Format.Builtin.TEXT_MAP, carrier }, new Class[] {}, null);
    stopSpan();
    TraceSegment tracingSegment = assertTraceSemgnets();
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(tracingSegment);
    assertNull(tracingSegment.getRefs());
    assertSpanCommonsAttribute(spans.get(0));
}
Also used : HashMap(java.util.HashMap) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TextMap(io.opentracing.propagation.TextMap) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

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