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 ChannelPipelineFinalizerHandlerTest method doChannelInactive_does_not_try_to_recomplete_span_if_already_completed.
@Test
public void doChannelInactive_does_not_try_to_recomplete_span_if_already_completed() throws Exception {
// given
Span span = setupTracingForChannelInactive(false);
Deque<Span> deque = new LinkedList<>();
deque.add(span);
Tracer.getInstance().registerWithThread(deque);
Tracer.getInstance().completeRequestSpan();
Assertions.assertThat(span.isCompleted()).isTrue();
long durationNanosBefore = span.getDurationNanos();
// when
PipelineContinuationBehavior result = handler.doChannelInactive(ctxMock);
// then
// no change
Assertions.assertThat(span.isCompleted()).isTrue();
Assertions.assertThat(span.getDurationNanos()).isEqualTo(durationNanosBefore);
verify(requestInfoMock).releaseAllResources();
verify(proxyRouterStateMock).cancelRequestStreaming(any(), any());
verify(proxyRouterStateMock).cancelDownstreamRequest(any());
Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
use of com.nike.wingtips.Span in project riposte by Nike-Inc.
the class VerifyProxyRouterTracingBehaviorComponentTest method proxy_endpoint_tracing_behavior_should_work_as_desired_when_orig_request_does_have_tracing_headers.
@DataProvider(value = { "HEADERS_ON_SUBSPAN_ON | true", "HEADERS_ON_SUBSPAN_ON | false", "HEADERS_OFF_SUBSPAN_ON | true", "HEADERS_OFF_SUBSPAN_ON | false", "HEADERS_ON_SUBSPAN_OFF | true", "HEADERS_ON_SUBSPAN_OFF | false", "HEADERS_OFF_SUBSPAN_OFF | true", "HEADERS_OFF_SUBSPAN_OFF | false" }, splitBy = "\\|")
@Test
public void proxy_endpoint_tracing_behavior_should_work_as_desired_when_orig_request_does_have_tracing_headers(TracingBehaviorScenario scenario, boolean sampled) {
Span origCallSpan = Span.newBuilder("origCall", Span.SpanPurpose.CLIENT).withSampleable(sampled).build();
Map<String, String> tracingHeaders = new HashMap<>();
HttpRequestTracingUtils.propagateTracingHeaders(tracingHeaders::put, origCallSpan);
ExtractableResponse response = given().baseUri("http://127.0.0.1").port(proxyServerConfig.endpointsPort()).basePath(RouterEndpoint.MATCHING_PATH).header(SET_TRACING_HEADERS_HEADER_KEY, scenario.tracingHeadersOn).header(PERFORM_SUBSPAN_HEADER_KEY, scenario.subspanOn).headers(tracingHeaders).log().all().when().get().then().log().headers().extract();
assertThat(response.statusCode()).isEqualTo(200);
assertThat(response.asString()).isEqualTo(DownstreamEndpoint.RESPONSE_PAYLOAD);
// Verify that the proxy honored the subspan option, and get a handle on the span that surrounded the proxy
// downstream call.
Span spanForDownstreamCall = verifyCompletedSpansAndReturnSpanForDownstreamCall(scenario.subspanOn);
// Sanity checking - spanForDownstreamCall should be a child of origCallSpan (same trace ID and sampleable
// value but different span IDs.
assertThat(spanForDownstreamCall.getTraceId()).isEqualTo(origCallSpan.getTraceId());
assertThat(spanForDownstreamCall.isSampleable()).isEqualTo(origCallSpan.isSampleable());
assertThat(spanForDownstreamCall.getSpanId()).isNotEqualTo(origCallSpan.getSpanId());
if (scenario.tracingHeadersOn) {
// The downstream endpoint should have received tracing headers based on the span surrounding the proxy
// downstream call.
verifyExpectedTracingHeadersReceivedDownstream(response, spanForDownstreamCall);
} else {
// The ProxyRouterEndpoint is configured to *not* set tracing headers, so we should see the values
// from origCallSpan show up on the other end since we sent them with the original call - the proxy
// should not have messed with them.
verifyExpectedTracingHeadersReceivedDownstream(response, origCallSpan);
}
}
use of com.nike.wingtips.Span in project riposte by Nike-Inc.
the class DTraceStartHandlerTest method startTrace_creates_trace_from_parent_if_available_and_sets_expected_span_name_and_tags_and_annotations.
@Test
public void startTrace_creates_trace_from_parent_if_available_and_sets_expected_span_name_and_tags_and_annotations() {
// 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);
assertThat(Tracer.getInstance().getCurrentSpan(), nullValue());
// when
long nanosBefore = System.nanoTime();
handler.startTrace(httpRequest, ctxMock);
long nanosAfter = System.nanoTime();
// 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(initialSpanNameFromStrategy.get()));
assertThat(span.getUserId(), is(parentUserId));
assertThat(span.isSampleable(), is(Boolean.valueOf(parentTraceEnabled)));
strategyInitialSpanNameArgs.get().verifyArgs(requestInfoMock, tagAndNamingAdapterMock);
strategyRequestTaggingArgs.get().verifyArgs(span, requestInfoMock, tagAndNamingAdapterMock);
long expectedMaxWireReceiveStartTimestamp = span.getSpanStartTimeEpochMicros() + TimeUnit.NANOSECONDS.toMicros(nanosAfter - nanosBefore);
TimestampedAnnotation wireReceiveStartAnnotation = findAnnotationInSpan(span, "wr.start");
Assertions.assertThat(wireReceiveStartAnnotation.getTimestampEpochMicros()).isBetween(span.getSpanStartTimeEpochMicros(), expectedMaxWireReceiveStartTimestamp);
}
use of com.nike.wingtips.Span in project riposte by Nike-Inc.
the class DTraceStartHandlerTest method doChannelRead_adds_wire_receive_finish_annotation_whem_msg_is_LastHttpContent_if_desired.
@DataProvider(value = { "true | true | true", "true | false | false", "false | true | false", "false | false | false" }, splitBy = "\\|")
@Test
public void doChannelRead_adds_wire_receive_finish_annotation_whem_msg_is_LastHttpContent_if_desired(boolean addWireReceiveFinishAnnotationConfigValue, boolean overallRequestSpanExists, boolean expectAnnotation) {
// given
DTraceStartHandler handlerSpy = spy(handler);
HttpProcessingState stateSpy = spy(state);
doReturn(stateSpy).when(stateAttributeMock).get();
Span spanMock = (overallRequestSpanExists) ? mock(Span.class) : null;
doReturn(spanMock).when(stateSpy).getOverallRequestSpan();
shouldAddWireReceiveFinishAnnotation = addWireReceiveFinishAnnotationConfigValue;
// when
PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, new DefaultLastHttpContent());
// then
if (expectAnnotation) {
verify(spanMock).addTimestampedAnnotationForCurrentTime(distributedTracingConfig.getServerSpanNamingAndTaggingStrategy().wireReceiveFinishAnnotationName());
verifyNoMoreInteractions(spanMock);
} else if (spanMock != null) {
verify(spanMock, never()).addTimestampedAnnotationForCurrentTime(anyString());
}
Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Aggregations