Search in sources :

Example 1 with OpenSpan

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());
}
Also used : OpenSpan(com.palantir.tracing.api.OpenSpan) Test(org.junit.Test)

Example 2 with OpenSpan

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();
}
Also used : OpenSpan(com.palantir.tracing.api.OpenSpan) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.Test)

Example 3 with OpenSpan

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();
}
Also used : OpenSpan(com.palantir.tracing.api.OpenSpan) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.Test)

Example 4 with OpenSpan

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();
}
Also used : OpenSpan(com.palantir.tracing.api.OpenSpan) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.Test)

Example 5 with OpenSpan

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();
}
Also used : OpenSpan(com.palantir.tracing.api.OpenSpan) Test(org.junit.Test)

Aggregations

OpenSpan (com.palantir.tracing.api.OpenSpan)17 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)7 List (java.util.List)7 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)7 Span (com.palantir.tracing.api.Span)3 SpanObserver (com.palantir.tracing.api.SpanObserver)2 CheckReturnValue (com.google.errorprone.annotations.CheckReturnValue)1 Request (okhttp3.Request)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1