|
5 | 5 | import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString; |
6 | 6 | import datadog.trace.bootstrap.instrumentation.decorator.BaseDecorator; |
7 | 7 | import java.net.URI; |
8 | | -import java.net.URISyntaxException; |
9 | 8 | import javax.servlet.RequestDispatcher; |
10 | 9 | import javax.servlet.http.HttpServletRequest; |
11 | | -import javax.servlet.jsp.HttpJspPage; |
12 | 10 | import org.apache.jasper.JspCompilationContext; |
13 | | -import org.slf4j.LoggerFactory; |
14 | 11 |
|
15 | 12 | public class JSPDecorator extends BaseDecorator { |
16 | 13 | public static final CharSequence JSP_COMPILE = UTF8BytesString.create("jsp.compile"); |
@@ -68,11 +65,14 @@ public void onRender(final AgentSpan span, final HttpServletRequest req) { |
68 | 65 | // HttpServletRequest#getRequestURL(), |
69 | 66 | // normalizing the URL should remove those symbols for readability and consistency |
70 | 67 | try { |
71 | | - span.setTag( |
72 | | - "jsp.requestURL", (new URI(req.getRequestURL().toString())).normalize().toString()); |
73 | | - } catch (final URISyntaxException uriSE) { |
74 | | - LoggerFactory.getLogger(HttpJspPage.class) |
75 | | - .debug("Failed to get and normalize request URL: {}", uriSE.getMessage()); |
| 68 | + // note: getRequestURL is supposed to always be nonnull - however servlet wrapping can happen |
| 69 | + // and we never know if ever this can happen |
| 70 | + final StringBuffer requestURL = req.getRequestURL(); |
| 71 | + if (requestURL != null && requestURL.length() > 0) { |
| 72 | + span.setTag("jsp.requestURL", (new URI(requestURL.toString())).normalize().toString()); |
| 73 | + } |
| 74 | + } catch (final Throwable ignored) { |
| 75 | + // logging here will be too verbose |
76 | 76 | } |
77 | 77 | } |
78 | 78 | } |
0 commit comments