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; }
/** * Sets the endpoint in the span for any future annotations. Also sets the endpoint in any * previous annotations that lack one. */ synchronized MutableSpan setEndpoint(Endpoint endpoint) { for (int i = 0; i < annotations.size(); i++) { Annotation a = annotations.get(i); if (a.endpoint.equals(Endpoints.UNKNOWN)) { annotations.set(i, a.toBuilder().endpoint(endpoint).build()); } } this.endpoint = endpoint; return this; }
@Override public Annotation fromJson(JsonReader reader) throws IOException { Annotation.Builder result = Annotation.builder(); reader.beginObject(); while (reader.hasNext()) { switch (reader.nextName()) { case "timestamp": result.timestamp(reader.nextLong()); break; case "value": result.value(reader.nextString()); break; case "endpoint": result.endpoint(ENDPOINT_ADAPTER.fromJson(reader)); break; default: reader.skipValue(); } } reader.endObject(); return result.build(); }
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 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 ) ); } }
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 void addAllAnnotationsToBuilder( zipkin.Span.Builder builder, List<TimestampedAnnotation> wingtipsAnnotations, Endpoint zipkinEndpoint ) { for (TimestampedAnnotation wingtipsAnnotation : wingtipsAnnotations) { builder.addAnnotation( Annotation.create( wingtipsAnnotation.getTimestampEpochMicros(), wingtipsAnnotation.getValue(), zipkinEndpoint ) ); } }
Annotation a = Annotation.create(input.timestamp(), input.value(), local); if (a.value.length() == 2) { if (a.value.equals("cs")) { case CLIENT: remoteEndpointType = "sa"; if (startTs != 0L) cs = Annotation.create(startTs, "cs", local); if (endTs != 0L) cr = Annotation.create(endTs, "cr", local); break; case SERVER: remoteEndpointType = "ca"; if (startTs != 0L) sr = Annotation.create(startTs, "sr", local); if (endTs != 0L) ss = Annotation.create(endTs, "ss", local); break; case PRODUCER: remoteEndpointType = "ma"; if (startTs != 0L) ms = Annotation.create(startTs, "ms", local); if (endTs != 0L) ws = Annotation.create(endTs, "ws", local); break; case CONSUMER: remoteEndpointType = "ma"; if (startTs != 0L && endTs != 0L) { wr = Annotation.create(startTs, "wr", local); mr = Annotation.create(endTs, "mr", local); } else if (startTs != 0L) { mr = Annotation.create(startTs, "mr", local);
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),
Annotation.create(startTimeEpochMicros, Constants.SERVER_RECV, zipkinEndpoint) ); assertThat(zipkinSpan.annotations).contains( Annotation.create(startTimeEpochMicros + durationMicros, Constants.SERVER_SEND, zipkinEndpoint) ); Annotation.create(startTimeEpochMicros, Constants.CLIENT_SEND, zipkinEndpoint) ); assertThat(zipkinSpan.annotations).contains( Annotation.create(startTimeEpochMicros + durationMicros, Constants.CLIENT_RECV, zipkinEndpoint) );
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),
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),
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),