pinpoint-apm / pinpoint

APM, (Application Performance Management) tool for large-scale distributed systems.
https://pinpoint-apm.gitbook.io/
Apache License 2.0
13.29k stars 3.75k forks source link

Error in getting http status code by springcloud gateway( reactor-netty ) #8586

Open zxy1994 opened 2 years ago

zxy1994 commented 2 years ago

Sorry, my English level is not very good, but I try my best.

Prerequisites

I have checked the FAQ, and issues and found no answer.

What version of pinpoint are you using?

v2.3.3

Describe the bug

Error in getting http status code by springcloud gateway( reactor-netty ) ;

  1. The http status code returned on the gateway is 400, but it is shown as 200 on Pinpoint.

  2. This error should be due to the wrong http status code obtained by pinpoint plug-in(pinpoint-reactor-netty-plugin).

  3. The following two images mainly illustrate that the program actually failed, but the gateway still showed success. 1 2

  4. The following two images mainly show that the status code actually returned by the gateway is 400, but it is shown as 200 on pinpoint. 3 4

minwoo-jung commented 2 years ago

Hi @zxy1994 This is because only a part of it is profiling with reactor-netty plugin. In other words, it is because the plugin was not developed until springcloud gateway and the springcloud gateway did not profiling correctly. We recommend that you try to develop the plugin yourself. guide

minwoo-jung commented 2 years ago

@zxy1994 I have an additional question. Is it correct that the call test below called the gateway server? Isn't a 400 error occurred by calling the dev-ark-clouddevice server directly? image

I thought it was because the stack trace was being traced very cleanly.

zxy1994 commented 2 years ago

@minwoo-jung
my gateway HTTP port is 7100, So this request is sent directly to the gateway。 5

minwoo-jung commented 2 years ago

@zxy1994 okay For now, this answer seems to be the most correct. In addition, I'll let you know if I have more to look into and share.

zxy1994 commented 2 years ago

@zxy1994 okay For now, this answer seems to be the most correct. In addition, I'll let you know if I have more to look into and share.

대단히 감사합니다

zxy1994 commented 2 weeks ago

I have found the answer to this question and can solve this bug by modifying the code. The specific code is as follows。

com.navercorp.pinpoint.plugin.reactor.netty.interceptor.HttpClientOperationsOnInboundNextInterceptor

@Override
public void doInBeforeTrace(SpanEventRecorder recorder, AsyncContext asyncContext, Object target, Object[] args) {
final HttpResponse httpResponses = (HttpResponse) args[1];
try {
final HttpResponseStatus httpResponseStatus = httpResponses.status();
if (httpResponseStatus != null) {
recorder.recordAttribute(AnnotationKey.HTTP_STATUS_CODE, httpResponseStatus.code());
final int httpStatusCode = httpResponseStatus.code();
// resolve the call tree `http.status.code` displayed error,
// if the onInboundNext records the status code not 200. we need to update the trace `http.status.code`.
// see #8586
if (httpStatusCode != 200) {
// the code like --> asyncContext.currentAsyncTraceObject().getSpanRecorder().recordStatusCode(httpResponseStatus.code());
// but use HttpStatusCodeRecorder is better than the code
Optional.ofNullable(asyncContext)
.map(AsyncContext::currentAsyncTraceObject)
.map(Trace::getSpanRecorder)
.ifPresent(x-> httpStatusCodeRecorder.record(x, httpStatusCode));
}
}
this.responseHeaderRecorder.recordHeader(recorder, httpResponses);
} catch (Exception ignored) {
}
}

The code in the red box in the figure is important code DevCap_20240614_123110

The effect before modifying the code is shown in the following figure

DevCap_20240614_115241

The effect after modifying the code is shown in the following figure

DevCap_20240614_122556

emeroad commented 2 weeks ago

We will be reviewing this bug.