You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "cuongquochoang (via GitHub)" <gi...@apache.org> on 2026/09/15 04:39:46 UTC

[PR] feat(opentelemetry): add upstream client span [apisix]

cuongquochoang opened a new pull request, #13946:
URL: https://github.com/apache/apisix/pull/13946

   ### Description
   
   APISIX's OpenTelemetry plugin currently propagates the gateway SERVER span directly to the upstream. As a result, no CLIENT span represents the proxy hop and APM service maps cannot connect APISIX to upstream services.
   
   This change:
   
   - starts an `apisix.upstream` CLIENT span after the balancer selects the upstream;
   - propagates that CLIENT span context to the upstream request, including retries;
   - finishes the span with the final NGINX upstream response/connect timing;
   - records `server.address`, `server.port`, and `http.response.status_code`; and
   - marks upstream 5xx responses as errors.
   
   The integration test verifies the span hierarchy, kind, attributes, timing bounds, propagated parent span ID, and HTTP/2 request isolation.
   
   #### Which issue(s) this PR fixes:
   
   Fixes #13945
   
   ### Tests
   
   - `t/plugin/opentelemetry6.t` — 27 assertions passed
   - `t/plugin/opentelemetry.t` — 156 assertions passed
   - `luacheck -q apisix/plugins/opentelemetry.lua t/lib/test_otel.lua t/lib/server.lua`
   - `./utils/check-test-code-style.sh`
   - `git diff --check`
   
   ### Checklist
   
   - [x] I have explained the need for this PR and the problem it solves
   - [x] I have explained the changes or the new features added to this PR
   - [x] I have added tests corresponding to this change
   - [x] Documentation is not applicable because this changes emitted telemetry without changing configuration or public APIs
   - [x] I have verified that this change is backward compatible
   


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(opentelemetry): add upstream client span [apisix]

Posted by "cuongquochoang (via GitHub)" <gi...@apache.org>.
cuongquochoang commented on PR #13946:
URL: https://github.com/apache/apisix/pull/13946#issuecomment-5724975209

   @janiussyafiq Resolved the conflicts with #13940 by merging master. `ext-plugin-post-resp` now sets both the upstream timing vars from #13940 and the tracing flags from this PR. Could you approve the CI workflows? Thanks!


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(opentelemetry): add upstream client span [apisix]

Posted by "ruanweihong-aaa (via GitHub)" <gi...@apache.org>.
ruanweihong-aaa commented on PR #13946:
URL: https://github.com/apache/apisix/pull/13946#issuecomment-6359918168

   这里读取的是 NGINX 的上游耗时:
   ```lua
   local response_time = tonumber(get_upstream_token(ngx_var.upstream_response_time, idx))
   ```
   但 `ext-plugin-post-resp` 将耗时写在 `ctx.var.upstream_response_time` 中。
   
   我用真实 Go runner 测试:前置插件等待 200ms,上游耗时 400ms,CLIENT span 却记录了约 603ms,把前置等待也算进去了。能否兼顾 ext-plugin 的计时来源,并补一个回归测试?
   
   源码:[读取位置](https://github.com/apache/apisix/blob/75e4057eeec5a6c05f904cebdea125685e2ce4c8/apisix/plugins/opentelemetry.lua#L547-L549) · [ext-plugin 写入位置](https://github.com/apache/apisix/blob/75e4057eeec5a6c05f904cebdea125685e2ce4c8/apisix/plugins/ext-plugin-post-resp.lua#L172)


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(opentelemetry): add upstream client span [apisix]

Posted by "janiussyafiq (via GitHub)" <gi...@apache.org>.
janiussyafiq commented on PR #13946:
URL: https://github.com/apache/apisix/pull/13946#issuecomment-5724357423

   Please resolve merge conflicts, thanks


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(opentelemetry): add upstream client span [apisix]

Posted by "cuongquochoang (via GitHub)" <gi...@apache.org>.
cuongquochoang closed pull request #13946: feat(opentelemetry): add upstream client span
URL: https://github.com/apache/apisix/pull/13946


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(opentelemetry): add upstream client span [apisix]

Posted by "ruanweihong-aaa (via GitHub)" <gi...@apache.org>.
ruanweihong-aaa commented on PR #13946:
URL: https://github.com/apache/apisix/pull/13946#issuecomment-6359965526

   This reads the NGINX upstream timing:
   ```lua
   local response_time = tonumber(get_upstream_token(ngx_var.upstream_response_time, idx))
   ```
   But `ext-plugin-post-resp` records its timing in `ctx.var.upstream_response_time`.
   
   I tested this with the real Go runner: a 200ms delay in a preceding `before_proxy` plugin plus a 400ms upstream response produced a CLIENT span of about 603ms, so the pre-dispatch delay was included. Could we account for the ext-plugin timing source and add a regression test?
   
   Source: [timing read](https://github.com/apache/apisix/blob/75e4057eeec5a6c05f904cebdea125685e2ce4c8/apisix/plugins/opentelemetry.lua#L547-L549) · [ext-plugin timing write](https://github.com/apache/apisix/blob/75e4057eeec5a6c05f904cebdea125685e2ce4c8/apisix/plugins/ext-plugin-post-resp.lua#L172)


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org