Search in sources :

Example 26 with ConstSampler

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

the class JaegerTracerTest method testWithBaggageRestrictionManager.

@Test
public void testWithBaggageRestrictionManager() {
    tracer = new JaegerTracer.Builder("TracerTestService").withReporter(new InMemoryReporter()).withSampler(new ConstSampler(true)).withMetrics(new Metrics(metricsFactory)).build();
    JaegerSpan span = tracer.buildSpan("some-operation").start();
    final String key = "key";
    tracer.setBaggage(span, key, "value");
    assertEquals(1, metricsFactory.getCounter("jaeger_tracer_baggage_updates", "result=ok"));
}
Also used : InMemoryReporter(io.jaegertracing.internal.reporters.InMemoryReporter) Metrics(io.jaegertracing.internal.metrics.Metrics) Builder(io.jaegertracing.internal.JaegerTracer.Builder) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) Test(org.junit.Test)

Example 27 with ConstSampler

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

the class JaegerTracerTest method testRegisterInjector.

@Test
public void testRegisterInjector() {
    @SuppressWarnings("unchecked") Injector<TextMap> injector = mock(Injector.class);
    JaegerTracer tracer = new JaegerTracer.Builder("TracerTestService").withReporter(new InMemoryReporter()).withSampler(new ConstSampler(true)).withMetrics(new Metrics(new InMemoryMetricsFactory())).registerInjector(Format.Builtin.TEXT_MAP, injector).build();
    JaegerSpan span = tracer.buildSpan("leela").start();
    TextMap carrier = mock(TextMap.class);
    tracer.inject(span.context(), Format.Builtin.TEXT_MAP, carrier);
    verify(injector).inject(any(JaegerSpanContext.class), any(TextMap.class));
}
Also used : InMemoryReporter(io.jaegertracing.internal.reporters.InMemoryReporter) Metrics(io.jaegertracing.internal.metrics.Metrics) InMemoryMetricsFactory(io.jaegertracing.internal.metrics.InMemoryMetricsFactory) Builder(io.jaegertracing.internal.JaegerTracer.Builder) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) TextMap(io.opentracing.propagation.TextMap) Test(org.junit.Test)

Example 28 with ConstSampler

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

the class BaggageSetterTest method setUp.

@Before
public void setUp() {
    metricsFactory = new InMemoryMetricsFactory();
    reporter = new InMemoryReporter();
    metrics = new Metrics(metricsFactory);
    mgr = mock(DefaultBaggageRestrictionManager.class);
    setter = new BaggageSetter(mgr, metrics);
    tracer = new JaegerTracer.Builder(SERVICE).withReporter(reporter).withSampler(new ConstSampler(true)).withMetrics(metrics).build();
    jaegerSpan = tracer.buildSpan("some-operation").start();
}
Also used : InMemoryReporter(io.jaegertracing.internal.reporters.InMemoryReporter) InMemoryMetricsFactory(io.jaegertracing.internal.metrics.InMemoryMetricsFactory) Metrics(io.jaegertracing.internal.metrics.Metrics) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Before(org.junit.Before)

Example 29 with ConstSampler

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

the class RemoteReporterTest method setUp.

@Before
public void setUp() {
    metricsFactory = new InMemoryMetricsFactory();
    metrics = new Metrics(metricsFactory);
    sender = new InMemorySender();
    reporter = new RemoteReporter.Builder().withSender(sender).withFlushInterval(flushInterval).withMaxQueueSize(maxQueueSize).withMetrics(metrics).build();
    tracer = new JaegerTracer.Builder("test-remote-reporter").withReporter(reporter).withSampler(new ConstSampler(true)).withMetrics(metrics).build();
}
Also used : InMemoryMetricsFactory(io.jaegertracing.internal.metrics.InMemoryMetricsFactory) Metrics(io.jaegertracing.internal.metrics.Metrics) Builder(io.jaegertracing.internal.reporters.RemoteReporter.Builder) InMemorySender(io.jaegertracing.internal.senders.InMemorySender) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Before(org.junit.Before)

Example 30 with ConstSampler

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

the class RemoteReporterTest method testFlushErrorsLoggedJustOnce.

@Test
public void testFlushErrorsLoggedJustOnce() throws InterruptedException {
    Object logMonitor = new Object();
    AtomicReference<String> logMsg = new AtomicReference<>(null);
    mockLogger(e -> {
        synchronized (logMonitor) {
            logMsg.set(e.getFormattedMessage());
            logMonitor.notifyAll();
        }
    });
    class FailingSender extends InMemorySender {

        private final AtomicInteger flushCounter = new AtomicInteger(0);

        @Override
        public int flush() throws SenderException {
            int i = super.flush();
            switch(flushCounter.getAndIncrement()) {
                case 1:
                case 2:
                case 3:
                    throw new SenderException("test1", i);
                default:
                    return i;
            }
        }

        private String awaitMessage(AtomicReference<String> ref) throws InterruptedException {
            synchronized (logMonitor) {
                while (ref.get() == null) {
                    logMonitor.wait();
                }
                return ref.getAndSet(null);
            }
        }
    }
    FailingSender sender = new FailingSender();
    RemoteReporter remoteReporter = new Builder().withSender(sender).withFlushInterval(Integer.MAX_VALUE).withMaxQueueSize(maxQueueSize).withMetrics(metrics).build();
    tracer = new JaegerTracer.Builder("test-remote-reporter").withReporter(remoteReporter).withSampler(new ConstSampler(true)).withMetrics(metrics).build();
    assertEquals(0, sender.flushCounter.get());
    tracer.buildSpan("mySpan").start().finish();
    remoteReporter.flush();
    // 1. SenderException is thrown (log should be produced)
    await().with().pollInterval(1, TimeUnit.MILLISECONDS).until(() -> sender.flushCounter.get() == 1);
    tracer.buildSpan("mySpan").start().finish();
    remoteReporter.flush();
    assertEquals("FlushCommand execution failed! Repeated errors of this command will not be logged.", sender.awaitMessage(logMsg));
    // 2. SenderException is thrown (log should not be produced)
    await().with().pollInterval(1, TimeUnit.MILLISECONDS).until(() -> sender.flushCounter.get() == 2);
    remoteReporter.flush();
    // 3. SenderException is thrown (log should not be produced)
    await().with().pollInterval(1, TimeUnit.MILLISECONDS).until(() -> sender.flushCounter.get() == 3);
    remoteReporter.flush();
    // No SenderException is thrown now, but 0 span is ready -> still stay in failing state
    await().with().pollInterval(1, TimeUnit.MILLISECONDS).until(() -> sender.flushCounter.get() == 4);
    remoteReporter.flush();
    // No SenderException is thrown now, but 1 span is ready -> move to working state
    tracer.buildSpan("mySpan").start().finish();
    remoteReporter.flush();
    assertEquals("FlushCommand is working again!", sender.awaitMessage(logMsg));
    await().with().pollInterval(1, TimeUnit.MILLISECONDS).until(() -> sender.getFlushed().size() == 3);
}
Also used : Builder(io.jaegertracing.internal.reporters.RemoteReporter.Builder) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InMemorySender(io.jaegertracing.internal.senders.InMemorySender) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) SenderException(io.jaegertracing.internal.exceptions.SenderException) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Test(org.junit.Test)

Aggregations

ConstSampler (io.jaegertracing.internal.samplers.ConstSampler)33 InMemoryReporter (io.jaegertracing.internal.reporters.InMemoryReporter)22 JaegerTracer (io.jaegertracing.internal.JaegerTracer)21 Test (org.junit.Test)19 Before (org.junit.Before)13 InMemoryMetricsFactory (io.jaegertracing.internal.metrics.InMemoryMetricsFactory)9 Metrics (io.jaegertracing.internal.metrics.Metrics)7 JaegerSpan (io.jaegertracing.internal.JaegerSpan)6 Builder (io.jaegertracing.internal.reporters.RemoteReporter.Builder)5 InMemorySender (io.jaegertracing.internal.senders.InMemorySender)4 Builder (io.jaegertracing.internal.JaegerTracer.Builder)3 TextMap (io.opentracing.propagation.TextMap)3 HashMap (java.util.HashMap)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 DefaultBaggageRestrictionManager (io.jaegertracing.internal.baggage.DefaultBaggageRestrictionManager)2 SenderException (io.jaegertracing.internal.exceptions.SenderException)2 Sampler (io.jaegertracing.spi.Sampler)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2