Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion tracing/src/main/java/com/palantir/tracing/CloseableTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ private CloseableTracer() { }
* Opens a new {@link SpanType#LOCAL LOCAL} span for this thread's call trace, labeled with the provided operation.
*/
public static CloseableTracer startSpan(String operation) {
Tracer.startSpan(operation);
return startSpan(operation, SpanType.LOCAL);
}

/**
* Opens a new span for this thread's call trace with the provided {@link SpanType},
* labeled with the provided operation.
*/
public static CloseableTracer startSpan(String operation, SpanType spanType) {
Tracer.startSpan(operation, spanType);
return INSTANCE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.palantir.tracing.api.OpenSpan;
import com.palantir.tracing.api.SpanType;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -33,7 +35,19 @@ public void before() {
@Test
public void startsAndClosesSpan() {
try (CloseableTracer tracer = CloseableTracer.startSpan("foo")) {
assertThat(Tracer.copyTrace().get().top()).isNotEmpty();
OpenSpan openSpan = Tracer.copyTrace().get().top().get();
assertThat(openSpan.getOperation()).isEqualTo("foo");
assertThat(openSpan.type()).isEqualTo(SpanType.LOCAL);
}
assertThat(Tracer.getAndClearTrace().top()).isEmpty();
}

@Test
public void startsAndClosesSpanWithType() {
try (CloseableTracer tracer = CloseableTracer.startSpan("foo", SpanType.CLIENT_OUTGOING)) {
OpenSpan openSpan = Tracer.copyTrace().get().top().get();
assertThat(openSpan.getOperation()).isEqualTo("foo");
assertThat(openSpan.type()).isEqualTo(SpanType.CLIENT_OUTGOING);
}
assertThat(Tracer.getAndClearTrace().top()).isEmpty();
}
Expand Down