wy471x opened a new pull request, #7705:
URL: https://github.com/apache/shenyu/pull/7705

   ### Summary
   
   A deployment can now decide how the gateway traces: which requests are 
sampled, what the spans carry as resource, where they are exported, and whether 
the gateway creates a span of its own. This is the fourth task of #7566.
   
   Make sure that:
   
   - [X] You have read the [contribution 
guidelines](https://shenyu.apache.org/community/contributor-guide).
   - [X] You submit test cases (unit or integration tests) that back your 
changes.
   - [X] Your local test passed `./mvnw clean install 
-Dmaven.javadoc.skip=true`.
         Run here for the touched modules and their dependencies: `mvn -pl 
shenyu-common,shenyu-plugin/shenyu-plugin-tracing,shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-tracing
 -am install` with checkstyle, RAT and tests enabled (BUILD SUCCESS). The full 
repository build was not run locally, CI covers it.
   
   ### Changes:
   
   1. `ShenyuConfig.TracingConfig` 
(`shenyu-common/.../config/ShenyuConfig.java:1999,2148`) — the tracing 
configuration gains the span creation switch, the sampler with its ratio, the 
resource attributes and a nested `OtlpConfig` with the endpoint, the timeout 
and the headers of the exporter. Every value keeps a working default, so an 
existing deployment only has to enable tracing.
   2. `TracingConstants` 
(`shenyu-plugin-tracing/.../TracingConstants.java:48,63`) — the names of the 
samplers, so that the configuration values and the code which reads them cannot 
drift apart.
   3. `TracingPlugin` (`.../TracingPlugin.java:91,126`) — a third constructor 
argument turns the span creation off. The plugin then only propagates the 
incoming context, which is how a deployment that already instruments the 
gateway, for example with a java agent, avoids tracing every request twice.
   4. `TracingPluginConfiguration.tracingTracerProvider` 
(`shenyu-spring-boot-starter-plugin-tracing/.../TracingPluginConfiguration.java:111`)
 — builds the provider from the resource and the configured sampler, attaches 
the batch processor only when an exporter exists, and logs the effective 
configuration once, without the credentials an endpoint may carry.
   5. `TracingPluginConfiguration.sampler` (`...:204,236`) — `parent_based` by 
default, so the decision of the client is respected, plus `always_on`, 
`always_off` and `ratio`. The ratio is clamped to the valid range, an unknown 
sampler and a ratio which is not a number are reported instead of changing the 
sampling silently.
   6. `TracingPluginConfiguration.createSpanExporter` (`...:269,305`) — exports 
over OTLP over http. The grpc transport is deliberately not bundled, because 
grpc netty is already on the classpath of the gateway through the grpc plugin. 
A base endpoint gets the traces path appended, so that a collector is not 
called at its root and the spans are not lost silently.
   7. `TracingPluginConfiguration.spanProcessor` (`...:254`) — the batch 
processor is created inside the same guard as the exporter: a failure is logged 
and the spans stay in the process, so neither the startup nor the forwarding of 
a request can be affected by the export path.
   8. `TracingExporterHolder` (new, `.../TracingExporterHolder.java:33`) — owns 
the exporter and closes it with the context. The batch processor does not close 
the exporter it writes to, while the OTLP exporter keeps a connection pool, so 
the exporter is a bean of its own which the context closes after it has closed 
the tracer provider.
   9. `TracingPluginConfiguration.redactedEndpoint` (`...:341`) — the endpoint 
is logged without its user information, its query and its fragment, and the 
failure of an exporter which cannot be created logs the type of the failure 
rather than its message, which may quote the endpoint.
   10. `shenyu-bootstrap/src/main/resources/application.yml` and 
`shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE` — the 
configuration block documents the defaults, and the artifacts the exporter adds 
to the distribution are registered in its LICENSE.
   
   ### Test Cases:
   
   - `TracingPluginConfigurationTest` (18 tests) — tracing disabled by default 
and by an explicit `false`; the beans when it is enabled; the service name and 
the resource attributes from the configuration; the tracing configuration bound 
from properties; the `always_off` and the `ratio` sampler, including a ratio of 
zero and of one; an exporter with an invalid endpoint which does not fail the 
startup; an unreachable exporter which neither breaks the span nor the request 
chain; the exporter owned by the context only when one is configured; a span 
exported to a collector stub, which also proves the traces path is appended to 
a base endpoint; the global OpenTelemetry not replaced; and the logged endpoint 
carrying none of its credentials.
   - `TracingPluginTest` (20 tests, 2 new) — the span creation disabled: no 
span is created while an incoming trace is still propagated, and a request 
without an incoming trace has nothing to propagate.
   - The existing suites of `shenyu-common` and the tracing plugin stay green.
   
   ### Verification
   
   - `mvn -pl 
shenyu-common,shenyu-plugin/shenyu-plugin-tracing,shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-tracing
 -am install` → BUILD SUCCESS, module tests: shenyu-common 511, tracing 66, 
tracing starter 18, no failures.
   - checkstyle 0 violations, and `apache-rat:check` Unapproved 0 for the 
touched modules including the distribution module.
   - `mvn -pl shenyu-bootstrap -am install -DskipTests` → BUILD SUCCESS, which 
checks that the plugin and the exporter integrate with the gateway build.
   
   ### Not covered by this change
   
   - The B3 propagator and a configurable set of propagators: the tracing 
plugin speaks W3C trace context today, and supporting B3 needs the extension 
propagators of OpenTelemetry and a wiring of both the inbound extraction and 
the outbound injection.
   - The OTLP over gRPC transport, which is deliberately not bundled.
   - The queue, delay and timeout knobs of the batch processor, which use the 
defaults of the OpenTelemetry SDK.
   - The documentation of the propagate only mode next to a java agent, and of 
the fact that a ratio which is lower than the default sampling needs an 
explicit `sampler: ratio` (#7617).
   
   Fixes #7612
   Part of #7566
   


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