HttpSpanFactory { public static @NotNull String getSpanName(@Nullable HttpServletRequest request) { String pathTemplate = determineUriPathTemplate(request); String method = (request == null) ? null : request.getMethod(); return HttpRequestTracingUtils.generateSafeSpanName(method, pathTemplate, (Integer)null); } private  HttpSpanFactory(); static Span fromHttpServletRequest(HttpServletRequest servletRequest, List<String> userIdHeaderKeys); static String getUserIdFromHttpServletRequest(HttpServletRequest servletRequest, List<String> userIdHeaderKeys); static @Nullable String determineUriPathTemplate(@Nullable HttpServletRequest request); static @NotNull String getSpanName(@Nullable HttpServletRequest request);  }
@DataProvider(value = { "GET | /some/http/route | /some/spring/pattern | GET /some/http/route", "GET | /some/http/route | null | GET /some/http/route", "GET | /some/http/route | | GET /some/http/route", "GET | /some/http/route | [whitespace] | GET /some/http/route", "GET | null | /some/spring/pattern | GET /some/spring/pattern", "GET | | /some/spring/pattern | GET /some/spring/pattern", "GET | [whitespace] | /some/spring/pattern | GET /some/spring/pattern", "GET | null | null | GET", "GET | | | GET", "GET | [whitespace] | [whitespace] | GET", "null | /some/http/route | null | UNKNOWN_HTTP_METHOD /some/http/route", " | /some/http/route | null | UNKNOWN_HTTP_METHOD /some/http/route", "[whitespace] | /some/http/route | null | UNKNOWN_HTTP_METHOD /some/http/route", "null | null | /some/spring/pattern | UNKNOWN_HTTP_METHOD /some/spring/pattern", " | null | /some/spring/pattern | UNKNOWN_HTTP_METHOD /some/spring/pattern", "[whitespace] | null | /some/spring/pattern | UNKNOWN_HTTP_METHOD /some/spring/pattern", "null | /some/http/route | /some/spring/pattern | UNKNOWN_HTTP_METHOD /some/http/route", "null | null | null | UNKNOWN_HTTP_METHOD", " | | | UNKNOWN_HTTP_METHOD", "[whitespace] | [whitespace] | [whitespace] | UNKNOWN_HTTP_METHOD", }, splitBy = "\\|") @Test public void getSpanName_works_as_expected( String httpMethod, String httpRouteRequestAttr, String springMatchingPatternRequestAttr, String expectedResult ) { if ("[whitespace]".equals(httpMethod)) { httpMethod = " \t\r\n "; } if ("[whitespace]".equals(httpRouteRequestAttr)) { httpRouteRequestAttr = " \t\r\n "; } if ("[whitespace]".equals(springMatchingPatternRequestAttr)) { springMatchingPatternRequestAttr = " \t\r\n "; } doReturn(httpMethod).when(request).getMethod(); doReturn(httpRouteRequestAttr).when(request).getAttribute(KnownZipkinTags.HTTP_ROUTE); doReturn(springMatchingPatternRequestAttr) .when(request).getAttribute(HttpSpanFactory.SPRING_BEST_MATCHING_PATTERN_REQUEST_ATTRIBUTE_KEY); String result = HttpSpanFactory.getSpanName(request); assertThat(result).isEqualTo(expectedResult); }
@Test public void getSpanName_returns_UNKNOWN_HTTP_METHOD_when_passed_null_request() { assertThat(HttpSpanFactory.getSpanName(null)).isEqualTo("UNKNOWN_HTTP_METHOD"); }