Skip to content

feat(opentelemetry): add upstream client span - #13946

Open
cuongquochoang wants to merge 4 commits into
apache:masterfrom
cuongquochoang:fix/opentelemetry-upstream-client-span
Open

cuongquochoang wants to merge 4 commits into
apache:masterfrom
cuongquochoang:fix/opentelemetry-upstream-client-span

Conversation

@cuongquochoang

@cuongquochoang cuongquochoang commented Sep 15, 2026

Copy link
Copy Markdown

Description

APISIX currently propagates the gateway SERVER span directly to an upstream service. Without a CLIENT span for the proxy hop, APM service maps cannot represent the APISIX-to-upstream relationship correctly.

This change:

  • creates an apisix.upstream CLIENT span for every upstream attempt;
  • propagates the CLIENT span context, including across retries;
  • records upstream address, port, HTTP status, and accurate attempt timing;
  • marks failed attempts and upstream 4xx/5xx responses as errors;
  • keeps the CLIENT span when ext-plugin-post-resp performs the outbound request and then exits early;
  • avoids exporting a synthetic CLIENT span when a later plugin exits without contacting upstream; and
  • documents the new OpenTelemetry variables in English and Chinese.

The tests cover span hierarchy and propagation, HTTP/2 request isolation, retry attempts, connection failures, early exits with and without a custom upstream dispatch, timing bounds, and error status handling.

Which issue(s) this PR fixes:

Fixes #13945

Tests

  • t/plugin/opentelemetry6.t — 75 assertions passed
  • OpenTelemetry plugin test suite (opentelemetry.t through opentelemetry6.t) — 226 assertions passed
  • targeted Lua syntax, lj-releng, test-code-style, Markdown lint, and git diff --check checks passed
  • full make lint: LuaCheck passed; lj-releng still reports pre-existing Unicode separator comments in unrelated service-discovery files

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the English and Chinese documentation
  • I have verified that this change is backward compatible

@janiussyafiq

Copy link
Copy Markdown
Contributor

Please resolve merge conflicts, thanks

…-upstream-client-span

# Conflicts:
#	apisix/plugins/ext-plugin-post-resp.lua
@cuongquochoang

Copy link
Copy Markdown
Author

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: opentelemetry plugin emits no CLIENT span for the upstream call, breaking APM service maps

2 participants