Search in sources :

Example 1 with ID

use of org.apache.skywalking.apm.agent.core.context.ids.ID 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 2 with ID

use of org.apache.skywalking.apm.agent.core.context.ids.ID in project incubator-skywalking by apache.

the class ContextCarrier method deserialize.

/**
 * Initialize fields with the given text.
 *
 * @param text carries {@link #traceSegmentId} and {@link #spanId}, with '|' split.
 */
ContextCarrier deserialize(String text) {
    if (text != null) {
        String[] parts = text.split("\\|", 8);
        if (parts.length == 8) {
            try {
                this.traceSegmentId = new ID(parts[0]);
                this.spanId = Integer.parseInt(parts[1]);
                this.parentApplicationInstanceId = Integer.parseInt(parts[2]);
                this.entryApplicationInstanceId = Integer.parseInt(parts[3]);
                this.peerHost = parts[4];
                this.entryOperationName = parts[5];
                this.parentOperationName = parts[6];
                this.primaryDistributedTraceId = new PropagatedTraceId(parts[7]);
            } catch (NumberFormatException e) {
            }
        }
    }
    return this;
}
Also used : PropagatedTraceId(org.apache.skywalking.apm.agent.core.context.ids.PropagatedTraceId) ID(org.apache.skywalking.apm.agent.core.context.ids.ID)

Aggregations

ID (org.apache.skywalking.apm.agent.core.context.ids.ID)2 TextMap (io.opentracing.propagation.TextMap)1 HashMap (java.util.HashMap)1 PropagatedTraceId (org.apache.skywalking.apm.agent.core.context.ids.PropagatedTraceId)1 TextMapContext (org.apache.skywalking.apm.toolkit.opentracing.TextMapContext)1 Test (org.junit.Test)1