/** * A convenience static factory method that lets you generate an instance of {@link TimestampedAnnotation} * with a timestamp of "right now", however unfortunately that "right now" timestamp will have a resolution of * only epoch milliseconds. This epoch millisecond resolution is the best we can do, because without more info * we don't have anything more accurate than {@link System#currentTimeMillis()}. * * <p>NOTE: {@link Span}s keep track of nanosecond duration, so {@link * Span#addTimestampedAnnotation(TimestampedAnnotation)} is able to give a more accurate timestamp than this * method by calling {@link #forEpochMicrosWithNanoOffset(long, long, String)} with the nanosecond offset. * Since {@link Span#addTimestampedAnnotation(TimestampedAnnotation)} is more accurate, you should use that * method directly on the {@link Span} rather than this method whenever possible. * * @param value The value to associate with the "right now" timestamp. * @return A new {@link TimestampedAnnotation} with a timestamp of {@link System#currentTimeMillis()} * (converted to microseconds), and the given value. */ public static TimestampedAnnotation forCurrentTime(String value) { return forEpochMillis(System.currentTimeMillis(), value); }
@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); }