String escapedAnnotationValue = escapeJson(annotation.getValue()); builder.append(",").append(KEY_VALUE_TIMESTAMPED_ANNOTATION_PREFIX) .append(annotation.getTimestampEpochMicros())
String escapedValue = escapeJson(annotation.getValue());
private TimestampedAnnotation findAnnotationInSpan(Span span, String annotationValue) { return span .getTimestampedAnnotations() .stream() .filter(ta -> annotationValue.equals(ta.getValue())) .findFirst() .orElseThrow(() -> new RuntimeException( "Expected to find annotation with value: \"" + annotationValue + "\", but none was found" )); }
SpanParser.ANNOTATION_SUBOBJECT_TIMESTAMP_FIELD, String.valueOf(a.getTimestampEpochMicros()) ).put( SpanParser.ANNOTATION_SUBOBJECT_VALUE_FIELD, a.getValue() ).build()
spanBuilder.addAnnotation(wingtipsAnnotation.getTimestampEpochMicros(), wingtipsAnnotation.getValue());
spanBuilder.addAnnotation(wingtipsAnnotation.getTimestampEpochMicros(), wingtipsAnnotation.getValue());
@UseDataProvider("escapedAndUnescapedQuotesBeforeKeyOrValueEndScenarioDataProvider") @Test public void fromJSON_properly_handles_escaped_quotes_and_unescaped_quotes_preceded_by_backslashes( EscapedAndUnescapedQuotesBeforeKeyOrValueEndScenario scenario ) { // given Span span = Span.newBuilder("someSpan", SpanPurpose.CLIENT) .withTag(scenario.unescapedKey, scenario.unescapedValue) .withTimestampedAnnotation( TimestampedAnnotation.forEpochMicros(1234, scenario.unescapedValue) ) .build(); String json = SpanParser.convertSpanToJSON(span); // when Span result = SpanParser.fromJSON(json); // then assertThat(result.getTags().get(scenario.unescapedKey)).isEqualTo(scenario.unescapedValue); assertThat(result.getTimestampedAnnotations().get(0).getValue()).isEqualTo(scenario.unescapedValue); }
@Test public void TimestampedAnnotation_forEpochMicrosWithNanoOffset_works_as_expected() { // given long timestampMicros = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()); long nanoOffset = 4242; String value = UUID.randomUUID().toString(); long expectedMicrosOffset = TimeUnit.NANOSECONDS.toMicros(nanoOffset); assertThat(expectedMicrosOffset).isGreaterThan(0); long expectedTimestamp = timestampMicros + expectedMicrosOffset; assertThat(expectedTimestamp).isNotEqualTo(timestampMicros); // when TimestampedAnnotation result = TimestampedAnnotation.forEpochMicrosWithNanoOffset( timestampMicros, nanoOffset, value ); // then assertThat(result.getTimestampEpochMicros()).isEqualTo(expectedTimestamp); assertThat(result.getValue()).isEqualTo(value); } }
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 void addAllAnnotationsToBuilder( zipkin.Span.Builder builder, List<TimestampedAnnotation> wingtipsAnnotations, Endpoint zipkinEndpoint ) { for (TimestampedAnnotation wingtipsAnnotation : wingtipsAnnotations) { builder.addAnnotation( Annotation.create( wingtipsAnnotation.getTimestampEpochMicros(), wingtipsAnnotation.getValue(), zipkinEndpoint ) ); } }
@Test public void TimestampedAnnotation_forCurrentTime_works_as_expected() { // given String value = UUID.randomUUID().toString(); // when long beforeMillis = System.currentTimeMillis(); TimestampedAnnotation result = TimestampedAnnotation.forCurrentTime(value); long afterMillis = System.currentTimeMillis(); // then long beforeMicros = TimeUnit.MILLISECONDS.toMicros(beforeMillis); long afterMicros = TimeUnit.MILLISECONDS.toMicros(afterMillis); assertThat(result.getTimestampEpochMicros()).isBetween(beforeMicros, afterMicros); assertThat(result.getValue()).isEqualTo(value); }
private TimestampedAnnotation findSpanAnnotation(Span span, String annotationName) { return span.getTimestampedAnnotations().stream() .filter(a -> annotationName.equalsIgnoreCase(a.getValue())) .findFirst() .orElse(null); }
@Test public void TimestampedAnnotation_forEpochMillis_works_as_expected() { // given long timestampMillis = System.currentTimeMillis(); String value = UUID.randomUUID().toString(); // when TimestampedAnnotation result = TimestampedAnnotation.forEpochMillis(timestampMillis, value); // then assertThat(result.getTimestampEpochMicros()).isEqualTo(TimeUnit.MILLISECONDS.toMicros(timestampMillis)); assertThat(result.getValue()).isEqualTo(value); }
@Test public void TimestampedAnnotation_forEpochMicros_works_as_expected() { // given long timestampMicros = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()); String value = UUID.randomUUID().toString(); // when TimestampedAnnotation result = TimestampedAnnotation.forEpochMicros(timestampMicros, value); // then assertThat(result.getTimestampEpochMicros()).isEqualTo(timestampMicros); assertThat(result.getValue()).isEqualTo(value); }
@Test public void TimestampedAnnotation_equals_returns_false_and_hashCode_different_if_timestamp_is_different() { // given TimestampedAnnotation annotation1 = new TimestampedAnnotation(42, "foo"); TimestampedAnnotation annotation2 = new TimestampedAnnotation( annotation1.getTimestampEpochMicros() + 1234, annotation1.getValue() ); // expect assertThat(annotation1.equals(annotation2)).isFalse(); assertThat(annotation1.hashCode()).isNotEqualTo(annotation2.hashCode()); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof TimestampedAnnotation)) { return false; } TimestampedAnnotation that = (TimestampedAnnotation) o; return getTimestampEpochMicros() == that.getTimestampEpochMicros() && Objects.equals(getValue(), that.getValue()); }
@Test public void TimestampedAnnotation_constructor_works_as_expected() { // given long timestamp = 42; String value = UUID.randomUUID().toString(); // when TimestampedAnnotation result = new TimestampedAnnotation(timestamp, value); // then assertThat(result.getTimestampEpochMicros()).isEqualTo(timestamp); assertThat(result.getValue()).isEqualTo(value); }
@Override public int hashCode() { return Objects.hash(getTimestampEpochMicros(), getValue()); } }
@Test public void TimestampedAnnotation_equals_returns_false_and_hashCode_different_if_value_is_different() { // given TimestampedAnnotation annotation1 = new TimestampedAnnotation(42, "foo"); TimestampedAnnotation annotation2 = new TimestampedAnnotation( annotation1.getTimestampEpochMicros(), annotation1.getValue() + "_nope" ); // expect assertThat(annotation1.equals(annotation2)).isFalse(); assertThat(annotation1.hashCode()).isNotEqualTo(annotation2.hashCode()); }
@Test public void TimestampedAnnotation_equals_returns_true_and_hashCode_same_if_all_fields_are_equal() { // given TimestampedAnnotation annotation1 = new TimestampedAnnotation(42, "foo"); TimestampedAnnotation annotation2 = new TimestampedAnnotation( annotation1.getTimestampEpochMicros(), annotation1.getValue() ); // expect assertThat(annotation1.equals(annotation2)).isTrue(); assertThat(annotation1.hashCode()).isEqualTo(annotation2.hashCode()); }