Search in sources :

Example 1 with JaegerTracer

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

the class MicrometerTest method testExposedMetrics.

@Test
public void testExposedMetrics() {
    Configuration configuration = new Configuration("exposedmetrics");
    final JaegerTracer tracer = configuration.getTracerBuilder().withMetrics(metrics).build();
    // This is a gauge, so it needs to be non-zero to come back from prometheus
    metrics.reporterQueueLength.update(1);
    List<Meter> meters = new ArrayList<>(prometheusRegistry.getMeters());
    Map<String, Long> metricCounts = meters.stream().collect(groupingBy(m -> m.getId().getName(), counting()));
    assertEquals("Wrong number of metrics collected", expectedMetricCounts.size(), metricCounts.keySet().size());
    for (String name : metricCounts.keySet()) {
        assertTrue("Unexpected metric " + name, expectedMetricCounts.containsKey(name));
    }
    for (String metricName : expectedMetricCounts.keySet()) {
        assertTrue("Did not find metric " + metricName, metricCounts.containsKey(metricName));
        assertEquals("Wrong count for " + metricName, expectedMetricCounts.get(metricName), metricCounts.get(metricName));
    }
    tracer.close();
}
Also used : Metrics(io.jaegertracing.internal.metrics.Metrics) MethodSorters(org.junit.runners.MethodSorters) BeforeClass(org.junit.BeforeClass) Collectors.counting(java.util.stream.Collectors.counting) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) HashMap(java.util.HashMap) JaegerSpan(io.jaegertracing.internal.JaegerSpan) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) Map(java.util.Map) After(org.junit.After) Sampler(io.jaegertracing.spi.Sampler) IsEqual(org.hamcrest.core.IsEqual) Timer(io.jaegertracing.internal.metrics.Timer) Before(org.junit.Before) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) Assert.assertTrue(org.junit.Assert.assertTrue) Meter(io.micrometer.core.instrument.Meter) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) Configuration(io.jaegertracing.Configuration) FixMethodOrder(org.junit.FixMethodOrder) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Assert.assertEquals(org.junit.Assert.assertEquals) PrometheusConfig(io.micrometer.prometheus.PrometheusConfig) Configuration(io.jaegertracing.Configuration) Meter(io.micrometer.core.instrument.Meter) ArrayList(java.util.ArrayList) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Test(org.junit.Test)

Example 2 with JaegerTracer

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

the class MicrometerTest method validateMetricCounts.

@Test
public void validateMetricCounts() throws InterruptedException {
    Sampler constantSampler = new ConstSampler(true);
    Configuration configuration = new Configuration("validateMetricCounts");
    JaegerTracer tracer = configuration.getTracerBuilder().withSampler(constantSampler).withMetrics(metrics).build();
    createSomeSpans(tracer);
    tracer.close();
    double finishedSpans = registry.get("jaeger_tracer_finished_spans").counter().count();
    double startedSpans = registry.get("jaeger_tracer_started_spans").tag("sampled", "y").counter().count();
    double traces = registry.get("jaeger_tracer_traces").tag("sampled", "y").tag("state", "started").counter().count();
    assertEquals("Wrong number of finishedSpans", 4.0, finishedSpans, assertDelta);
    assertEquals("Wrong number of startedSpans", 10.0, startedSpans, assertDelta);
    assertEquals("Wrong number of traces", 10.0, traces, assertDelta);
}
Also used : Configuration(io.jaegertracing.Configuration) Sampler(io.jaegertracing.spi.Sampler) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Test(org.junit.Test)

Example 3 with JaegerTracer

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

the class TraceContextCodecTest method testDebugIdWithoutTraceHeader.

@Test
public void testDebugIdWithoutTraceHeader() {
    Map<String, String> extractCarrier = new HashMap<>();
    TextMapAdapter textMap = new TextMapAdapter(extractCarrier);
    textMap.put(Constants.DEBUG_ID_HEADER_KEY, EXAMPLE_DEBUG_ID);
    JaegerSpanContext spanContext = traceContextCodec.extract(textMap);
    JaegerTracer tracer = new JaegerTracer.Builder("service").withReporter(new InMemoryReporter()).build();
    JaegerSpan child = tracer.buildSpan("span").asChildOf(spanContext).start();
    assertTrue(child.context().isDebug());
    child.finish();
    tracer.close();
}
Also used : InMemoryReporter(io.jaegertracing.internal.reporters.InMemoryReporter) HashMap(java.util.HashMap) JaegerSpan(io.jaegertracing.internal.JaegerSpan) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Test(org.junit.Test)

Example 4 with JaegerTracer

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

the class NoopMetricsFactoryTest method canBeUsedWithMetrics.

@Test
public void canBeUsedWithMetrics() {
    NoopMetricsFactory metricsFactory = new NoopMetricsFactory();
    JaegerTracer tracer = new JaegerTracer.Builder("metricsFactoryTest").withReporter(new InMemoryReporter()).withSampler(new ConstSampler(true)).withMetrics(new Metrics(metricsFactory)).build();
    tracer.buildSpan("theoperation").start();
}
Also used : InMemoryReporter(io.jaegertracing.internal.reporters.InMemoryReporter) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Test(org.junit.Test)

Example 5 with JaegerTracer

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

the class ConfigurationTest method testTracerUse128BitTraceId.

@Test
public void testTracerUse128BitTraceId() {
    System.setProperty(Configuration.JAEGER_SERVICE_NAME, "Test");
    System.setProperty(Configuration.JAEGER_TRACEID_128BIT, "true");
    JaegerTracer tracer = Configuration.fromEnv().getTracer();
    assertTrue(tracer.isUseTraceId128Bit());
}
Also used : JaegerTracer(io.jaegertracing.internal.JaegerTracer) Test(org.junit.Test)

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