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

Commit

Permalink
Support explicit Span finish times
Browse files Browse the repository at this point in the history
  • Loading branch information
bhs committed Aug 7, 2016
1 parent 1c20ac3 commit 1496025
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 1496025

Please sign in to comment.