apache / apisix

The Cloud-Native API Gateway
https://apisix.apache.org/blog/
Apache License 2.0
14.32k stars 2.49k forks source link

help request: how to get the error message in nginx error.log from apisix plugin #10617

Open wklken opened 9 months ago

wklken commented 9 months ago

Description

the error.log

2023/12/08 04:03:02 [error] 92#92: *31499039 upstream prematurely closed connection while reading response header from upstream ...

the response body

<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>openresty</center>
<p><em>Powered by <a href="https://apisix.apache.org/">APISIX</a>.</em></p></body>
</html>
 while sending to client

I want to write a plugin to wrap the 502, and put the error message upstream prematurely closed connection while reading response header from upstream into the response body

is there any way to retrieve the error message of nginx from lua?

Environment

shreemaan-abhishek commented 9 months ago

looks like you will probably have to patch apisix... but let me find something.

wklken commented 9 months ago

looks like you will probably have to patch apisix... but let me find something.

thanks @shreemaan-abhishek

We are facing difficulties because the error.log format cannot be customized to include a request_id, and the response body lacks useful information. Consequently, we have to manually query the logs, matching the date and URI to correlate error.log with access.log, for the developers.

Vacant2333 commented 9 months ago

looks like you will probably have to patch apisix... but let me find something.

thanks @shreemaan-abhishek

We are facing difficulties because the error.log format cannot be customized to include a request_id, and the response body lacks useful information. Consequently, we have to manually query the logs, matching the date and URI to correlate error.log with access.log, for the developers.

seems like the logger plugin will help u, u can see the http logger or file logger(may better)

wklken commented 9 months ago

there are no apisix variables or nginx variables represent the error message for logger; and we can't add a customized field like request_id into the error log format(https://github.com/apache/apisix/issues/9498), so can't link the access log record with the error log record.

Vacant2333 commented 8 months ago

there are no apisix variables or nginx variables represent the error message for logger; and we can't add a customized field like request_id into the error log format(#9498), so can't link the access log record with the error log record.

ok i got it, looks like the plugin cant implement it for now, but i think its a good feat if we can get them from plugin