feat(opentelemetry): emit a CLIENT span for the upstream call - #13954
Open
janiussyafiq wants to merge 1 commit into
Open
janiussyafiq wants to merge 1 commit into
janiussyafiq wants to merge 1 commit into
Conversation
The plugin only emitted a SERVER span and propagated its id to the upstream, so the upstream's SERVER span was parented to a SERVER span and APM service maps could not draw the gateway -> upstream edge. Start a child CLIENT span `apisix.upstream` in the rewrite phase and propagate its context instead. Stamp its start in before_proxy and finish it in the log phase with server.address, server.port and http.response.status_code, using $upstream_response_time for the end time. Requests answered before proxying do not export the span. Fixes apache#13945
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
opentelemetryplugin only emits aSERVERspan and propagates that span's id to the upstream. The upstream'sSERVERspan is therefore parented to aSERVERspan, and APM service maps (Tempo, HyperDX, Datadog, the collectorservicegraphconnector) never draw the gateway -> upstream edge, so APISIX shows up as a disconnected node.This PR adds a child
CLIENTspan namedapisix.upstreamfor the call to the upstream:rewrite: start theCLIENTspan under theSERVERspan and propagate its context intraceparent, so the upstream's span becomes its child.before_proxy: record the start time (runs per try).log: setserver.address,server.portandhttp.response.status_code, mark 5xx or unreachable upstream as error, end the span using$upstream_response_timeand finish it before theSERVERspan.A request answered before being proxied never finishes the span, so nothing is exported for it.
$opentelemetry_span_idand related variables keep referring to theSERVERspan.Verified with an OTel-instrumented upstream behind APISIX: Tempo's service graph gains the
apisix-gw -> upstreamedge, and Jaeger shows the upstream span underapisix.upstream.Which issue(s) this PR fixes:
Fixes #13945
Checklist