bug: Some nginx vars related to upstream are missing when using ext-plugin-post-resp
- Dominant language
- Lua
- Stars
- 17.1k
- Forks
- 2.9k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 63
Description
### Current Behavior
When I'm using ext-plugin-post-resp and http-logger, some values are missing from the logs, specifically the ones related to upstream - upstream and upstream_latency (same as described in this issue - https://github.com/apache/apisix/issues/10369).
### Expected Behavior
I believe this isis happening because `upstream_response_time` and `upstream_addr` nginx vars are unavailable, so when log-util.lua is trying to inject them into logs, no value is present. I understand that when using ext-plugin-post-resp, the mechanics of calling upstream is different, but I still expect to have these values in the logs, no matter what route configuration I have.
For now, the only way for me to fix it, was to change _M.before_proxy method in ext-plugin-post-resp.lua and explicitly set these vars:
```
function _M.before_proxy(conf, ctx)
local start_time = ngx.now() -- EDIT: Start timer here
local http_obj = http.new()
local res, err = get_response(ctx, http_obj)
-- EDIT: Set upstream vars, right after get_response returns
ctx.var.upstream_response_time = math.floor((ngx.now() - start_time) * 1000 + 0.5) / 1000
ctx.var.upstream_addr = ctx.picked_server.host .. ":" .. ctx.picked_server.port
```
### Error Logs
_No response_
### Steps to Reproduce
1. Run APISIX
2. Create a route that would have two plugins - http-logger and ext-plugin-post-resp
3. Try to make call to upstream
4. Check the logs sent by http-logger and see that upstream and upstream_latency are missing
### Environment
- APISIX version (run `apisix version`): 3.13.0
- Operating system (run `uname -a`): Darwin 25.2.0
- OpenResty / Nginx version (run `openresty -V` or `nginx -V`):
- etcd version, if relevant (run `curl http://127.0.0.1:9090/v1/server_info`): 9.7.3
- APISIX Dashboard version, if relevant: 0.8.2
- Plugin runner version, for issues related to plugin runners: ext-java-plugin-runner 0.6.0
- LuaRocks version, for installation issues (run `luarocks --version`):
Contributor guide
Research direction
Start by reading ext-plugin-post-resp.lua, especially _M.before_proxy, and then follow how log-util.lua supplies upstream fields to http-logger. Reproduce the route with both ext-plugin-post-resp and http-logger, then verify that the logs contain upstream and upstream_latency values for the upstream request.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, nginx
- Domain
- api, backend, observability
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100