ZipkinHttpTagStrategy extends HttpTagAndSpanNamingStrategy<REQ, RES> { @Override protected void doHandleResponseAndErrorTagging( @NotNull Span span, @Nullable REQ request, @Nullable RES response, @Nullable Throwable error, @NotNull HttpTagAndSpanNamingAdapter<REQ, RES> adapter ) { putTagIfValueIsNotBlank(span, KnownZipkinTags.HTTP_ROUTE, adapter.getRequestUriPathTemplate(request, response)); putTagIfValueIsNotBlank(span, KnownZipkinTags.HTTP_STATUS_CODE, adapter.getResponseHttpStatus(response)); if (error != null) { String message = error.getMessage(); if (message == null) { message = error.getClass().getSimpleName(); } addErrorTagToSpan(span, message); } else { String errorTagValue = adapter.getErrorResponseTagValue(response); if (StringUtils.isNotBlank(errorTagValue)) { addErrorTagToSpan(span, errorTagValue); } } }  @SuppressWarnings("unchecked") static ZipkinHttpTagStrategy<REQ, RES> getDefaultInstance();  }
@DataProvider(value = { "ERROR_IS_NOT_NULL_AND_HAS_MESSAGE", "ERROR_IS_NOT_NULL_BUT_HAS_NO_MESSAGE", "ERROR_IS_NULL_BUT_ADAPTER_ERROR_TAG_VALUE_IS_NOT_BLANK", "ERROR_IS_NULL_AND_ADAPTER_ERROR_TAG_VALUE_IS_NULL", "ERROR_IS_NULL_AND_ADAPTER_ERROR_TAG_VALUE_IS_EMPTY", "ERROR_IS_NULL_AND_ADAPTER_ERROR_TAG_VALUE_IS_WHITESPACE" }) @Test public void doHandleResponseAndErrorTagging_puts_expected_tags_based_on_adapter_results_and_error_existence( ErrorTaggingScenario scenario ) { Integer adapterHttpStatus = 42; String adapterRoute = "route-" + UUID.randomUUID().toString(); doReturn(adapterHttpStatus).when(adapterMock).getResponseHttpStatus(anyObject()); doReturn(adapterRoute).when(adapterMock).getRequestUriPathTemplate(anyObject(), anyObject()); doReturn(scenario.adapterErrorTagValue).when(adapterMock).getErrorResponseTagValue(anyObject()); implSpy.doHandleResponseAndErrorTagging(spanMock, requestMock, responseMock, scenario.error, adapterMock); verify(adapterMock).getRequestUriPathTemplate(requestMock, responseMock); verify(adapterMock).getResponseHttpStatus(responseMock); verify(implSpy).putTagIfValueIsNotBlank(spanMock, KnownZipkinTags.HTTP_ROUTE, adapterRoute); verify(implSpy).putTagIfValueIsNotBlank(spanMock, KnownZipkinTags.HTTP_STATUS_CODE, adapterHttpStatus); if (scenario.error == null) { verify(adapterMock).getErrorResponseTagValue(responseMock); } else { verify(adapterMock, never()).getErrorResponseTagValue(anyObject()); } if (scenario.expectErrorTagPutOnSpan) { verify(implSpy).putTagIfValueIsNotBlank(spanMock, KnownZipkinTags.ERROR, scenario.expectedErrorTagValue); } }