Aias00 opened a new issue, #7566:
URL: https://github.com/apache/shenyu/issues/7566

   ### Feature Request
   
   Add vendor-neutral end-to-end distributed tracing that connects an inbound 
client request, its execution through the ShenYu gateway, and the outbound call 
to the upstream service.
   
   This is an implementation follow-up to the distributed-tracing discussion in 
#6349.
   
   ### Is your feature request related to a problem? Please describe
   
   ShenYu currently provides request logging and Prometheus metrics, but the 
main repository does not create a gateway request span or propagate a trace 
context to upstream services.
   
   The logging implementation only reads an externally supplied trace ID from 
the `shenyu-agent-trace-id` exchange attribute. Core DEBUG messages use 
`ServerWebExchange.getLogPrefix()`, which is a WebFlux log prefix rather than a 
distributed trace ID. As a result, operators cannot reliably follow one request 
across:
   
   ```text
   client -> ShenYu gateway -> upstream service
   ```
   
   They also cannot correlate the gateway access log, gateway errors, and 
upstream spans without a custom agent or plugin.
   
   Relevant code:
   
   - The access log reads an externally populated trace ID: 
https://github.com/apache/shenyu/blob/2dff2730ff399635b2bc657e21a903f391fb9df8/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/body/LoggingServerHttpResponse.java#L233-L241
   - The exchange attribute contract is `shenyu-agent-trace-id`: 
https://github.com/apache/shenyu/blob/2dff2730ff399635b2bc657e21a903f391fb9df8/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/constant/GenericLoggingConstant.java#L35-L38
   - The gateway/plugin timing logs use the WebFlux log prefix: 
https://github.com/apache/shenyu/blob/2dff2730ff399635b2bc657e21a903f391fb9df8/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/ShenyuPlugin.java#L149-L153
   
   ### Describe the solution you'd like
   
   Introduce a tracing plugin and Spring Boot starter based on the 
OpenTelemetry API, while keeping the tracing backend vendor-neutral.
   
   #### Inbound request
   
   - Extract W3C Trace Context (`traceparent`/`tracestate`) and baggage from 
incoming requests.
   - Optionally support B3 propagation for compatibility.
   - Create a new trace when the client does not send a valid context.
   - Create a ShenYu server span and preserve its context across Reactor 
asynchronous boundaries.
   - Start the span before observable gateway processing and finish it when the 
reactive request completes, fails, or is cancelled.
   
   #### Gateway span data
   
   - Record normalized route/plugin information, RPC type, selector/rule 
identifiers where appropriate, HTTP method/status, upstream target, and ShenYu 
error outcome.
   - Record exceptions and set the span status consistently.
   - Avoid high-cardinality attributes such as unnormalized raw paths and 
sensitive request data by default.
   - Expose the active trace ID through the existing `shenyu-agent-trace-id` 
exchange attribute so current logging plugins can correlate access logs without 
duplicating tracing logic.
   
   #### Outbound propagation
   
   - Inject the active context into requests sent from ShenYu to upstream 
services.
   - Cover the HTTP proxy path first and define an extension point for Spring 
Cloud, gRPC, Dubbo, and other protocol plugins.
   - Preserve an incoming client trace and parent relationship instead of 
starting an unrelated upstream trace.
   
   #### Configuration and export
   
   - Provide configuration for enablement, service name/resource attributes, 
sampling, propagators, and OTLP export.
   - Keep tracing disabled by default unless the community decides otherwise.
   - Allow deployments that already use a Java agent to avoid duplicate 
instrumentation and duplicate spans.
   
   ### Acceptance Criteria
   
   - [ ] A request carrying a valid `traceparent` produces a gateway span in 
the same trace.
   - [ ] A request without tracing headers starts a new trace.
   - [ ] The upstream service receives an injected context whose parent 
relationship includes the gateway span.
   - [ ] The gateway span closes correctly on success, HTTP error, thrown 
exception, timeout, and cancellation.
   - [ ] Trace context survives Reactor thread switches and asynchronous plugin 
execution.
   - [ ] ShenYu access logs contain the same trace ID through 
`shenyu-agent-trace-id`.
   - [ ] Invalid incoming tracing headers are handled safely.
   - [ ] Sampling and exporter failures do not break request forwarding.
   - [ ] Integration tests verify `test client -> ShenYu -> mock upstream` 
trace continuity and parent-child relationships.
   - [ ] Documentation includes configuration, supported propagators/protocols, 
backend examples, and performance considerations.
   
   ### Describe alternatives you've considered
   
   Relying only on a general-purpose Java agent can provide partial HTTP 
instrumentation, but it does not define ShenYu-specific span attributes, plugin 
lifecycle behavior, access-log correlation, or propagation adapters for all 
supported proxy protocols. The proposed plugin should also coexist cleanly with 
agent-based instrumentation.
   
   ### Additional context
   
   - Related discussion: #6349
   - The former ShenYu agent was removed in #3085, which explicitly encouraged 
tracing implementations based on plugins.
   - Historical agent tracing work: #2699
   - Current version inspected: `2.7.2-SNAPSHOT`, commit 
`2dff2730ff399635b2bc657e21a903f391fb9df8`.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to