Fix the issue of createSpan failure caused by invalid request URL in HttpClient 4.x/5.x plugin (#603)
This commit is contained in:
parent
44b8f669a9
commit
922a5001fa
|
|
@ -6,6 +6,7 @@ Release Notes.
|
|||
------------------
|
||||
|
||||
* Fix hbase onConstruct NPE in the file configuration scenario
|
||||
* Fix the issue of createSpan failure caused by invalid request URL in HttpClient 4.x/5.x plugin
|
||||
* Optimize ElasticSearch 6.x 7.x plugin compatibility
|
||||
|
||||
#### Documentation
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import org.apache.skywalking.apm.plugin.httpclient.HttpClientPluginConfig;
|
|||
import org.apache.skywalking.apm.util.StringUtil;
|
||||
|
||||
public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
private static final String ERROR_URI = "/_blank";
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
|
|
@ -60,7 +61,9 @@ public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterc
|
|||
String requestURI = getRequestURI(uri);
|
||||
String operationName = requestURI;
|
||||
AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, remotePeer);
|
||||
|
||||
if (ERROR_URI.equals(requestURI)) {
|
||||
span.errorOccurred();
|
||||
}
|
||||
span.setComponent(ComponentsDefine.HTTPCLIENT);
|
||||
Tags.URL.set(span, buildSpanValue(httpHost, uri));
|
||||
Tags.HTTP.METHOD.set(span, httpRequest.getRequestLine().getMethod());
|
||||
|
|
@ -112,9 +115,14 @@ public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterc
|
|||
activeSpan.log(t);
|
||||
}
|
||||
|
||||
private String getRequestURI(String uri) throws MalformedURLException {
|
||||
private String getRequestURI(String uri) {
|
||||
if (isUrl(uri)) {
|
||||
String requestPath = new URL(uri).getPath();
|
||||
String requestPath;
|
||||
try {
|
||||
requestPath = new URL(uri).getPath();
|
||||
} catch (MalformedURLException e) {
|
||||
return ERROR_URI;
|
||||
}
|
||||
return requestPath != null && requestPath.length() > 0 ? requestPath : "/";
|
||||
} else {
|
||||
return uri;
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import java.net.MalformedURLException;
|
|||
import java.net.URL;
|
||||
|
||||
public class HttpClientDoExecuteInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
private static final String ERROR_URI = "/_blank";
|
||||
|
||||
private static final ILog LOGGER = LogManager.getLogger(HttpClientDoExecuteInterceptor.class);
|
||||
|
||||
|
|
@ -59,7 +60,9 @@ public class HttpClientDoExecuteInterceptor implements InstanceMethodsAroundInte
|
|||
String requestURI = getRequestURI(uri);
|
||||
String operationName = requestURI;
|
||||
AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, remotePeer);
|
||||
|
||||
if (ERROR_URI.equals(requestURI)) {
|
||||
span.errorOccurred();
|
||||
}
|
||||
span.setComponent(ComponentsDefine.HTTPCLIENT);
|
||||
Tags.URL.set(span, buildURL(httpHost, uri));
|
||||
Tags.HTTP.METHOD.set(span, httpRequest.getMethod());
|
||||
|
|
@ -101,9 +104,14 @@ public class HttpClientDoExecuteInterceptor implements InstanceMethodsAroundInte
|
|||
activeSpan.log(t);
|
||||
}
|
||||
|
||||
private String getRequestURI(String uri) throws MalformedURLException {
|
||||
private String getRequestURI(String uri) {
|
||||
if (isUrl(uri)) {
|
||||
String requestPath = new URL(uri).getPath();
|
||||
String requestPath;
|
||||
try {
|
||||
requestPath = new URL(uri).getPath();
|
||||
} catch (MalformedURLException e) {
|
||||
return ERROR_URI;
|
||||
}
|
||||
return requestPath != null && requestPath.length() > 0 ? requestPath : "/";
|
||||
} else {
|
||||
return uri;
|
||||
|
|
|
|||
Loading…
Reference in New Issue