@Test public void getSpanName_returns_UNKNOWN_HTTP_METHOD_when_passed_null_request() { // expect assertThat(HttpSpanFactory.getSpanName(null)).isEqualTo("UNKNOWN_HTTP_METHOD"); } }
/** * @param request The incoming request. * @param namingStrategy The {@link HttpTagAndSpanNamingStrategy} that should be used to try and generate the * initial span name - cannot be null. * @param adapter The {@link HttpTagAndSpanNamingAdapter} that should be passed to the given {@code namingStrategy} * to try and generate the initial span name - cannot be null. * @return The human-readable name to be given to a {@link Span} representing this request. By default this method * attempts to use {@link HttpTagAndSpanNamingStrategy#getInitialSpanName(Object, HttpTagAndSpanNamingAdapter)} * with the given {@code namingStrategy} and {@code adapter} for generating the name, and falls back to * {@link HttpSpanFactory#getSpanName(HttpServletRequest)} if the {@link HttpTagAndSpanNamingStrategy} returns * null or blank. */ protected String getInitialSpanName( HttpServletRequest request, HttpTagAndSpanNamingStrategy<HttpServletRequest, ?> namingStrategy, HttpTagAndSpanNamingAdapter<HttpServletRequest, ?> adapter ) { // Try the naming strategy first. String spanNameFromStrategy = namingStrategy.getInitialSpanName(request, adapter); if (StringUtils.isNotBlank(spanNameFromStrategy)) { return spanNameFromStrategy; } // The naming strategy didn't have anything for us. Fall back to something reasonable. return HttpSpanFactory.getSpanName(request); }
String result = HttpSpanFactory.getSpanName(request);
/** * @return A {@link Span} object created from the headers if they exist (see {@link #fromHttpServletRequest(HttpServletRequest, List)} for details), or if the headers don't * have enough information then this will return a new root span with a span name based on the results of {@link #getSpanName(HttpServletRequest)} and user ID based * on the result of {@link #getUserIdFromHttpServletRequest(HttpServletRequest, List)}. Since this method is for a server receiving a request * the returned span's {@link Span#getSpanPurpose()} will be {@link SpanPurpose#SERVER}. */ public static Span fromHttpServletRequestOrCreateRootSpan(HttpServletRequest servletRequest, List<String> userIdHeaderKeys) { Span span = fromHttpServletRequest(servletRequest, userIdHeaderKeys); if (span == null) { span = Span .generateRootSpanForNewTrace(getSpanName(servletRequest), SpanPurpose.SERVER) .withUserId(getUserIdFromHttpServletRequest(servletRequest, userIdHeaderKeys)) .build(); } return span; }