use of io.jaegertracing.internal.JaegerSpan 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();
}
use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.
the class TraceBehavior method observeSpan.
private ObservedSpan observeSpan() {
JaegerSpan span = (JaegerSpan) tracer.activeSpan();
if (tracer.activeSpan() == null) {
log.error("No span found");
return new ObservedSpan("no span found", false, "no span found");
}
JaegerSpanContext context = span.context();
String traceId = context.getTraceId();
boolean sampled = context.isSampled();
String baggage = span.getBaggageItem(Constants.BAGGAGE_KEY);
return new ObservedSpan(traceId, sampled, baggage);
}
use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.
the class ZipkinV2ReporterTest method testConvertsAndSendsSpan.
@Test
public void testConvertsAndSendsSpan() {
JaegerSpan span = tracer.buildSpan("raza").start();
span.finish();
reporter.report(span);
zipkinReporter.flush();
List<List<zipkin2.Span>> spans = zipkinRule.getTraces();
assertEquals(spans.get(0).get(0).name(), "raza");
}
use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.
the class ZipkinSenderTest method testFlushSendsSpan.
@Test
public void testFlushSendsSpan() throws Exception {
JaegerSpan expectedSpan = tracer.buildSpan("raza").start();
assertEquals(0, sender.append(expectedSpan));
assertEquals(1, sender.flush());
List<List<zipkin2.Span>> traces = zipkinRule.getTraces();
assertEquals(traces.size(), 1);
assertEquals(traces.get(0).size(), 1);
zipkin2.Span actualSpan = traces.get(0).get(0);
JaegerSpanContext context = expectedSpan.context();
assertEquals(context.getTraceIdLow(), HexCodec.lowerHexToUnsignedLong(actualSpan.traceId()));
assertEquals(context.getTraceIdHigh(), 0L);
assertEquals(context.getSpanId(), HexCodec.lowerHexToUnsignedLong(actualSpan.id()));
assertEquals(context.getParentId(), 0L);
assertNull(actualSpan.parentId());
assertEquals(expectedSpan.getOperationName(), actualSpan.name());
assertEquals(tracer.getServiceName(), actualSpan.localServiceName());
}
use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.
the class ZipkinSenderTest method testAppend.
@Test
public void testAppend() throws Exception {
JaegerSpan jaegerSpan = tracer.buildSpan("raza").start();
com.twitter.zipkin.thriftjava.Span span = ThriftSpanConverter.convertSpan(jaegerSpan);
int expectedNumSpans = 11;
List<byte[]> spansToSend = new ArrayList<>(expectedNumSpans);
for (int i = 0; i < expectedNumSpans; i++) {
spansToSend.add(new ThriftSpanEncoder().encode(ZipkinSender.backFillHostOnAnnotations(span)));
}
// create a sender that's a multiple of the span size (accounting for span overhead)
// this allows us to test the boundary conditions of writing spans.
int messageMaxBytes = sender.delegate.messageSizeInBytes(spansToSend);
sender.close();
sender = newSender(messageMaxBytes);
// add enough spans to be under buffer limit
for (int i = 0; i < expectedNumSpans - 1; i++) {
assertEquals(0, sender.append(jaegerSpan));
}
// add a span that overflows the limit to hit the last branch
int result = sender.append(jaegerSpan);
assertEquals(expectedNumSpans, result);
}
Aggregations