Loading skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/HttpClientExecuteInterceptor.java +20 −4 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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(); Loading @@ -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) { Loading skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/test/java/com/a/eye/skywalking/plugin/httpClient/v4/HttpClientExecuteInterceptorTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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")); Loading Loading
skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/HttpClientExecuteInterceptor.java +20 −4 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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(); Loading @@ -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) { Loading
skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/test/java/com/a/eye/skywalking/plugin/httpClient/v4/HttpClientExecuteInterceptorTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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")); Loading