This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/master by this push:
     new 573c335  Fix Agent Plugin "asynchttpclient" not record the status code 
of the … (#6665)
573c335 is described below

commit 573c3359caf805740358de4e75ea4498e5c69b21
Author: Darcy <[email protected]>
AuthorDate: Sat Apr 3 15:42:59 2021 +0800

    Fix Agent Plugin "asynchttpclient" not record the status code of the … 
(#6665)
---
 CHANGES.md                                                        | 1 +
 .../apm/plugin/asynchttpclient/v2/AsyncHandlerWrapper.java        | 8 +++++++-
 .../scenarios/asynchttpclient-scenario/config/expectedData.yaml   | 1 +
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/CHANGES.md b/CHANGES.md
index ce5160b..d070996 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -29,6 +29,7 @@ Release Notes.
 * Fix bug that springmvn-annotation-4.x-plugin, witness class does not exist 
in some versions.
 * Add Redis command parameters to 'db.statement' field on Lettuce span UI for 
displaying more info
 * Fix NullPointerException with `ReactiveRequestHolder.getHeaders`.
+* Fix bug that asynchttpclient plugin does not record the response status code
 
 #### OAP-Backend
 * Allow user-defined `JAVA_OPTS` in the startup script.
diff --git 
a/apm-sniffer/apm-sdk-plugin/asynchttpclient-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/asynchttpclient/v2/AsyncHandlerWrapper.java
 
b/apm-sniffer/apm-sdk-plugin/asynchttpclient-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/asynchttpclient/v2/AsyncHandlerWrapper.java
index 0562d34..c668231 100644
--- 
a/apm-sniffer/apm-sdk-plugin/asynchttpclient-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/asynchttpclient/v2/AsyncHandlerWrapper.java
+++ 
b/apm-sniffer/apm-sdk-plugin/asynchttpclient-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/asynchttpclient/v2/AsyncHandlerWrapper.java
@@ -22,6 +22,7 @@ import io.netty.handler.codec.http.HttpHeaders;
 import java.net.InetSocketAddress;
 import java.util.List;
 import javax.net.ssl.SSLSession;
+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.logging.api.ILog;
 import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
@@ -40,7 +41,7 @@ public class AsyncHandlerWrapper implements AsyncHandler {
     private final AsyncHandler userAsyncHandler;
     private final AbstractSpan asyncSpan;
 
-    private static ILog LOGGER = 
LogManager.getLogger(AsyncHandlerWrapper.class);
+    private static final ILog LOGGER = 
LogManager.getLogger(AsyncHandlerWrapper.class);
 
     public AsyncHandlerWrapper(AsyncHandler asyncHandler, AbstractSpan span) {
         this.userAsyncHandler = asyncHandler == null ? new 
AsyncCompletionHandlerBase() : asyncHandler;
@@ -49,6 +50,11 @@ public class AsyncHandlerWrapper implements AsyncHandler {
 
     @Override
     public State onStatusReceived(final HttpResponseStatus httpResponseStatus) 
throws Exception {
+        int statusCode = httpResponseStatus.getStatusCode();
+        Tags.STATUS_CODE.set(asyncSpan, String.valueOf(statusCode));
+        if (statusCode >= 400) {
+            asyncSpan.errorOccurred();
+        }
         return userAsyncHandler.onStatusReceived(httpResponseStatus);
     }
 
diff --git 
a/test/plugin/scenarios/asynchttpclient-scenario/config/expectedData.yaml 
b/test/plugin/scenarios/asynchttpclient-scenario/config/expectedData.yaml
index 1eed6c1..1db379f 100644
--- a/test/plugin/scenarios/asynchttpclient-scenario/config/expectedData.yaml
+++ b/test/plugin/scenarios/asynchttpclient-scenario/config/expectedData.yaml
@@ -34,6 +34,7 @@ segmentItems:
             tags:
               - {key: http.method, value: GET}
               - {key: url, value: 'http://localhost:8080/asynchttpclient/back'}
+              - {key: status_code, value: '200'}
           - operationName: /asynchttpclient/case
             operationId: 0
             parentSpanId: -1

Reply via email to