提交 21696f13 编写于 作者: A ascrutae

fix http client plugin test failure issue

上级 c4b61098
......@@ -16,6 +16,9 @@ import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import java.net.MalformedURLException;
import java.net.URL;
/**
* {@link HttpClientExecuteInterceptor} transport the trace context by call {@link HttpRequest#setHeader(Header)},
* The current span tag the {@link Tags#ERROR} if {@link StatusLine#getStatusCode()} is not equals 200.
......@@ -36,13 +39,12 @@ public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterc
}
HttpHost httpHost = (HttpHost) allArguments[0];
HttpRequest httpRequest = (HttpRequest) allArguments[1];
Span span = ContextManager.INSTANCE.createSpan(httpRequest.getRequestLine().getUri());
Span span = createSpan(httpRequest);
Tags.PEER_PORT.set(span, httpHost.getPort());
Tags.PEER_HOST.set(span, httpHost.getHostName());
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT);
Tags.COMPONENT.set(span, COMPONENT_NAME);
Tags.URL.set(span, generateURL(httpHost, httpRequest));
Tags.URL.set(span, generateURL(httpRequest));
Tags.SPAN_LAYER.asHttp(span);
ContextCarrier contextCarrier = new ContextCarrier();
......@@ -55,10 +57,24 @@ public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterc
*
* @return request URL
*/
private String generateURL(HttpHost httpHost, HttpRequest httpRequest) {
private String generateURL(HttpRequest httpRequest) {
return httpRequest.getRequestLine().getUri();
}
/**
* Create span.
*/
private Span createSpan(HttpRequest httpRequest) {
Span span;
try {
URL url = new URL(httpRequest.getRequestLine().getUri());
span = ContextManager.INSTANCE.createSpan(url.getPath());
} catch (MalformedURLException e) {
span = ContextManager.INSTANCE.createSpan(httpRequest.getRequestLine().getUri());
}
return span;
}
@Override
public Object afterMethod(EnhancedClassInstanceContext context,
InstanceMethodInvokeContext interceptorContext, Object ret) {
......
......@@ -77,7 +77,7 @@ public class HttpClientExecuteInterceptorTest {
@Override
public String getUri() {
return "/test-web/test";
return "http://127.0.0.1:8080/test-web/test";
}
});
when(httpHost.getPort()).thenReturn(8080);
......@@ -151,7 +151,7 @@ public class HttpClientExecuteInterceptorTest {
private void assertHttpSpan(Span span) {
assertThat(span.getOperationName(), is("/test-web/test"));
assertThat(Tags.COMPONENT.get(span), is("Http"));
assertThat(Tags.COMPONENT.get(span), is("HttpClient"));
assertThat(Tags.PEER_HOST.get(span), is("127.0.0.1"));
assertThat(Tags.PEER_PORT.get(span), is(8080));
assertThat(Tags.URL.get(span), is("http://127.0.0.1:8080/test-web/test"));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册