Hadi,
You can use "Server" header.
And if you allow to pass "Server" header from upstream(s) to the client, you should be able to distinguish between 5XX coming from upstream vs. openresty ones:
proxy_pass_header "Server";
It’ll work if you have multiple proxies staked also.
Just have them set with different "Server" header.
Naturally, any “must be in response” header should do, providing you distinguish them.
"Server" is most convenient one, IMO.
There should be more ways to do it.
Regards,
ecc256