Search in sources :

Example 26 with JaegerTracer

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

the class JaegerTracerResolverTest method canFindTracerFactory.

@Test
public void canFindTracerFactory() {
    System.setProperty(Configuration.JAEGER_SERVICE_NAME, "canFindTracerFactory");
    Tracer tracer = ServiceLoader.load(TracerFactory.class).iterator().next().getTracer();
    assertNotNull(tracer);
    assertTrue(tracer instanceof JaegerTracer);
}
Also used : Tracer(io.opentracing.Tracer) JaegerTracer(io.jaegertracing.internal.JaegerTracer) TracerFactory(io.opentracing.contrib.tracerresolver.TracerFactory) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Test(org.junit.Test)

Example 27 with JaegerTracer

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

the class ThriftSpanConverter method convertSpan.

public static com.twitter.zipkin.thriftjava.Span convertSpan(JaegerSpan jaegerSpan) {
    JaegerTracer tracer = jaegerSpan.getTracer();
    Endpoint host = new Endpoint(tracer.getIpv4(), (short) 0, tracer.getServiceName());
    JaegerSpanContext context = jaegerSpan.context();
    return new com.twitter.zipkin.thriftjava.Span(context.getTraceIdLow(), jaegerSpan.getOperationName(), context.getSpanId(), buildAnnotations(jaegerSpan, host), buildBinaryAnnotations(jaegerSpan, host)).setParent_id(context.getParentId()).setTrace_id_high(context.getTraceIdHigh()).setDebug(context.isDebug()).setTimestamp(jaegerSpan.getStart()).setDuration(jaegerSpan.getDuration());
}
Also used : Endpoint(com.twitter.zipkin.thriftjava.Endpoint) JaegerTracer(io.jaegertracing.internal.JaegerTracer) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext)

Example 28 with JaegerTracer

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

the class V2SpanConverter method convertSpan.

public static zipkin2.Span convertSpan(JaegerSpan span) {
    JaegerTracer tracer = span.getTracer();
    zipkin2.Endpoint.Builder host = zipkin2.Endpoint.newBuilder().serviceName(tracer.getServiceName());
    if (tracer.getIpv4() != 0) {
        host.parseIp(convertIp(tracer.getIpv4()));
    }
    zipkin2.Endpoint peerEndpoint = extractPeerEndpoint(span.getTags());
    JaegerSpanContext context = span.context();
    zipkin2.Span.Builder builder = zipkin2.Span.newBuilder().id(Long.toHexString(context.getSpanId())).traceId(context.getTraceIdHigh(), context.getTraceIdLow()).name(span.getOperationName()).parentId(Long.toHexString(context.getParentId())).debug(context.isDebug()).localEndpoint(host.build()).remoteEndpoint(peerEndpoint).kind(convertKind(span.getTags().get(Tags.SPAN_KIND.getKey()))).timestamp(span.getStart()).duration(span.getDuration());
    buildAnnotations(span, builder);
    buildTags(span, builder);
    return builder.build();
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) JaegerTracer(io.jaegertracing.internal.JaegerTracer) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext)

Example 29 with JaegerTracer

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

the class ThriftSpanConverterTest method dataProviderTracerTags.

@DataProvider
public static Object[][] dataProviderTracerTags() {
    JaegerTracer tracer = new JaegerTracer.Builder("x").withReporter(null).withSampler(null).build();
    Map<String, String> rootTags = new HashMap<>();
    rootTags.put("tracer.jaeger.version", tracer.getVersion());
    rootTags.put("tracer.hostname", ANY);
    rootTags.put("tracer.tag.str", "y");
    rootTags.put("tracer.tag.bool", "true");
    rootTags.put("tracer.tag.num", "1");
    rootTags.put("sampler.type", "const");
    rootTags.put("sampler.param", "true");
    Map<String, String> childTags = new HashMap<>();
    childTags.put("tracer.jaeger.version", UNDEF);
    childTags.put("tracer.hostname", UNDEF);
    childTags.put("tracer.tag.str", UNDEF);
    childTags.put("tracer.tag.bool", UNDEF);
    childTags.put("tracer.tag.num", UNDEF);
    childTags.put("sampler.type", UNDEF);
    childTags.put("sampler.param", UNDEF);
    Map<String, String> rpcTags = new HashMap<>();
    rpcTags.put("tracer.jaeger.version", tracer.getVersion());
    rpcTags.put("tracer.hostname", ANY);
    rpcTags.put("tracer.tag.str", "y");
    rpcTags.put("tracer.tag.bool", "true");
    rpcTags.put("tracer.tag.num", "1");
    rpcTags.put("sampler.type", UNDEF);
    rpcTags.put("sampler.param", UNDEF);
    return new Object[][] { { SpanType.ROOT, rootTags }, { SpanType.CHILD, childTags }, { SpanType.RPC_SERVER, rpcTags } };
}
Also used : HashMap(java.util.HashMap) JaegerTracer(io.jaegertracing.internal.JaegerTracer) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 30 with JaegerTracer

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

the class V2SpanConverterTest method testTracerTags.

@Test
@UseDataProvider("dataProviderTracerTags")
public void testTracerTags(SpanType spanType, Map<String, String> expectedTags) {
    InMemoryReporter spanReporter = new InMemoryReporter();
    JaegerTracer tracer = new JaegerTracer.Builder("x").withReporter(spanReporter).withSampler(new ConstSampler(true)).withZipkinSharedRpcSpan().withTag("tag.str", "y").withTag("tag.bool", true).withTag("tag.num", 1).build();
    JaegerSpan span = tracer.buildSpan("root").start();
    if (spanType == SpanType.CHILD) {
        span = tracer.buildSpan("child").asChildOf(span).start();
    } else if (spanType == SpanType.RPC_SERVER) {
        span = tracer.buildSpan("rpc-server").asChildOf(span).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).start();
    }
    zipkin2.Span zipkinSpan = V2SpanConverter.convertSpan(span);
    Map<String, String> zipkinTags = zipkinSpan.tags();
    for (Map.Entry<String, String> entry : expectedTags.entrySet()) {
        String key = entry.getKey();
        Object expectedValue = entry.getValue();
        String tagValue = zipkinTags.get(key);
        if (expectedValue.equals(UNDEF)) {
            assertNull("Not expecting " + key + " for " + spanType, tagValue);
        } else if (expectedValue.equals(ANY)) {
            assertNotNull(key, tagValue);
        } else {
            assertEquals("Expecting " + key + " for " + spanType, expectedValue, tagValue);
        }
    }
}
Also used : InMemoryReporter(io.jaegertracing.internal.reporters.InMemoryReporter) JaegerSpan(io.jaegertracing.internal.JaegerSpan) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) HashMap(java.util.HashMap) Map(java.util.Map) TextMap(io.opentracing.propagation.TextMap) TreeMap(java.util.TreeMap) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

JaegerTracer (io.jaegertracing.internal.JaegerTracer)33 Test (org.junit.Test)29 InMemoryReporter (io.jaegertracing.internal.reporters.InMemoryReporter)12 ConstSampler (io.jaegertracing.internal.samplers.ConstSampler)8 JaegerSpan (io.jaegertracing.internal.JaegerSpan)7 JaegerSpanContext (io.jaegertracing.internal.JaegerSpanContext)7 HashMap (java.util.HashMap)7 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)4 List (java.util.List)3 Map (java.util.Map)3 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)2 Configuration (io.jaegertracing.Configuration)2 SenderException (io.jaegertracing.internal.exceptions.SenderException)2 Sampler (io.jaegertracing.spi.Sampler)2 Process (io.jaegertracing.thriftjava.Process)2 Tracer (io.opentracing.Tracer)2 TextMap (io.opentracing.propagation.TextMap)2 TextMapAdapter (io.opentracing.propagation.TextMapAdapter)2 TreeMap (java.util.TreeMap)2 BinaryAnnotation (com.twitter.zipkin.thriftjava.BinaryAnnotation)1