.stream() .map(r -> Span.builder() .traceId(r.getValue(ZIPKIN_SPANS.TRACE_ID)) .name(r.getValue(ZIPKIN_SPANS.NAME)) .id(r.getValue(ZIPKIN_SPANS.ID)) .parentId(r.getValue(ZIPKIN_SPANS.PARENT_ID)) .timestamp(r.getValue(ZIPKIN_SPANS.START_TS)) .duration(r.getValue(ZIPKIN_SPANS.DURATION)) .debug(r.getValue(ZIPKIN_SPANS.DEBUG)) .build()) .collect( groupingBy((Span s) -> s.traceId, LinkedHashMap::new, Collectors.<Span>toList())); int type = a.getValue(ZIPKIN_ANNOTATIONS.A_TYPE); if (type == -1) { span.addAnnotation(Annotation.create( a.getValue(ZIPKIN_ANNOTATIONS.A_TIMESTAMP), a.getValue(ZIPKIN_ANNOTATIONS.A_KEY), endpoint)); } else { span.addBinaryAnnotation(BinaryAnnotation.create( a.getValue(ZIPKIN_ANNOTATIONS.A_KEY), a.getValue(ZIPKIN_ANNOTATIONS.A_VALUE), Span rawSpan = span.build(); trace.add(raw ? rawSpan : ApplyTimestampAndDuration.apply(rawSpan));
String traceId = in.traceId(); zipkin.Span.Builder result = zipkin.Span.builder() .traceId(IdConversion.convertToLong(traceId)) .parentId(in.parentId() != null ? IdConversion.convertToLong(in.parentId()) : null) .id(IdConversion.convertToLong(in.id())) .debug(in.debug()) .name(in.name() != null ? in.name() : ""); // avoid a NPE result.traceIdHigh(IdConversion.convertToLong(traceId, 0)); Long endTs = in.duration() == null ? 0L : in.timestamp() + in.duration(); if (startTs != 0L) { result.timestamp(startTs); result.duration(in.duration()); } else { wroteEndpoint = true; result.addAnnotation(a); result.addAnnotation(a); result.addBinaryAnnotation(BinaryAnnotation.create(tag.getKey(), tag.getValue(), local)); || ms != null || mr != null) { if (cs != null) result.addAnnotation(cs); if (sr != null) result.addAnnotation(sr); if (ss != null) result.addAnnotation(ss); if (cr != null) result.addAnnotation(cr);
.stream() .map(r -> zipkin.Span.builder() .traceIdHigh(maybeGet(r, ZIPKIN_SPANS.TRACE_ID_HIGH, 0L)) .traceId(r.getValue(ZIPKIN_SPANS.TRACE_ID)) .name(r.getValue(ZIPKIN_SPANS.NAME)) .id(r.getValue(ZIPKIN_SPANS.ID)) .parentId(r.getValue(ZIPKIN_SPANS.PARENT_ID)) .timestamp(r.getValue(ZIPKIN_SPANS.START_TS)) .duration(r.getValue(ZIPKIN_SPANS.DURATION)) .debug(r.getValue(ZIPKIN_SPANS.DEBUG)) .build()) .collect( groupingBy((zipkin.Span s) -> Pair.create(s.traceIdHigh, s.traceId), int type = a.getValue(ZIPKIN_ANNOTATIONS.A_TYPE); if (type == -1) { span.addAnnotation(Annotation.create( a.getValue(ZIPKIN_ANNOTATIONS.A_TIMESTAMP), a.getValue(ZIPKIN_ANNOTATIONS.A_KEY), endpoint)); } else { span.addBinaryAnnotation(BinaryAnnotation.create( a.getValue(ZIPKIN_ANNOTATIONS.A_KEY), a.getValue(ZIPKIN_ANNOTATIONS.A_VALUE), allSpans.add(span.build());
.selectFrom(ZIPKIN_SPANS).where(traceIdCondition) .stream() .map(r -> new Span.Builder() .traceId(r.getValue(ZIPKIN_SPANS.TRACE_ID)) .name(r.getValue(ZIPKIN_SPANS.NAME)) .id(r.getValue(ZIPKIN_SPANS.ID)) .parentId(r.getValue(ZIPKIN_SPANS.PARENT_ID)) .timestamp(r.getValue(ZIPKIN_SPANS.START_TS)) .duration(r.getValue(ZIPKIN_SPANS.DURATION)) .debug(r.getValue(ZIPKIN_SPANS.DEBUG)) .build()) .collect(groupingBy((Span s) -> s.traceId, LinkedHashMap::new, Collectors.<Span>toList())); List<Span> trace = new ArrayList<>(spans.size()); for (Span s : spans) { Span.Builder span = new Span.Builder(s); Pair<?> key = Pair.create(s.traceId, s.id); int type = a.getValue(ZIPKIN_ANNOTATIONS.A_TYPE); if (type == -1) { span.addAnnotation(Annotation.create( a.getValue(ZIPKIN_ANNOTATIONS.A_TIMESTAMP), a.getValue(ZIPKIN_ANNOTATIONS.A_KEY), endpoint)); } else { span.addBinaryAnnotation(BinaryAnnotation.create( a.getValue(ZIPKIN_ANNOTATIONS.A_KEY), a.getValue(ZIPKIN_ANNOTATIONS.A_VALUE),
.selectFrom(ZIPKIN_SPANS).where(traceIdCondition) .stream() .map(r -> new Span.Builder() .traceId(r.getValue(ZIPKIN_SPANS.TRACE_ID)) .name(r.getValue(ZIPKIN_SPANS.NAME)) .id(r.getValue(ZIPKIN_SPANS.ID)) .parentId(r.getValue(ZIPKIN_SPANS.PARENT_ID)) .timestamp(r.getValue(ZIPKIN_SPANS.START_TS)) .duration(r.getValue(ZIPKIN_SPANS.DURATION)) .debug(r.getValue(ZIPKIN_SPANS.DEBUG)) .build()) .collect( groupingBy((Span s) -> s.traceId, LinkedHashMap::new, Collectors.<Span>toList())); List<Span> trace = new ArrayList<>(spans.size()); for (Span s : spans) { Span.Builder span = new Span.Builder(s); Pair<?> key = Pair.create(s.traceId, s.id); int type = a.getValue(ZIPKIN_ANNOTATIONS.A_TYPE); if (type == -1) { span.addAnnotation(Annotation.create( a.getValue(ZIPKIN_ANNOTATIONS.A_TIMESTAMP), a.getValue(ZIPKIN_ANNOTATIONS.A_KEY), endpoint)); } else { span.addBinaryAnnotation(BinaryAnnotation.create( a.getValue(ZIPKIN_ANNOTATIONS.A_KEY), a.getValue(ZIPKIN_ANNOTATIONS.A_VALUE),
String traceId = reader.nextString(); if (traceId.length() == 32) { result.traceIdHigh(lowerHexToUnsignedLong(traceId, 0)); result.traceId(lowerHexToUnsignedLong(traceId)); break; case "name": result.name(reader.nextString()); break; case "id": result.id(lowerHexToUnsignedLong(reader.nextString())); break; case "parentId": result.parentId(lowerHexToUnsignedLong(reader.nextString())); break; case "timestamp": result.timestamp(reader.nextLong()); break; case "duration": result.duration(reader.nextLong()); break; case "annotations": reader.beginArray(); while (reader.hasNext()) { result.addAnnotation(ANNOTATION_ADAPTER.fromJson(reader)); reader.beginArray(); while (reader.hasNext()) { result.addBinaryAnnotation(BINARY_ANNOTATION_ADAPTER.fromJson(reader));
protected zipkin.Span.Builder createNewZipkinSpanBuilderWithSpanPurposeAnnotations( Span wingtipsSpan, long startEpochMicros, long durationMicros, Endpoint zipkinEndpoint, String localComponentNamespace ) { zipkin.Span.Builder zsb = zipkin.Span.builder(); switch(wingtipsSpan.getSpanPurpose()) { case SERVER: zsb.addAnnotation(Annotation.create(startEpochMicros, Constants.SERVER_RECV, zipkinEndpoint)) .addAnnotation(Annotation.create(startEpochMicros + durationMicros, Constants.SERVER_SEND, zipkinEndpoint)); break; case CLIENT: zsb.addAnnotation(Annotation.create(startEpochMicros, Constants.CLIENT_SEND, zipkinEndpoint)) .addAnnotation(Annotation.create(startEpochMicros + durationMicros, Constants.CLIENT_RECV, zipkinEndpoint)); break; case LOCAL_ONLY: case UNKNOWN: // intentional fall-through: local and unknown span purpose are treated the same way zsb.addBinaryAnnotation(BinaryAnnotation.create(Constants.LOCAL_COMPONENT, localComponentNamespace, zipkinEndpoint)); break; default: logger.warn("Unhandled SpanPurpose type: " + wingtipsSpan.getSpanPurpose().name()); } return zsb; }
protected zipkin.Span.Builder createNewZipkinSpanBuilderWithSpanPurposeAnnotations( Span wingtipsSpan, long startEpochMicros, long durationMicros, Endpoint zipkinEndpoint, String localComponentNamespace ) { zipkin.Span.Builder zsb = zipkin.Span.builder(); switch(wingtipsSpan.getSpanPurpose()) { case SERVER: zsb.addAnnotation(Annotation.create(startEpochMicros, Constants.SERVER_RECV, zipkinEndpoint)) .addAnnotation(Annotation.create(startEpochMicros + durationMicros, Constants.SERVER_SEND, zipkinEndpoint)); break; case CLIENT: zsb.addAnnotation(Annotation.create(startEpochMicros, Constants.CLIENT_SEND, zipkinEndpoint)) .addAnnotation(Annotation.create(startEpochMicros + durationMicros, Constants.CLIENT_RECV, zipkinEndpoint)); break; case LOCAL_ONLY: case UNKNOWN: // intentional fall-through: local and unknown span purpose are treated the same way zsb.addBinaryAnnotation(BinaryAnnotation.create(Constants.LOCAL_COMPONENT, localComponentNamespace, zipkinEndpoint)); break; default: logger.warn("Unhandled SpanPurpose type: " + wingtipsSpan.getSpanPurpose().name()); } return zsb; }
synchronized MutableSpan addAnnotation(Time timestamp, String value) { if (annotations.isEmpty()) { span.timestamp(timestamp.inMicroseconds()); } if (!isComplete && (value.equals(CLIENT_RECV) || value.equals(SERVER_SEND) || value.equals(TimeoutFilter.TimeoutAnnotation()))) { if (!annotations.isEmpty()) { span.duration(timestamp.inMicroseconds() - annotations.get(0).timestamp); } isComplete = true; } annotations.add(Annotation.create(timestamp.inMicroseconds(), value, endpoint)); return this; }
protected void addAllAnnotationsToBuilder( zipkin.Span.Builder builder, List<TimestampedAnnotation> wingtipsAnnotations, Endpoint zipkinEndpoint ) { for (TimestampedAnnotation wingtipsAnnotation : wingtipsAnnotations) { builder.addAnnotation( Annotation.create( wingtipsAnnotation.getTimestampEpochMicros(), wingtipsAnnotation.getValue(), zipkinEndpoint ) ); } }
@Override public zipkin.Span convertWingtipsSpanToZipkinSpan(Span wingtipsSpan, Endpoint zipkinEndpoint, String localComponentNamespace) { String traceId = wingtipsSpan.getTraceId(); long startEpochMicros = wingtipsSpan.getSpanStartTimeEpochMicros(); long durationMicros = TimeUnit.NANOSECONDS.toMicros(wingtipsSpan.getDurationNanos()); zipkin.Span.Builder builder = createNewZipkinSpanBuilderWithSpanPurposeAnnotations(wingtipsSpan, startEpochMicros, durationMicros, zipkinEndpoint, localComponentNamespace) .id(nullSafeLong(wingtipsSpan.getSpanId())) .name(wingtipsSpan.getSpanName()) .parentId(nullSafeLong(wingtipsSpan.getParentSpanId())) .timestamp(startEpochMicros) .traceIdHigh(traceId.length() == 32 ? nullSafeLong(traceId, 0) : 0) .traceId(nullSafeLong(traceId)) .duration(durationMicros); addAllTagsToBuilderAsBinaryAnnotations(builder, wingtipsSpan.getTags(), zipkinEndpoint); addAllAnnotationsToBuilder(builder, wingtipsSpan.getTimestampedAnnotations(), zipkinEndpoint); return builder.build(); }
synchronized Span toSpan() { // fill in the host/service data for all the annotations for (Annotation ann : annotations) { Endpoint ep = Endpoints.boundEndpoint(ann.endpoint); span.addAnnotation( ann.toBuilder().endpoint(ep.toBuilder().serviceName(service).build()).build()); } for (BinaryAnnotation ann : binaryAnnotations) { Endpoint ep = Endpoints.boundEndpoint(ann.endpoint); // TODO: service name for "ca" or "sa" is likely incorrect span.addBinaryAnnotation( ann.toBuilder().endpoint(ep.toBuilder().serviceName(service).build()).build()); } return span.build(); }
protected void addAllAnnotationsToBuilder( zipkin.Span.Builder builder, List<TimestampedAnnotation> wingtipsAnnotations, Endpoint zipkinEndpoint ) { for (TimestampedAnnotation wingtipsAnnotation : wingtipsAnnotations) { builder.addAnnotation( Annotation.create( wingtipsAnnotation.getTimestampEpochMicros(), wingtipsAnnotation.getValue(), zipkinEndpoint ) ); } }
@Override public zipkin.Span convertWingtipsSpanToZipkinSpan(Span wingtipsSpan, Endpoint zipkinEndpoint, String localComponentNamespace) { String traceId = wingtipsSpan.getTraceId(); long startEpochMicros = wingtipsSpan.getSpanStartTimeEpochMicros(); long durationMicros = TimeUnit.NANOSECONDS.toMicros(wingtipsSpan.getDurationNanos()); zipkin.Span.Builder builder = createNewZipkinSpanBuilderWithSpanPurposeAnnotations(wingtipsSpan, startEpochMicros, durationMicros, zipkinEndpoint, localComponentNamespace) .id(nullSafeLong(wingtipsSpan.getSpanId())) .name(wingtipsSpan.getSpanName()) .parentId(nullSafeLong(wingtipsSpan.getParentSpanId())) .timestamp(startEpochMicros) .traceIdHigh(traceId.length() == 32 ? nullSafeLong(traceId, 0) : 0) .traceId(nullSafeLong(traceId)) .duration(durationMicros); addAllTagsToBuilderAsBinaryAnnotations(builder, wingtipsSpan.getTags(), zipkinEndpoint); addAllAnnotationsToBuilder(builder, wingtipsSpan.getTimestampedAnnotations(), zipkinEndpoint); return builder.build(); }
protected void addAllTagsToBuilderAsBinaryAnnotations( zipkin.Span.Builder builder, Map<String,String> tagsToAdd, Endpoint zipkinEndpoint ) { for (Map.Entry<String, String> tagEntry : tagsToAdd.entrySet()) { BinaryAnnotation tagAnnotation = BinaryAnnotation.create( tagEntry.getKey(), tagEntry.getValue(), zipkinEndpoint ); builder.addBinaryAnnotation(tagAnnotation); } }
protected void addAllTagsToBuilderAsBinaryAnnotations( zipkin.Span.Builder builder, Map<String,String> tagsToAdd, Endpoint zipkinEndpoint ) { for (Map.Entry<String, String> tagEntry : tagsToAdd.entrySet()) { BinaryAnnotation tagAnnotation = BinaryAnnotation.create( tagEntry.getKey(), tagEntry.getValue(), zipkinEndpoint ); builder.addBinaryAnnotation(tagAnnotation); } }
synchronized MutableSpan setName(String n) { span.name(n); return this; }
MutableSpan(TraceId traceId, Time started) { this.span = Span.builder(); span.id(traceId.spanId().toLong()); if (traceId._parentId().isDefined()) { span.parentId(traceId.parentId().toLong()); } span.traceId(traceId.traceId().toLong()); if (traceId.traceIdHigh().isDefined()) { span.traceIdHigh(traceId.traceIdHigh().get().toLong()); } if (traceId.flags().isDebug()) { span.debug(true); } span.name("unknown"); this.started = started; }
@Override protected Span adjust(Span span) { List<Annotation> annotations = new ArrayList<>(); for (Annotation a : span.annotations) { if (!a.value.equals("finagle.flush")) { annotations.add(a); } } return span.toBuilder().annotations(annotations).build(); } }