nic-6443 opened a new pull request, #13224:
URL: https://github.com/apache/apisix/pull/13224

   ## What
   
   Add `core.response.get_response_source(ctx)` API to distinguish where HTTP 
responses originate from:
   
   | Value | Meaning | Detection |
   |-------|---------|-----------|
   | `"apisix"` | APISIX Lua code generated the response | 
`core.response.exit()` sets `ctx._resp_source` |
   | `"nginx"` | NGINX proxy module generated the error | Proxied but 
`$upstream_header_time` last token is `"-"` |
   | `"upstream"` | Upstream service returned the response | Proxied and 
`$upstream_header_time` last token is numeric |
   
   ## Why
   
   Users need to differentiate 5XX error sources via OTel tracing and 
Prometheus metrics. Previously, gateway-generated errors (connection refused → 
502, timeout → 504) were indistinguishable from upstream-returned 5XX, and in 
OTel traces, gateway errors were completely invisible (`upstream_status` was 
nil).
   
   ## Changes
   
   - **`core/response.lua`**: `resp_exit()` marks `ctx._resp_source = "apisix"` 
for error codes; new `get_response_source()` API
   - **`init.lua`**: Sets `ctx._apisix_proxied = true` after `before_proxy` 
phase, before `proxy_pass`
   - **`opentelemetry.lua`**: Adds `apisix.response_source` span attribute; 
uses `ngx.status` for `http.status_code` (fixes nil for gateway errors)
   - **`prometheus/exporter.lua`**: Adds `response_source` label to 
`http_status` counter
   - **`zipkin.lua`**: Adds `apisix.response_source` span tag; uses `ngx.status`
   - **Tests**: Unit tests for `get_response_source()` covering all scenarios 
including multi-attempt retries
   
   ## Known Limitations
   
   - `bypass_nginx_upstream` path (e.g. ai-proxy): responses are labeled 
`"apisix"` since they don't go through NGINX proxy. Bypass plugins can 
explicitly set `ctx._resp_source = "upstream"` if needed.
   - Stream (L4) proxy: `$upstream_header_time` is HTTP-only; stream needs 
separate handling.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to