Repository navigation
Conversation
The request to OPA only carried `Content-Type`, so when distributed tracing was enabled OPA could not continue the request trace and its spans started a separate trace. The incoming `traceparent` was only visible inside the JSON input body, which OPA does not use for tracing. Forward the current `traceparent` header on the OPA request. When the opentelemetry plugin is enabled it has already injected the APISIX span into that header, so OPA's spans become children of the APISIX span. Fixes apache#14051
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
opaplugin sends its decision request to OPA with only aContent-Typeheader. So with distributed tracing enabled, OPA never gets the W3C trace context, and its spans start a new trace instead of joining the APISIX request trace. The incomingtraceparentis visible to OPA only inside the JSON input (input.request.headers), which OPA does not use for tracing (see open-policy-agent/opa#6905).This PR forwards the request's current
traceparentheader on the call to OPA. When theopentelemetryplugin is enabled, its rewrite phase has already put the APISIX span into that header, so OPA's spans become children of the APISIX span. If the header is missing, nothing extra is sent.sequenceDiagram participant C as Client participant A as APISIX (opentelemetry + opa) participant O as OPA C->>A: GET /hello (traceparent: 00-T-client-01) Note over A: opentelemetry starts span S and<br/>injects traceparent 00-T-S-xx A->>O: POST /v1/data/<policy> (traceparent: 00-T-S-xx) Note over O: OPA span is a child of S in trace TI used a plain header rather than a schema option because OPA ignores
traceparentwhen its tracing is off, so forwarding it is harmless. I can put it behind an option (e.g.propagate_trace_context) if reviewers prefer.Which issue(s) this PR fixes:
Fixes #14051
Tests
New
t/plugin/opa4.truns a mock OPA endpoint in the test server that denies every request and echoes back thetraceparentit received:traceparentis forwarded to OPA.traceparentis sent when the request has none.opentelemetryenabled, OPA gets the same trace id but the APISIX span id, not the client's.Without the fix, TEST 2 and TEST 5 fail (OPA gets no header). With the fix, the file passes.
luacheckandlj-relengare clean onapisix/plugins/opa.lua.Checklist