use of com.palantir.tracing.api.OpenSpan in project tracing-java by palantir.
the class TraceTest method testToString.
@Test
public void testToString() {
Trace trace = Trace.of(true, TraceState.of("traceId", Optional.empty(), Optional.empty()));
OpenSpan span = trace.startSpan("operation", SpanType.LOCAL);
assertThat(trace.toString()).isEqualTo("Trace{" + "stack=[" + span + "], " + "isObservable=true, " + "state=TraceState{traceId='traceId', requestId='null', forUserAgent='null'}}").contains(span.getOperation()).contains(span.getSpanId());
}
use of com.palantir.tracing.api.OpenSpan in project tracing-java by palantir.
the class TracersTest method testWrapRunnableWithNewTrace_traceStateInsideRunnableHasSpan.
@Test
public void testWrapRunnableWithNewTrace_traceStateInsideRunnableHasSpan() throws Exception {
List<List<OpenSpan>> spans = new ArrayList<>();
Runnable wrappedRunnable = Tracers.wrapWithNewTrace(() -> {
spans.add(getCurrentTrace());
});
wrappedRunnable.run();
assertThat(spans.get(0)).hasSize(1);
OpenSpan span = spans.get(0).get(0);
assertThat(span.getOperation()).isEqualTo("root");
assertThat(span.getParentSpanId()).isEmpty();
}
use of com.palantir.tracing.api.OpenSpan in project tracing-java by palantir.
the class TracersTest method testWrapRunnableWithAlternateTraceId_traceStateInsideRunnableHasGivenSpan.
@Test
public void testWrapRunnableWithAlternateTraceId_traceStateInsideRunnableHasGivenSpan() {
List<List<OpenSpan>> spans = new ArrayList<>();
String traceIdToUse = "someTraceId";
Runnable wrappedRunnable = Tracers.wrapWithAlternateTraceId(traceIdToUse, "operation", () -> {
spans.add(getCurrentTrace());
});
wrappedRunnable.run();
assertThat(spans.get(0)).hasSize(1);
OpenSpan span = spans.get(0).get(0);
assertThat(span.getOperation()).isEqualTo("operation");
assertThat(span.getParentSpanId()).isEmpty();
}
use of com.palantir.tracing.api.OpenSpan in project tracing-java by palantir.
the class TracersTest method testWrapCallableWithAlternateTraceId_traceStateInsideCallableHasSpan.
@Test
public void testWrapCallableWithAlternateTraceId_traceStateInsideCallableHasSpan() throws Exception {
String traceIdToUse = "someTraceId";
Callable<List<OpenSpan>> wrappedCallable = Tracers.wrapWithAlternateTraceId(traceIdToUse, "operation", Observability.UNDECIDED, TracersTest::getCurrentTrace);
List<OpenSpan> spans = wrappedCallable.call();
assertThat(spans).hasSize(1);
OpenSpan span = spans.get(0);
assertThat(span.getOperation()).isEqualTo("operation");
assertThat(span.getParentSpanId()).isEmpty();
}
use of com.palantir.tracing.api.OpenSpan in project tracing-java by palantir.
the class CloseableTracerTest method startsAndClosesSpanWithType.
@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();
}
Aggregations