WingtipsApacheHttpClientUtil { public static void propagateTracingHeaders(HttpRequest request, Span span) { HttpRequestForPropagation requestForPropagation = (request == null) ? null : new HttpRequestForPropagation(request); HttpRequestTracingUtils.propagateTracingHeaders(requestForPropagation, span); } @SuppressWarnings("WeakerAccess") protected  WingtipsApacheHttpClientUtil(); static void propagateTracingHeaders(HttpRequest request, Span span); static String getFallbackSubspanSpanName(HttpRequest request);  }
@DataProvider(value = { "true | true", "true | false", "false | true", "false | false" }, splitBy = "\\|") @Test public void propagateTracingHeaders_works_as_expected( boolean requestIsNull, boolean spanIsNull ) { if (requestIsNull) requestMock = null; Span spanSpy = (spanIsNull) ? null : spy(Span.newBuilder(UUID.randomUUID().toString(), Span.SpanPurpose.CLIENT) .withParentSpanId(UUID.randomUUID().toString()) .build()); WingtipsApacheHttpClientUtil.propagateTracingHeaders(requestMock, spanSpy); if (requestIsNull || spanIsNull) { if (requestMock != null) verifyZeroInteractions(requestMock); if (spanSpy != null) verifyZeroInteractions(spanSpy); } else { verify(requestMock).setHeader(TRACE_ID, spanSpy.getTraceId()); verify(requestMock).setHeader(SPAN_ID, spanSpy.getSpanId()); verify(requestMock) .setHeader(TRACE_SAMPLED, convertSampleableBooleanToExpectedB3Value(spanSpy.isSampleable())); verify(requestMock).setHeader(PARENT_SPAN_ID, spanSpy.getParentSpanId()); } }
@DataProvider(value = { "true", "false" }) @Test public void propagateTracingHeaders_uses_B3_spec_for_sampleable_header_value( boolean sampleable ) { Span span = Span.newBuilder("foo", Span.SpanPurpose.CLIENT) .withSampleable(sampleable) .build(); WingtipsApacheHttpClientUtil.propagateTracingHeaders(requestMock, span); verify(requestMock) .setHeader(TRACE_SAMPLED, convertSampleableBooleanToExpectedB3Value(span.isSampleable())); }
@DataProvider(value = { "true", "false" }) @Test public void propagateTracingHeaders_only_sends_parent_span_id_header_if_parent_span_id_exists( boolean parentSpanIdExists ) { String parentSpanId = (parentSpanIdExists) ? UUID.randomUUID().toString() : null; Span span = Span.newBuilder("foo", Span.SpanPurpose.CLIENT) .withParentSpanId(parentSpanId) .build(); WingtipsApacheHttpClientUtil.propagateTracingHeaders(requestMock, span); if (parentSpanIdExists) { verify(requestMock).setHeader(PARENT_SPAN_ID, parentSpanId); } else { verify(requestMock, never()).setHeader(eq(PARENT_SPAN_ID), anyString()); } }