use of com.nike.wingtips.Span in project riposte by Nike-Inc.
the class ChannelPipelineFinalizerHandlerTest method setupTracingForChannelInactive.
private Span setupTracingForChannelInactive(boolean traceCompletedOrScheduled) {
state.setTraceCompletedOrScheduled(traceCompletedOrScheduled);
Span span = Span.newBuilder("fooSpan", Span.SpanPurpose.SERVER).build();
Assertions.assertThat(span.isCompleted()).isFalse();
Deque<Span> spanStack = new LinkedList<>();
spanStack.add(span);
state.setDistributedTraceStack(spanStack);
return span;
}
use of com.nike.wingtips.Span in project riposte by Nike-Inc.
the class DTraceEndHandlerTest method endDtrace_completes_the_trace_immediately_if_state_is_not_null_but_isResponseSendingLastChunkSent_returns_false.
@Test
public void endDtrace_completes_the_trace_immediately_if_state_is_not_null_but_isResponseSendingLastChunkSent_returns_false() {
// given
assertThat(state.isTraceCompletedOrScheduled(), is(false));
state.setResponseWriterFinalChunkChannelFuture(null);
assertThat(state.isResponseSendingLastChunkSent(), is(false));
assertThat(state.getDistributedTraceStack(), nullValue());
Pair<Deque<Span>, Map<String, String>> expectedDtraceInfo = setupStateWithNewSpan("blahTrace");
assertThat(state.getDistributedTraceStack(), notNullValue());
assertThat(state.getDistributedTraceStack(), is(expectedDtraceInfo.getLeft()));
assertThat(state.getDistributedTraceStack().size(), is(1));
Span expectedSpan = expectedDtraceInfo.getLeft().peek();
// when
handlerSpy.endDtrace(ctxMock);
// then
verify(handlerSpy).completeCurrentSpan();
assertThat(currentSpanWhenCompleteCurrentSpanWasCalled, is(expectedSpan));
assertThat(currentSpanAfterCompleteCurrentSpanWasCalled, nullValue());
assertThat(state.isTraceCompletedOrScheduled(), is(true));
}
use of com.nike.wingtips.Span in project riposte by Nike-Inc.
the class DTraceStartHandlerTest method startTrace_creates_trace_from_parent_if_available.
@Test
public void startTrace_creates_trace_from_parent_if_available() {
// given
String parentTraceId = UUID.randomUUID().toString();
String parentParentSpanId = UUID.randomUUID().toString();
String parentSpanId = UUID.randomUUID().toString();
String parentSpanName = UUID.randomUUID().toString();
String parentTraceEnabled = "true";
String parentUserId = UUID.randomUUID().toString();
httpRequest.headers().set(TraceHeaders.TRACE_ID, parentTraceId);
httpRequest.headers().set(TraceHeaders.PARENT_SPAN_ID, parentParentSpanId);
httpRequest.headers().set(TraceHeaders.SPAN_ID, parentSpanId);
httpRequest.headers().set(TraceHeaders.SPAN_NAME, parentSpanName);
httpRequest.headers().set(TraceHeaders.TRACE_SAMPLED, parentTraceEnabled);
httpRequest.headers().set(USER_ID_HEADER_KEY, parentUserId);
String expectedSpanName = handler.getSpanName(httpRequest);
assertThat(Tracer.getInstance().getCurrentSpan(), nullValue());
// when
handler.startTrace(httpRequest);
// then
Span span = Tracer.getInstance().getCurrentSpan();
assertThat(span.getTraceId(), is(parentTraceId));
assertThat(span.getParentSpanId(), is(parentSpanId));
assertThat(span.getSpanId(), notNullValue());
assertThat(span.getSpanId(), not(parentSpanId));
assertThat(span.getSpanName(), is(expectedSpanName));
assertThat(span.getUserId(), is(parentUserId));
assertThat(span.isSampleable(), is(Boolean.valueOf(parentTraceEnabled)));
}
use of com.nike.wingtips.Span in project riposte by Nike-Inc.
the class DTraceStartHandlerTest method startTrace_creates_new_trace_if_no_parent_available.
@Test
public void startTrace_creates_new_trace_if_no_parent_available() {
// given
String expectedSpanName = handler.getSpanName(httpRequest);
assertThat(Tracer.getInstance().getCurrentSpan(), nullValue());
// when
handler.startTrace(httpRequest);
// then
Span span = Tracer.getInstance().getCurrentSpan();
assertThat(span.getTraceId(), notNullValue());
assertThat(span.getParentSpanId(), nullValue());
assertThat(span.getSpanId(), notNullValue());
assertThat(span.getSpanName(), is(expectedSpanName));
assertThat(span.getUserId(), nullValue());
}
use of com.nike.wingtips.Span in project riposte by Nike-Inc.
the class AsyncCompletionHandlerWithTracingAndMdcSupportTest method constructor_sets_values_exactly_as_given_when_subtracing_is_off.
@Test
public void constructor_sets_values_exactly_as_given_when_subtracing_is_off() {
// given
CompletableFuture cfResponse = mock(CompletableFuture.class);
AsyncResponseHandler responseHandlerFunc = mock(AsyncResponseHandler.class);
String method = "notused-method";
String url = "notused-url";
Optional<CircuitBreaker<Response>> circuitBreaker = Optional.of(mock(CircuitBreaker.class));
Deque<Span> spanStack = mock(Deque.class);
Map<String, String> mdcInfo = mock(Map.class);
Deque<Span> spanStackBeforeCall = Tracer.getInstance().getCurrentSpanStackCopy();
Map<String, String> mdcInfoBeforeCall = MDC.getCopyOfContextMap();
// when
AsyncCompletionHandlerWithTracingAndMdcSupport instance = new AsyncCompletionHandlerWithTracingAndMdcSupport(cfResponse, responseHandlerFunc, false, method, url, circuitBreaker, spanStack, mdcInfo);
// then
assertThat(instance.completableFutureResponse).isSameAs(cfResponse);
assertThat(instance.responseHandlerFunction).isSameAs(responseHandlerFunc);
assertThat(instance.performSubSpanAroundDownstreamCalls).isEqualTo(false);
assertThat(instance.circuitBreakerManualTask).isSameAs(circuitBreaker);
assertThat(instance.distributedTraceStackToUse).isSameAs(spanStack);
assertThat(instance.mdcContextToUse).isSameAs(mdcInfo);
assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isEqualTo(spanStackBeforeCall);
assertThat(MDC.getCopyOfContextMap()).isEqualTo(mdcInfoBeforeCall);
}
Aggregations