use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.
the class UdpSenderTest method testAppendSpanTooLarge.
@Test(expected = SenderException.class)
public void testAppendSpanTooLarge() throws Exception {
Process process = new Process(tracer.getServiceName()).setTags(JaegerThriftSpanConverter.buildTags(tracer.tags()));
int processSize = sender.getSize(process);
JaegerSpan jaegerSpan = buildSpanWithSize(maxPacketSize - UdpSender.EMIT_BATCH_OVERHEAD - processSize + 1);
try {
sender.append(jaegerSpan);
} catch (SenderException e) {
assertEquals(e.getDroppedSpanCount(), 1);
throw e;
}
}
use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.
the class V2SpanConverterTest method testSpanDetectsIsClient.
@Test
public void testSpanDetectsIsClient() {
JaegerSpan span = tracer.buildSpan("test-service-operation").start();
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT);
assertTrue(ConverterUtil.isRpc(span));
assertTrue(ConverterUtil.isRpcClient(span));
}
use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.
the class JaegerTracerTagsTest method testTracerTags.
@Test
public void testTracerTags() {
InMemoryReporter spanReporter = new InMemoryReporter();
JaegerTracer tracer = new JaegerTracer.Builder("x").withReporter(spanReporter).withSampler(new ConstSampler(true)).withZipkinSharedRpcSpan().withTag("tracer.tag.str", "y").build();
JaegerSpan jaegerSpan = tracer.buildSpan("root").start();
// span should only contain sampler tags and no tracer tags
assertEquals(2, jaegerSpan.getTags().size());
assertEquals(true, jaegerSpan.getTags().containsKey("sampler.type"));
assertEquals(true, jaegerSpan.getTags().containsKey("sampler.param"));
assertEquals(false, jaegerSpan.getTags().containsKey("tracer.tag.str"));
}
use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.
the class UdpSenderTest method buildSpanWithSize.
/**
* create a mock span with target size
*/
private JaegerSpan buildSpanWithSize(int targetSpanSize) throws Exception {
JaegerSpan jaegerSpan = tracer.buildSpan("raza").start();
jaegerSpan.setTag("mock", "");
// contains mock span tag with empty string value, which is later used to match target span size
io.jaegertracing.thriftjava.Span emptySpan = JaegerThriftSpanConverter.convertSpan(jaegerSpan);
int emptySpanSize = sender.getSize(emptySpan);
int freePacketSizeLeft = targetSpanSize - emptySpanSize;
// each "0" takes 1 byte in UTF-8
String mockStr = String.join("", Collections.nCopies(freePacketSizeLeft, "0"));
jaegerSpan.setTag("mock", mockStr);
// subtract some chars since the actual encoding takes a few extra bytes
while (targetSpanSize != sender.getSize(JaegerThriftSpanConverter.convertSpan(jaegerSpan))) {
mockStr = mockStr.substring(1);
jaegerSpan.setTag("mock", mockStr);
}
return jaegerSpan;
}
use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.
the class UdpSenderTest method testFlushSendsSpan.
@Test
public void testFlushSendsSpan() throws Exception {
// in milliseconds
int timeout = 50;
int expectedNumSpans = 1;
JaegerSpan expectedSpan = tracer.buildSpan("raza").start();
int appendNum = sender.append(expectedSpan);
int flushNum = sender.flush();
assertEquals(appendNum, 0);
assertEquals(flushNum, 1);
Batch batch = server.getBatch(expectedNumSpans, timeout);
assertEquals(expectedNumSpans, batch.getSpans().size());
io.jaegertracing.thriftjava.Span actualSpan = batch.getSpans().get(0);
assertEquals(expectedSpan.context().getTraceIdLow(), actualSpan.getTraceIdLow());
assertEquals(0, actualSpan.getTraceIdHigh());
assertEquals(expectedSpan.context().getSpanId(), actualSpan.getSpanId());
assertEquals(0, actualSpan.getParentSpanId());
assertTrue(actualSpan.getReferences().isEmpty());
assertEquals(expectedSpan.getOperationName(), actualSpan.getOperationName());
assertEquals(4, batch.getProcess().getTags().size());
assertEquals("hostname", batch.getProcess().getTags().get(0).getKey());
assertEquals("jaeger.version", batch.getProcess().getTags().get(1).getKey());
assertEquals("bar", batch.getProcess().getTags().get(2).getVStr());
assertEquals("ip", batch.getProcess().getTags().get(3).getKey());
}
Aggregations