Tries to determine the URI path template for this request, and returns null if no such template could be found.
i.e. We try to return
/foo/:id (or however your framework shows path template) rather than
/foo/12345.
The rules this method follows for trying to find the path template:
-
We look in
HttpServletRequest#getAttribute(String) for a request attribute matching
KnownZipkinTags#HTTP_ROUTE ("http.route"). If we find a non-empty http.route attribute, then
we'll use it as the path template.
-
If there was no http.route request attribute, then we'll look for Spring's
"best matching pattern" attribute (
#SPRING_BEST_MATCHING_PATTERN_REQUEST_ATTRIBUTE_KEY).
In particular, note that we're not falling back to
HttpServletRequest#getServletPath(), because while
that works in some cases for raw Servlets, many popular Servlet frameworks don't honor the spirit of that
method's javadocs and return full URIs. If you're working in a system where you know
HttpServletRequest#getServletPath() is safe to use, then you can call
request.setAttribute(KnownZipkinTags.HTTP_ROUTE, request.getServletPath()) and this method will use it.
A similar trick of setting http.route as a request attribute can be used anytime by any code to set the path
template that will be used.