File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed
main/java/com/palantir/tracing
test/java/com/palantir/tracing Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 1818
1919import static org .assertj .core .api .Assertions .assertThat ;
2020
21+ import com .palantir .tracing .api .OpenSpan ;
22+ import com .palantir .tracing .api .SpanType ;
2123import org .junit .Before ;
2224import org .junit .Test ;
2325import 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 }
You can’t perform that action at this time.
0 commit comments