Gate W3C trace support to request phases with ngx.var access#345
Gate W3C trace support to request phases with ngx.var access#345mtrop-godaddy wants to merge 4 commits into
Conversation
The http library reads ngx.var.http_traceparent in send_request to propagate W3C trace context. ngx.var is only readable in request-bearing phases, so this crashes code running in init/init_worker. Gate the read on ngx.get_phase() being in a request-bearing phase via a whitelist, so request-less phases (init, init_worker, timer, etc.) are excluded by default. Behavior is unchanged for real requests.
5217ac3 to
9eff4ce
Compare
| header_filter = true, | ||
| body_filter = true, | ||
| log = true, | ||
| balancer = true, |
There was a problem hiding this comment.
Phases reviewed. Those look mostly good. Thanks.
But what about adding "precontent" as seen in t/089-phase.t#L227?
I'd like to drop balancer and preread, because balancer has no full API support and preread is unlikely to be triggered.
|
Reviewed documentation and code:
|
|
Phases not listed as supported in https://openresty-reference.readthedocs.io/en/latest/Lua_Nginx_API/#ngxvarvariable:
Accessible via |
|
|
|
Thanks for taking a look. That works for me - I updated the allow list. I also had to make some changes to the test workflow because of the Node.js 20 deprecation and an ancient OpenResty image (or more accurately it's Alpine base) which doesn't support Node.js 24. |
The http library reads ngx.var.http_traceparent in send_request to propagate W3C trace context. ngx.var is only readable in request-bearing phases, so this crashes code running in init/init_worker.
Gate the read on ngx.get_phase() being in a request-bearing phase via a whitelist, so request-less phases (init, init_worker, timer, etc.) are excluded by default. Behavior is unchanged for real requests.