From ea8a4963a23464dafa03b6a7ce3e9d25e1d0e163 Mon Sep 17 00:00:00 2001 From: ralphgj Date: Mon, 18 Jan 2021 19:49:33 +0800 Subject: [PATCH] fix recording url tag with wrong port (#6214) --- CHANGES.md | 1 + .../spring/resttemplate/async/RestExecuteInterceptor.java | 4 ++-- .../spring/resttemplate/sync/RestExecuteInterceptor.java | 4 ++-- .../scenarios/jdk-threading-scenario/config/expectedData.yaml | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 694be6013..8aa8860fe 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -34,6 +34,7 @@ Release Notes. * Fix duplicated `EnhancedInstance` interface added. * Fix thread leaks caused by the elasticsearch-6.x-plugin plugin. * Support reading segmentId and spanId with toolkit. +* Fix RestTemplate plugin recording url tag with wrong port #### OAP-Backend diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestExecuteInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestExecuteInterceptor.java index 62e89fc7b..896584530 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestExecuteInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestExecuteInterceptor.java @@ -50,8 +50,8 @@ public class RestExecuteInterceptor implements InstanceMethodsAroundInterceptor AbstractSpan span = ContextManager.createExitSpan(uri, contextCarrier, remotePeer); span.setComponent(ComponentsDefine.SPRING_REST_TEMPLATE); - Tags.URL.set(span, requestURL.getScheme() + "://" + requestURL.getHost() + ":" + requestURL.getPort() + requestURL - .getPath()); + Tags.URL.set(span, requestURL.getScheme() + "://" + requestURL.getHost() + + (requestURL.getPort() > 0 ? ":" + requestURL.getPort() : "") + requestURL.getPath()); Tags.HTTP.METHOD.set(span, httpMethod.toString()); SpanLayer.asHttp(span); RestTemplateRuntimeContextHelper.addUri(uri); diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/RestExecuteInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/RestExecuteInterceptor.java index b8b2f98f4..2e9a1290f 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/RestExecuteInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/sync/RestExecuteInterceptor.java @@ -46,8 +46,8 @@ public class RestExecuteInterceptor implements InstanceMethodsAroundInterceptor AbstractSpan span = ContextManager.createExitSpan(formatURIPath, contextCarrier, remotePeer); span.setComponent(ComponentsDefine.SPRING_REST_TEMPLATE); - Tags.URL.set(span, requestURL.getScheme() + "://" + requestURL.getHost() + ":" + requestURL.getPort() + requestURL - .getPath()); + Tags.URL.set(span, requestURL.getScheme() + "://" + requestURL.getHost() + + (requestURL.getPort() > 0 ? ":" + requestURL.getPort() : "") + requestURL.getPath()); Tags.HTTP.METHOD.set(span, httpMethod.toString()); SpanLayer.asHttp(span); diff --git a/test/plugin/scenarios/jdk-threading-scenario/config/expectedData.yaml b/test/plugin/scenarios/jdk-threading-scenario/config/expectedData.yaml index 48975dc3a..bdc90d470 100644 --- a/test/plugin/scenarios/jdk-threading-scenario/config/expectedData.yaml +++ b/test/plugin/scenarios/jdk-threading-scenario/config/expectedData.yaml @@ -48,7 +48,7 @@ segmentItems: spanType: Exit peer: github.com:443 tags: - - {key: url, value: 'https://github.com:-1/apache/skywalking'} + - {key: url, value: 'https://github.com/apache/skywalking'} - {key: http.method, value: GET} skipAnalysis: 'false' - operationName: Threading/test.apache.skywalking.apm.testcase.jdk.threading.Application$TestController$1/run @@ -81,7 +81,7 @@ segmentItems: spanType: Exit peer: github.com:443 tags: - - {key: url, value: 'https://github.com:-1/apache/skywalking'} + - {key: url, value: 'https://github.com/apache/skywalking'} - {key: http.method, value: GET} skipAnalysis: 'false' - operationName: Threading/test.apache.skywalking.apm.testcase.jdk.threading.Application$TestController$2/call