Add a new log method to span that allows for setting the time (#501)
* Add a new log method that allows for setting the time * Clarify with time unit * Simple test and spelling correction * Consolidate "logic" and add a test for the other log method
This commit is contained in:
committed by
Marcin Grzejszczak
parent
32d8ea8fc7
commit
1c7d861ffc
@@ -340,7 +340,15 @@ public class Span implements SpanContext {
|
||||
* Add an {@link Log#event event} to the timeline associated with this span.
|
||||
*/
|
||||
public void logEvent(String event) {
|
||||
this.logs.add(new Log(System.currentTimeMillis(), event));
|
||||
logEvent(System.currentTimeMillis(), event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a {@link Log#event event} to a specific point (a timestamp in milliseconds) in the timeline
|
||||
* associated with this span.
|
||||
*/
|
||||
public void logEvent(long timestampMilliseconds, String event) {
|
||||
this.logs.add(new Log(timestampMilliseconds, event));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -166,6 +166,19 @@ public class SpanTests {
|
||||
.isEqualTo(span.logs());
|
||||
}
|
||||
|
||||
@Test public void can_log_with_generated_timestamp() throws IOException {
|
||||
span.logEvent("event1");
|
||||
|
||||
long beforeLog = System.currentTimeMillis();
|
||||
assertThat(span.logs().get(0).getTimestamp()).isGreaterThanOrEqualTo(beforeLog);
|
||||
}
|
||||
|
||||
@Test public void can_log_with_specified_timestamp() throws IOException {
|
||||
span.logEvent(1L, "event1");
|
||||
|
||||
then(span.logs().get(0).getTimestamp()).isEqualTo(1L);
|
||||
}
|
||||
|
||||
@Test public void should_properly_serialize_tags() throws IOException {
|
||||
span.tag("calculatedTax", "100");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user