Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zxy1994 opened this issue Jan 6, 2022 · 7 comments
Open

Comments

@zxy1994
Copy link

zxy1994 commented Jan 6, 2022

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
Copy link
Member

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
Copy link
Member

@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
Copy link
Author

zxy1994 commented Jan 7, 2022

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

@minwoo-jung
Copy link
Member

@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
Copy link
Author

zxy1994 commented Jan 7, 2022

@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
Copy link
Author

zxy1994 commented Jun 14, 2024

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

@zxy1994 zxy1994 closed this as completed Jun 14, 2024
@emeroad emeroad reopened this Jun 14, 2024
@emeroad emeroad added this to the 3.0.1 milestone Jun 14, 2024
@emeroad emeroad modified the milestones: 3.0.1, 3.0.2 Jun 14, 2024
@emeroad
Copy link
Member

emeroad commented Jun 14, 2024

We will be reviewing this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants