Search in sources :

Example 41 with JaegerSpan

use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.

the class ThriftSpanConverterTest method testSpanDetectsEndpointTags.

@Test
public void testSpanDetectsEndpointTags() {
    int expectedIp = (127 << 24) | 1;
    int expectedPort = 8080;
    String expectedServiceName = "some-peer-service";
    JaegerSpan span = tracer.buildSpan("test-service-operation").start();
    Tags.PEER_HOST_IPV4.set(span, expectedIp);
    Tags.PEER_PORT.set(span, expectedPort);
    Tags.PEER_SERVICE.set(span, expectedServiceName);
    assertEquals(expectedIp, ThriftSpanConverter.extractPeerEndpoint(span.getTags()).getIpv4());
    assertEquals(expectedPort, ThriftSpanConverter.extractPeerEndpoint(span.getTags()).getPort());
    assertEquals(expectedServiceName, ThriftSpanConverter.extractPeerEndpoint(span.getTags()).getService_name());
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) Test(org.junit.Test)

Example 42 with JaegerSpan

use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.

the class V2SpanConverterTest method testAddsTracerIpAsLocalIpV4.

@Test
public void testAddsTracerIpAsLocalIpV4() {
    tracer = new JaegerTracer.Builder("test-service-name").withReporter(new InMemoryReporter()).withSampler(new ConstSampler(true)).withZipkinSharedRpcSpan().withTag(Constants.TRACER_IP_TAG_KEY, "1.2.3.4").build();
    JaegerSpan span = tracer.buildSpan("operation-name").start();
    zipkin2.Span zipkinSpan = V2SpanConverter.convertSpan(span);
    assertEquals(zipkinSpan.localEndpoint().ipv4(), "1.2.3.4");
}
Also used : InMemoryReporter(io.jaegertracing.internal.reporters.InMemoryReporter) JaegerSpan(io.jaegertracing.internal.JaegerSpan) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) Test(org.junit.Test)

Example 43 with JaegerSpan

use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.

the class V2SpanConverterTest method testRpcChildSpanHasTheSameId.

@Test
@SuppressWarnings("Duplicates")
public void testRpcChildSpanHasTheSameId() {
    String expectedOperation = "parent";
    JaegerSpan client = tracer.buildSpan(expectedOperation).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start();
    Map<String, String> map = new HashMap<>();
    TextMap carrier = new TextMapAdapter(map);
    tracer.inject(client.context(), Format.Builtin.TEXT_MAP, carrier);
    JaegerSpanContext ctx = tracer.extract(Format.Builtin.TEXT_MAP, carrier);
    JaegerSpanContext clientCtx = client.context();
    assertEquals(clientCtx.getSpanId(), ctx.getSpanId());
    JaegerSpan server = tracer.buildSpan("child").withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).asChildOf(ctx).start();
    JaegerSpanContext serverCtx = server.context();
    assertEquals("client and server must have the same span ID", clientCtx.getSpanId(), serverCtx.getSpanId());
}
Also used : HashMap(java.util.HashMap) JaegerSpan(io.jaegertracing.internal.JaegerSpan) TextMap(io.opentracing.propagation.TextMap) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 44 with JaegerSpan

use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.

the class V2SpanConverterTest method testSpanLogsCreateAnnotations.

@Test
public void testSpanLogsCreateAnnotations() {
    JaegerSpan span = tracer.buildSpan("span-with-logs").start();
    span.log("event");
    // use sorted map for consistent ordering in test
    Map<String, Object> fields = new TreeMap<String, Object>();
    fields.put("event", "structured data");
    fields.put("string", "something");
    fields.put("number", 42);
    fields.put("boolean", true);
    span.log(fields);
    zipkin2.Span zipkinSpan = V2SpanConverter.convertSpan(span);
    List<String> annotationValues = new ArrayList<String>();
    for (Annotation annotation : zipkinSpan.annotations()) {
        annotationValues.add(annotation.value());
    }
    List<String> expectedValues = new ArrayList<String>();
    expectedValues.add("event");
    expectedValues.add("{\"boolean\":true,\"event\":\"structured data\",\"number\":42,\"string\":\"something\"}");
    assertEquals("zipkin span should contain matching annotations for span logs", expectedValues, annotationValues);
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Annotation(zipkin2.Annotation) Test(org.junit.Test)

Example 45 with JaegerSpan

use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.

the class V2SpanConverterTest method testExpectedLocalComponentNameUsed.

@Test
public void testExpectedLocalComponentNameUsed() {
    String expectedComponentName = "local-name";
    JaegerSpan span = tracer.buildSpan("operation-name").start();
    Tags.COMPONENT.set(span, expectedComponentName);
    zipkin2.Span zipkinSpan = V2SpanConverter.convertSpan(span);
    String actualComponent = zipkinSpan.tags().get(Tags.COMPONENT.getKey());
    assertEquals(expectedComponentName, actualComponent);
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) Test(org.junit.Test)

Aggregations

JaegerSpan (io.jaegertracing.internal.JaegerSpan)51 Test (org.junit.Test)47 JaegerSpanContext (io.jaegertracing.internal.JaegerSpanContext)10 HashMap (java.util.HashMap)8 JaegerTracer (io.jaegertracing.internal.JaegerTracer)7 InMemoryReporter (io.jaegertracing.internal.reporters.InMemoryReporter)7 ConstSampler (io.jaegertracing.internal.samplers.ConstSampler)6 ArrayList (java.util.ArrayList)6 TreeMap (java.util.TreeMap)5 BinaryAnnotation (com.twitter.zipkin.thriftjava.BinaryAnnotation)4 SenderException (io.jaegertracing.internal.exceptions.SenderException)4 TextMap (io.opentracing.propagation.TextMap)4 TextMapAdapter (io.opentracing.propagation.TextMapAdapter)4 List (java.util.List)4 Annotation (com.twitter.zipkin.thriftjava.Annotation)3 Process (io.jaegertracing.thriftjava.Process)3 Map (java.util.Map)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Builder (io.jaegertracing.internal.reporters.RemoteReporter.Builder)2 InMemorySender (io.jaegertracing.internal.senders.InMemorySender)2