use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverter method convertSpan.
public static com.twitter.zipkin.thriftjava.Span convertSpan(JaegerSpan jaegerSpan) {
JaegerTracer tracer = jaegerSpan.getTracer();
Endpoint host = new Endpoint(tracer.getIpv4(), (short) 0, tracer.getServiceName());
JaegerSpanContext context = jaegerSpan.context();
return new com.twitter.zipkin.thriftjava.Span(context.getTraceIdLow(), jaegerSpan.getOperationName(), context.getSpanId(), buildAnnotations(jaegerSpan, host), buildBinaryAnnotations(jaegerSpan, host)).setParent_id(context.getParentId()).setTrace_id_high(context.getTraceIdHigh()).setDebug(context.isDebug()).setTimestamp(jaegerSpan.getStart()).setDuration(jaegerSpan.getDuration());
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class V2SpanConverter method convertSpan.
public static zipkin2.Span convertSpan(JaegerSpan span) {
JaegerTracer tracer = span.getTracer();
zipkin2.Endpoint.Builder host = zipkin2.Endpoint.newBuilder().serviceName(tracer.getServiceName());
if (tracer.getIpv4() != 0) {
host.parseIp(convertIp(tracer.getIpv4()));
}
zipkin2.Endpoint peerEndpoint = extractPeerEndpoint(span.getTags());
JaegerSpanContext context = span.context();
zipkin2.Span.Builder builder = zipkin2.Span.newBuilder().id(Long.toHexString(context.getSpanId())).traceId(context.getTraceIdHigh(), context.getTraceIdLow()).name(span.getOperationName()).parentId(Long.toHexString(context.getParentId())).debug(context.isDebug()).localEndpoint(host.build()).remoteEndpoint(peerEndpoint).kind(convertKind(span.getTags().get(Tags.SPAN_KIND.getKey()))).timestamp(span.getStart()).duration(span.getDuration());
buildAnnotations(span, builder);
buildTags(span, builder);
return builder.build();
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverterTest method testRpcChildSpanHasTheSameId.
@Test
public void testRpcChildSpanHasTheSameId() {
String expectedOperation = "parent";
JaegerSpan client = tracer.buildSpan(expectedOperation).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start();
Map<String, String> map = new HashMap<>();
TextMap carrier = new TextMapAdapter(map);
tracer.inject(client.context(), Format.Builtin.TEXT_MAP, carrier);
JaegerSpanContext ctx = tracer.extract(Format.Builtin.TEXT_MAP, carrier);
JaegerSpanContext clientCtx = client.context();
assertEquals(clientCtx.getSpanId(), ctx.getSpanId());
JaegerSpan server = tracer.buildSpan("child").withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).asChildOf(ctx).start();
JaegerSpanContext serverCtx = server.context();
assertEquals("client and server must have the same span ID", clientCtx.getSpanId(), serverCtx.getSpanId());
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class V2SpanConverterTest method testRpcChildSpanHasTheSameId.
@Test
@SuppressWarnings("Duplicates")
public void testRpcChildSpanHasTheSameId() {
String expectedOperation = "parent";
JaegerSpan client = tracer.buildSpan(expectedOperation).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start();
Map<String, String> map = new HashMap<>();
TextMap carrier = new TextMapAdapter(map);
tracer.inject(client.context(), Format.Builtin.TEXT_MAP, carrier);
JaegerSpanContext ctx = tracer.extract(Format.Builtin.TEXT_MAP, carrier);
JaegerSpanContext clientCtx = client.context();
assertEquals(clientCtx.getSpanId(), ctx.getSpanId());
JaegerSpan server = tracer.buildSpan("child").withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).asChildOf(ctx).start();
JaegerSpanContext serverCtx = server.context();
assertEquals("client and server must have the same span ID", clientCtx.getSpanId(), serverCtx.getSpanId());
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class V2SpanConverterTest method testConvertSpanWith128BitTraceId.
@Test
public void testConvertSpanWith128BitTraceId() {
// zipkinSpan.traceId() always returns full length ID (padded with 0s).
// To make the test stable, use a short idHigh portion.
JaegerSpanContext c = new JaegerSpanContext(1L, 1L, 1L, 0L, (byte) 0x01);
JaegerSpan span = tracer128.buildSpan("operation-name").asChildOf(c).start();
zipkin2.Span zipkinSpan = V2SpanConverter.convertSpan(span);
assertNotEquals(0, span.context().getTraceIdHigh());
assertEquals(span.context().getTraceId(), zipkinSpan.traceId());
}
Aggregations