result.setTraceInfo(RPCTraceInfoProto.newBuilder() .setTraceId(span.getSpanId().getHigh()) .setParentId(span.getSpanId().getLow()) .build());
/** * Converts a given HTrace span to a Zipkin Span. * <ul> * <li>First set the start annotation. [CS, SR], depending whether it is a client service or not. * <li>Set other id's, etc [TraceId's etc] * <li>Create binary annotations based on data from HTrace Span object. * <li>Set the last annotation. [SS, CR] * </ul> */ public Span convert(org.apache.htrace.core.Span hTraceSpan) { Span zipkinSpan = new Span(); String serviceName = hTraceSpan.getTracerId().toLowerCase(); Endpoint ep = new Endpoint(ipv4Address, (short) getPort(serviceName), serviceName); List<Annotation> annotationList = createZipkinAnnotations(hTraceSpan, ep); List<BinaryAnnotation> binaryAnnotationList = createZipkinBinaryAnnotations(hTraceSpan, ep); zipkinSpan.setTrace_id(hTraceSpan.getSpanId().getHigh()); if (hTraceSpan.getParents().length > 0) { if (hTraceSpan.getParents().length > 1) { LOG.error("zipkin doesn't support spans with multiple parents. Omitting " + "other parents for " + hTraceSpan); } zipkinSpan.setParent_id(hTraceSpan.getParents()[0].getLow()); } zipkinSpan.setId(hTraceSpan.getSpanId().getLow()); zipkinSpan.setName(hTraceSpan.getDescription()); zipkinSpan.setAnnotations(annotationList); zipkinSpan.setBinary_annotations(binaryAnnotationList); return zipkinSpan; }
@Override public void requestShortCircuitShm(String clientName) throws IOException { ShortCircuitShmRequestProto.Builder builder = ShortCircuitShmRequestProto.newBuilder(). setClientName(clientName); SpanId spanId = Tracer.getCurrentSpanId(); if (spanId.isValid()) { builder.setTraceInfo(DataTransferTraceInfoProto.newBuilder(). setTraceId(spanId.getHigh()). setParentId(spanId.getLow())); } ShortCircuitShmRequestProto proto = builder.build(); send(out, Op.REQUEST_SHORT_CIRCUIT_SHM, proto); }
/** * Converts a given HTrace span to a Zipkin Span. * <ul> * <li>First set the start annotation. [CS, SR], depending whether it is a client service or not. * <li>Set other id's, etc [TraceId's etc] * <li>Create binary annotations based on data from HTrace Span object. * <li>Set the last annotation. [SS, CR] * </ul> */ public Span convert(org.apache.htrace.core.Span hTraceSpan) { Span zipkinSpan = new Span(); String serviceName = hTraceSpan.getTracerId().toLowerCase(); Endpoint ep = new Endpoint(ipv4Address, (short) getPort(serviceName), serviceName); List<Annotation> annotationList = createZipkinAnnotations(hTraceSpan, ep); List<BinaryAnnotation> binaryAnnotationList = createZipkinBinaryAnnotations(hTraceSpan, ep); zipkinSpan.setTrace_id(hTraceSpan.getSpanId().getHigh()); if (hTraceSpan.getParents().length > 0) { if (hTraceSpan.getParents().length > 1) { LOG.error("zipkin doesn't support spans with multiple parents. Omitting " + "other parents for " + hTraceSpan); } zipkinSpan.setParent_id(hTraceSpan.getParents()[0].getLow()); } zipkinSpan.setId(hTraceSpan.getSpanId().getLow()); zipkinSpan.setName(hTraceSpan.getDescription()); zipkinSpan.setAnnotations(annotationList); zipkinSpan.setBinary_annotations(binaryAnnotationList); return zipkinSpan; }
private void assertSpansAreEquivalent(Span s, com.twitter.zipkin.gen.Span zs) { assertTrue("zipkin doesn't support multiple parents to a single span.", s.getParents().length <= 1); if (s.getParents().length == 1) { assertEquals(s.getParents()[0].getLow(), zs.getParent_id()); } assertEquals(s.getSpanId().getLow(), zs.getId()); Assert.assertNotNull(zs.getAnnotations()); if (ROOT_SPAN_DESC.equals(zs.getName())) { assertEquals(5, zs.getAnnotations().size());// two start, two stop + one timeline annotation assertEquals(1, zs.getBinary_annotations().size()); } else { assertEquals(4, zs.getAnnotations().size()); } } }
@Override public void releaseShortCircuitFds(SlotId slotId) throws IOException { ReleaseShortCircuitAccessRequestProto.Builder builder = ReleaseShortCircuitAccessRequestProto.newBuilder(). setSlotId(PBHelperClient.convert(slotId)); SpanId spanId = Tracer.getCurrentSpanId(); if (spanId.isValid()) { builder.setTraceInfo(DataTransferTraceInfoProto.newBuilder(). setTraceId(spanId.getHigh()). setParentId(spanId.getLow())); } ReleaseShortCircuitAccessRequestProto proto = builder.build(); send(out, Op.RELEASE_SHORT_CIRCUIT_FDS, proto); }
static BaseHeaderProto buildBaseHeader(ExtendedBlock blk, Token<BlockTokenIdentifier> blockToken) { BaseHeaderProto.Builder builder = BaseHeaderProto.newBuilder() .setBlock(PBHelperClient.convert(blk)) .setToken(PBHelperClient.convert(blockToken)); SpanId spanId = Tracer.getCurrentSpanId(); if (spanId.isValid()) { builder.setTraceInfo(DataTransferTraceInfoProto.newBuilder() .setTraceId(spanId.getHigh()) .setParentId(spanId.getLow())); } return builder.build(); }
Insert spanInsert = tableSpan.newInsert(); PartialRow spanRow = spanInsert.getRow(); spanRow.addLong(column_span_trace_id, span.getSpanId().getLow()); spanRow.addLong(column_span_start_time, span.getStartTimeMillis()); spanRow.addLong(column_span_stop_time, span.getStopTimeMillis()); Insert parentInsert = tableParent.newInsert(); PartialRow parentRow = parentInsert.getRow(); parentRow.addLong(column_parent_id_low, span.getParents()[i].getLow()); parentRow.addLong(column_parent_id_high, span.getParents()[i].getHigh()); parentRow.addLong(column_parent_child_span_id, span.getSpanId().getLow()); session.apply(parentInsert); Insert timelineInsert = tableTimeline.newInsert(); PartialRow timelineRow = timelineInsert.getRow(); timelineRow.addLong(column_timeline_timeline_id, span.getSpanId().getLow() + annotationCounter); timelineRow.addLong(column_timeline_time, ta.getTime()); timelineRow.addString(column_timeline_message, ta.getMessage()); timelineRow.addLong(column_timeline_span_id, span.getSpanId().getLow()); session.apply(timelineInsert);
.setStart(span.getStartTimeMillis()) .setStop(span.getStopTimeMillis()) .setSpanId(span.getSpanId().getLow()) .setProcessId(span.getTracerId()) .setDescription(span.getDescription()); sbuilder.setParentId(0); } else if (span.getParents().length > 0) { sbuilder.setParentId(span.getParents()[0].getLow()); if (span.getParents().length > 1) { LOG.error("error: HBaseSpanReceiver does not support spans " +
public static void appendJsonString(Span span, OutputStreamWriter writer) throws IOException { writer.append("{"); appendField(JSON_FIELD_TRACE_ID, span.getSpanId().getLow(), writer); appendField(JSON_FIELD_SPAN_ID, span.getSpanId().getHigh(), writer); appendField(JSON_FIELD_DESCRIPTION, span.getDescription(), writer); if (span.getParents().length != 0) { appendField(JSON_FIELD_PARENT_ID, span.getParents()[0].getLow(), writer); } appendField(JSON_FIELD_START, span.getStartTimeMillis(), writer); appendField(JSON_FIELD_STOP, span.getStopTimeMillis(), writer); if (!span.getTimelineAnnotations().isEmpty()) { writer.append("\""); writer.append(JSON_FIELD_TIMELINE); writer.append("\""); writer.append(":"); writer.append("["); for (TimelineAnnotation annotation : span.getTimelineAnnotations()) { writer.append("{"); appendField(JSON_FIELD_TIMELINE_TIME, annotation.getTime(), writer); appendField(JSON_FIELD_TIMELINE_MESSEGE, annotation.getMessage(), writer); writer.append("}"); } writer.append("]"); } writer.append("}"); }
result.setTraceInfo(RPCTraceInfoProto.newBuilder() .setTraceId(span.getSpanId().getHigh()) .setParentId(span.getSpanId().getLow()) .build());
Assert.assertEquals(childScope.getSpan().getParents()[0].getHigh(), spanIdHashMap.get(childScope.getSpan().getParents()[0].hashCode()).getHigh()); Assert.assertEquals(childScope.getSpan().getParents()[0].getLow(), spanIdHashMap.get(childScope.getSpan().getParents()[0].hashCode()).getLow()); Assert.assertEquals(childScope.getSpan().getParents()[1].getLow(), spanIdHashMap.get(childScope.getSpan().getParents()[1].hashCode()).getLow()); childScope.close(); activeScope.close();
@Test(timeout=60000) public void testRootSpansHaveNonZeroSpanId() throws Exception { Tracer tracer = new Tracer.Builder(). name("testRootSpansHaveNonZeroSpanId"). tracerPool(new TracerPool("testRootSpansHaveNonZeroSpanId")). conf(HTraceConfiguration.fromKeyValuePairs( "sampler.classes", "AlwaysSampler")).build(); TraceScope scope = tracer. newScope("myRootSpan", new SpanId(100L, 200L)); Assert.assertNotNull(scope); Assert.assertEquals("myRootSpan", scope.getSpan().getDescription()); Assert.assertTrue(scope.getSpan().getSpanId().isValid()); Assert.assertEquals(100L, scope.getSpan().getSpanId().getHigh()); Assert.assertNotEquals(0L, scope.getSpan().getSpanId().getLow()); scope.close(); } }