Merge pull request #717 from ascrutae/fix/url-port-issue

[Agent] fix the remote port is incorrect
This commit is contained in:
吴晟 Wu Sheng 2017-12-31 12:02:56 +08:00 committed by GitHub
commit 1441493067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 8 deletions

View File

@ -16,22 +16,22 @@
*
*/
package org.apache.skywalking.apm.plugin.httpClient.v4;
import io.netty.handler.codec.http.HttpScheme;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.skywalking.apm.agent.core.context.CarrierItem;
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.context.CarrierItem;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
@ -48,7 +48,10 @@ public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterc
HttpRequest httpRequest = (HttpRequest)allArguments[1];
final ContextCarrier contextCarrier = new ContextCarrier();
AbstractSpan span = null;
String remotePeer = httpHost.getHostName() + ":" + httpHost.getPort();
String remotePeer = httpHost.getHostName() + ":" + (httpHost.getPort() > 0 ? httpHost.getPort() :
HttpScheme.HTTPS.name().equals(httpHost.getSchemeName().toLowerCase()) ? 443 : 80);
try {
URL url = new URL(httpRequest.getRequestLine().getUri());
span = ContextManager.createExitSpan(url.getPath(), contextCarrier, remotePeer);

View File

@ -16,7 +16,6 @@
*
*/
package org.apache.skywalking.apm.plugin.spring.resttemplate.async;
import java.lang.reflect.Method;
@ -40,7 +39,8 @@ public class RestExecuteInterceptor implements InstanceMethodsAroundInterceptor
final URI requestURL = (URI)allArguments[0];
final HttpMethod httpMethod = (HttpMethod)allArguments[1];
final ContextCarrier contextCarrier = new ContextCarrier();
String remotePeer = requestURL.getHost() + ":" + requestURL.getPort();
String remotePeer = requestURL.getHost() + ":" + (requestURL.getPort() > 0 ? requestURL.getPort() : "https".equalsIgnoreCase(requestURL.getScheme()) ? 443 : 80);
AbstractSpan span = ContextManager.createExitSpan(requestURL.getPath(), contextCarrier, remotePeer);
span.setComponent(ComponentsDefine.SPRING_REST_TEMPLATE);

View File

@ -16,7 +16,6 @@
*
*/
package org.apache.skywalking.apm.plugin.spring.resttemplate.sync;
import java.lang.reflect.Method;
@ -40,7 +39,8 @@ public class RestExecuteInterceptor implements InstanceMethodsAroundInterceptor
final URI requestURL = (URI)allArguments[0];
final HttpMethod httpMethod = (HttpMethod)allArguments[1];
final ContextCarrier contextCarrier = new ContextCarrier();
String remotePeer = requestURL.getHost() + ":" + requestURL.getPort();
String remotePeer = requestURL.getHost() + ":" + (requestURL.getPort() > 0 ? requestURL.getPort() : "https".equalsIgnoreCase(requestURL.getScheme()) ? 443 : 80);
AbstractSpan span = ContextManager.createExitSpan(requestURL.getPath(), contextCarrier, remotePeer);
span.setComponent(ComponentsDefine.SPRING_REST_TEMPLATE);