/** * By default this method uses a combination of {@link #getSpanNamePrefix(Object)} and {@link * HttpRequestTracingUtils#generateSafeSpanName(Object, Object, HttpTagAndSpanNamingAdapter)} to generate a name. * You can override this method if you need different behavior. * * @param request The request object to be inspected - <b>this may be null!</b> * @param response The response object to be inspected - <b>this may be null!</b> * * @return The final span name that this adapter wants to use for a span around the given request, or null * if this adapter can't (or doesn't want to) come up with a name. Callers should always check for a null return * value, and should not change the preexisting initial span name if this returns null. */ public @Nullable String getFinalSpanName(@Nullable REQ request, @Nullable RES response) { String prefix = getSpanNamePrefix(request); String defaultSpanName = HttpRequestTracingUtils.generateSafeSpanName(request, response, this); return (StringUtils.isBlank(prefix)) ? defaultSpanName : prefix + "-" + defaultSpanName; }
/** * By default this method uses a combination of {@link #getSpanNamePrefix(Object)} and {@link * HttpRequestTracingUtils#generateSafeSpanName(Object, Object, HttpTagAndSpanNamingAdapter)} to generate a name. * You can override this method if you need different behavior. * * @param request The request object to be inspected - <b>this may be null!</b> * * @return The initial span name that this adapter wants to use for a span around the given request, or null * if this adapter can't (or doesn't want to) come up with a name. Callers should always check for a null return * value, and come up with a reasonable fallback name in that case. */ public @Nullable String getInitialSpanName(@Nullable REQ request) { String prefix = getSpanNamePrefix(request); String defaultSpanName = HttpRequestTracingUtils.generateSafeSpanName(request, null, this); return (StringUtils.isBlank(prefix)) ? defaultSpanName : prefix + "-" + defaultSpanName; }
@DataProvider(value = { "true", "false" }) @Test public void getSpanNamePrefix_returns_null(boolean passNullRequestObj) { // given Object requestObj = (passNullRequestObj) ? null : new Object(); // when String result = implSpy.getSpanNamePrefix(requestObj); // then assertThat(result).isNull(); }
) { doReturn(prefix).when(implSpy).getSpanNamePrefix(anyObject()); doReturn(httpMethod).when(implSpy).getRequestHttpMethod(anyObject()); doReturn(pathTemplate).when(implSpy).getRequestUriPathTemplate(anyObject(), anyObject());