Skip to content

Commit

Permalink
Fix Agent Plugin "asynchttpclient" not record the status code of the … (
Browse files Browse the repository at this point in the history
  • Loading branch information
darcyda1 authored Apr 3, 2021
1 parent 0dd9cc1 commit 573c335
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand All @@ -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;
Expand All @@ -49,6 +50,11 @@ public AsyncHandlerWrapper(AsyncHandler asyncHandler, AbstractSpan span) {

@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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 573c335

Please sign in to comment.