Skip to content

Commit 5cd301b

Browse files
diogoholandabulldozer-bot[bot]
authored andcommitted
CloseableTracer supports all SpanTypes (#76)
## Before this PR CloseableTracer only supported the LOCAL SpanType. ## After this PR CloseableTracer only supports all SpanTypes.
1 parent 4c4fdc1 commit 5cd301b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

tracing/src/main/java/com/palantir/tracing/CloseableTracer.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ private CloseableTracer() { }
3636
* Opens a new {@link SpanType#LOCAL LOCAL} span for this thread's call trace, labeled with the provided operation.
3737
*/
3838
public static CloseableTracer startSpan(String operation) {
39-
Tracer.startSpan(operation);
39+
return startSpan(operation, SpanType.LOCAL);
40+
}
41+
42+
/**
43+
* Opens a new span for this thread's call trace with the provided {@link SpanType},
44+
* labeled with the provided operation.
45+
*/
46+
public static CloseableTracer startSpan(String operation, SpanType spanType) {
47+
Tracer.startSpan(operation, spanType);
4048
return INSTANCE;
4149
}
4250

tracing/src/test/java/com/palantir/tracing/CloseableTracerTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

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

21+
import com.palantir.tracing.api.OpenSpan;
22+
import com.palantir.tracing.api.SpanType;
2123
import org.junit.Before;
2224
import org.junit.Test;
2325
import org.junit.runner.RunWith;
@@ -33,7 +35,19 @@ public void before() {
3335
@Test
3436
public void startsAndClosesSpan() {
3537
try (CloseableTracer tracer = CloseableTracer.startSpan("foo")) {
36-
assertThat(Tracer.copyTrace().get().top()).isNotEmpty();
38+
OpenSpan openSpan = Tracer.copyTrace().get().top().get();
39+
assertThat(openSpan.getOperation()).isEqualTo("foo");
40+
assertThat(openSpan.type()).isEqualTo(SpanType.LOCAL);
41+
}
42+
assertThat(Tracer.getAndClearTrace().top()).isEmpty();
43+
}
44+
45+
@Test
46+
public void startsAndClosesSpanWithType() {
47+
try (CloseableTracer tracer = CloseableTracer.startSpan("foo", SpanType.CLIENT_OUTGOING)) {
48+
OpenSpan openSpan = Tracer.copyTrace().get().top().get();
49+
assertThat(openSpan.getOperation()).isEqualTo("foo");
50+
assertThat(openSpan.type()).isEqualTo(SpanType.CLIENT_OUTGOING);
3751
}
3852
assertThat(Tracer.getAndClearTrace().top()).isEmpty();
3953
}

0 commit comments

Comments
 (0)