Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #35 from opentracing/bhs/explicit_finish
Browse files Browse the repository at this point in the history
Support explicit Span finish times
  • Loading branch information
bensigelman authored Aug 8, 2016
2 parents ea0eebe + 1496025 commit 7e0d6b2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
22 changes: 19 additions & 3 deletions opentracing-api/src/main/java/io/opentracing/Span.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,34 @@ public interface Span extends AutoCloseable {
/**
* Retrieve the associated SpanContext.
*
* This may be called at any time, including after calls to finish().
*
* @return the SpanContext that encapsulates Span state that should propagate across process boundaries.
*/
SpanContext context();

/**
* Sets the end timestamp and records the span.
* Sets the end timestamp to now and records the span.
*
* <p>With the exception of calls to Span.context(), this should be the last call made to the span instance, and to
* do otherwise leads to undefined behavior.
*
* <p>This should be the last call made to any span instance, and to do otherwise leads to
* undefined behavior.
* @see Span#context()
*/
void finish();

/**
* Sets an explicit end timestamp and records the span.
*
* <p>With the exception of calls to Span.context(), this should be the last call made to the span instance, and to
* do otherwise leads to undefined behavior.
*
* @param finishMicros an explicit finish time, in microseconds since the epoch
*
* @see Span#context()
*/
void finish(long finishMicros);

void close();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public void finish() {
assert null == duration;
duration = Duration.between(start, Instant.now());
}
@Override
public void finish(long finishMicros) {
long finishEpochSeconds = TimeUnit.MICROSECONDS.toSeconds(finishMicros);
long nanos = TimeUnit.MICROSECONDS.toNanos(finishMicros) - TimeUnit.SECONDS.toNanos(finishEpochSeconds);
assert null == duration;
duration = Duration.between(start, Instant.ofEpochSecond(finishEpochSeconds, nanos));
}

@Override
public void close() {
Expand Down
3 changes: 3 additions & 0 deletions opentracing-impl/src/main/java/io/opentracing/NoopSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ private NoopSpan() {}
@Override
public void finish() {}

@Override
public void finish(long finishMicros) {}

@Override
public void close() {
finish();
Expand Down

0 comments on commit 7e0d6b2

Please sign in to comment.