Skip to content

bug: Some nginx vars related to upstream are missing when using ext-plugin-post-resp #13016

@MariaLapovska

Description

@MariaLapovska

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 - #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):

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions