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"));
}
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));
}
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();
}
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();
}
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);
}
Aggregations