Skip to content

feat(opentelemetry): emit a CLIENT span for the upstream call - #13954

Open
janiussyafiq wants to merge 1 commit into
apache:masterfrom
janiussyafiq:feat/otel-upstream-client-span
Open

janiussyafiq wants to merge 1 commit into
apache:masterfrom
janiussyafiq:feat/otel-upstream-client-span

Conversation

@janiussyafiq

Copy link
Copy Markdown
Contributor

Description

The opentelemetry plugin only emits a SERVER span and propagates that span's id to the upstream. The upstream's SERVER span is therefore parented to a SERVER span, and APM service maps (Tempo, HyperDX, Datadog, the collector servicegraph connector) never draw the gateway -> upstream edge, so APISIX shows up as a disconnected node.

This PR adds a child CLIENT span named apisix.upstream for the call to the upstream:

  • rewrite: start the CLIENT span under the SERVER span and propagate its context in traceparent, so the upstream's span becomes its child.
  • before_proxy: record the start time (runs per try).
  • log: set server.address, server.port and http.response.status_code, mark 5xx or unreachable upstream as error, end the span using $upstream_response_time and finish it before the SERVER span.

A request answered before being proxied never finishes the span, so nothing is exported for it. $opentelemetry_span_id and related variables keep referring to the SERVER span.

Verified with an OTel-instrumented upstream behind APISIX: Tempo's service graph gains the apisix-gw -> upstream edge, and Jaeger shows the upstream span under apisix.upstream.

Which issue(s) this PR fixes:

Fixes #13945

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 documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

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

1 participant