Search in sources :

Example 1 with JaegerSpan

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

the class RemoteReporterTest method testUpdateErrorMetricWhenCommandExecuteFails.

@Test
public void testUpdateErrorMetricWhenCommandExecuteFails() throws Exception {
    int reporterFailures = 5;
    sender = new InMemorySender() {

        @Override
        public int append(JaegerSpan span) throws SenderException {
            throw new SenderException("", reporterFailures);
        }
    };
    RemoteReporter reporter = new Builder().withSender(sender).withFlushInterval(flushInterval).withMaxQueueSize(maxQueueSize).withMetrics(metrics).build();
    reporter.report(newSpan());
    reporter.close();
    assertEquals(reporterFailures, metricsFactory.getCounter("jaeger_tracer_reporter_spans", "result=err"));
}
Also used : Builder(io.jaegertracing.internal.reporters.RemoteReporter.Builder) JaegerSpan(io.jaegertracing.internal.JaegerSpan) InMemorySender(io.jaegertracing.internal.senders.InMemorySender) SenderException(io.jaegertracing.internal.exceptions.SenderException) Test(org.junit.Test)

Example 2 with JaegerSpan

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

the class RemoteReporterTest method testRemoteReporterFlushesOnClose.

@Test
public void testRemoteReporterFlushesOnClose() {
    int numberOfSpans = 100;
    for (int i = 0; i < numberOfSpans; i++) {
        JaegerSpan span = tracer.buildSpan("raza").start();
        reporter.report(span);
    }
    reporter.close();
    assertEquals(0, sender.getAppended().size());
    assertEquals(numberOfSpans, sender.getFlushed().size());
    assertEquals(100, metricsFactory.getCounter("jaeger_tracer_started_spans", "sampled=y"));
    assertEquals(100, metricsFactory.getCounter("jaeger_tracer_reporter_spans", "result=ok"));
    assertEquals(100, metricsFactory.getCounter("jaeger_tracer_traces", "sampled=y,state=started"));
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) Test(org.junit.Test)

Example 3 with JaegerSpan

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

the class RemoteReporterTest method testRemoteReporterReport.

@Test
public void testRemoteReporterReport() {
    JaegerSpan span = tracer.buildSpan("raza").start();
    reporter.report(span);
    // do sleep until automatic flush happens on 'reporter'
    // added 20ms on top of 'flushInterval' to avoid corner cases
    await().with().pollInterval(1, TimeUnit.MILLISECONDS).atMost(flushInterval + 20, TimeUnit.MILLISECONDS).until(() -> sender.getReceived().size() > 0);
    List<JaegerSpan> received = sender.getReceived();
    assertEquals(1, received.size());
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) Test(org.junit.Test)

Example 4 with JaegerSpan

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

the class BaggageSetterTest method testOverrideBaggage.

@Test
public void testOverrideBaggage() {
    when(mgr.getRestriction(SERVICE, KEY)).thenReturn(Restriction.of(true, 5));
    final String value = "value";
    JaegerSpanContext ctx = setter.setBaggage(jaegerSpan, KEY, value);
    JaegerSpan child = tracer.buildSpan("some-operation").asChildOf(ctx).start();
    ctx = setter.setBaggage(child, KEY, value);
    assertBaggageLogs(child, KEY, value, false, true, false);
    assertEquals(value, ctx.getBaggageItem(KEY));
    assertEquals(2, metricsFactory.getCounter("jaeger_tracer_baggage_updates", "result=ok"));
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 5 with JaegerSpan

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

the class BaggageSetterTest method testBaggageNullRemoveValue.

@Test
public void testBaggageNullRemoveValue() {
    when(mgr.getRestriction(SERVICE, KEY)).thenReturn(Restriction.of(true, 5));
    final String value = "value";
    JaegerSpan originalSpan = jaegerSpan.setBaggageItem(KEY, value);
    assertEquals(value, originalSpan.getBaggageItem(KEY));
    JaegerSpan child = tracer.buildSpan("some-operation").asChildOf(originalSpan).start();
    child = child.setBaggageItem(KEY, null);
    assertBaggageLogs(child, KEY, null, false, true, false);
    assertNull(child.getBaggageItem(KEY));
    assertEquals(2, metricsFactory.getCounter("jaeger_tracer_baggage_updates", "result=ok"));
}
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