Updates to latest Sampling infrastructure (2.1.x) (#1461)

* Updates to latest Sampling infrastructure (2.1.x)

This adapts #1456 for the 2.1.x branch
This commit is contained in:
Adrian Cole
2019-10-08 16:47:25 -07:00
committed by Marcin Grzejszczak
parent ac7dd52544
commit aa533bc4cb
26 changed files with 815 additions and 103 deletions

View File

@@ -845,21 +845,23 @@ Sleuth will search for beans of those types and automatically apply customizatio
=== HTTP
If a customization of client / server parsing of the HTTP related spans is required,
just register a bean of type `brave.http.HttpClientParser` or
If a customization of client / server parsing of the HTTP related spans is
required, just register a bean of type `brave.http.HttpClientParser` or
`brave.http.HttpServerParser`. If client /server sampling is required, just
register a bean of type `brave.http.HttpSampler` and name the bean
`sleuthClientSampler` for client sampler and `sleuthServerSampler` for server sampler.
For your convenience the `@ClientSampler` and `@ServerSampler`
annotations can be used to inject the proper beans or to
reference the bean names via their static String `NAME` fields.
register a bean of type `brave.sampler.SamplerFunction<HttpRequest>` and name
the bean `sleuthHttpClientSampler` for client sampler and
`sleuthHttpServerSampler` for server sampler.
For your convenience the `@HttpClientSampler` and `@HttpServerSampler`
annotations can be used to inject the proper beans or to reference the bean
names via their static String `NAME` fields.
Check out Brave's code to see an example of how to make a path-based sampler
https://github.com/openzipkin/brave/tree/master/instrumentation/http#sampling-policy
If you want to completely rewrite the `HttpTracing` bean you can use the `SkipPatternProvider`
interface to retrieve the URL `Pattern` for spans that should be not sampled. Below you can see
an example of usage of `SkipPatternProvider` inside a server side, `HttpSampler`.
an example of usage of `SkipPatternProvider` inside a server side, `Sampler<HttpRequest>`.
[source,java]
----
@@ -881,6 +883,34 @@ In the following example, we register the `TracingFilter` bean, add the `ZIPKIN-
include::../../../..//spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceFilterIntegrationTests.java[tags=response_headers,indent=0]
----
=== RPC
Sleuth automatically configures the `RpcTracing` bean which serves as a
foundation for RPC instrumentation such as gRPC or Dubbo.
If a customization of client / server sampling of the RPC traces is required,
just register a bean of type `brave.sampler.SamplerFunction<RpcRequest>` and
name the bean `sleuthRpcClientSampler` for client sampler and
`sleuthRpcServerSampler` for server sampler.
For your convenience the `@RpcClientSampler` and `@RpcServerSampler`
annotations can be used to inject the proper beans or to reference the bean
names via their static String `NAME` fields.
Ex. Here's a sampler that traces 100 "GetUserToken" server requests per second.
This doesn't start new traces for requests to the health check service. Other
requests will use the global sampling configuration.
[source,java]
----
@Configuration
class Config {
include::../../../../spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/rpc/TraceRpcAutoConfigurationIntegrationTests.java[tags=custom_rpc_server_sampler,indent=2]
}
----
For more, see https://github.com/openzipkin/brave/tree/master/instrumentation/rpc#sampling-policy
=== Custom service name
By default, Sleuth assumes that, when you send a span to Zipkin, you want the span's service name to be equal to the value of the `spring.application.name` property.
@@ -1119,13 +1149,13 @@ To change the order of tracing filter registration, please set the
==== Dubbo RPC support
Via the integration with Brave, Spring Cloud Sleuth supports https://dubbo.apache.org/[Dubbo].
It's enough to add the `brave-instrumentation-dubbo-rpc` dependency:
It's enough to add the `brave-instrumentation-dubbo` dependency:
[source,xml,indent=0]
----
<dependency>
<groupId>io.zipkin.brave</groupId>
<artifactId>brave-instrumentation-dubbo-rpc</artifactId>
<artifactId>brave-instrumentation-dubbo</artifactId>
</dependency>
----