Sync docs from 2.1.x to gh-pages

This commit is contained in:
buildmaster
2019-10-08 23:48:39 +00:00
parent c4106adac4
commit 14b82d21e9
5 changed files with 126 additions and 74 deletions

View File

@@ -1,31 +1,27 @@
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>12.&nbsp;Customizations</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><link rel="home" href="multi_spring-cloud-sleuth.html" title="Spring Cloud Sleuth"><link rel="up" href="multi_spring-cloud-sleuth.html" title="Spring Cloud Sleuth"><link rel="prev" href="multi__managing_spans_with_annotations.html" title="11.&nbsp;Managing Spans with Annotations"><link rel="next" href="multi__sending_spans_to_zipkin.html" title="13.&nbsp;Sending Spans to Zipkin"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">12.&nbsp;Customizations</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__managing_spans_with_annotations.html">Prev</a>&nbsp;</td><th width="60%" align="center">&nbsp;</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="multi__sending_spans_to_zipkin.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_customizations" href="#_customizations"></a>12.&nbsp;Customizations</h1></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_customizers" href="#_customizers"></a>12.1&nbsp;Customizers</h2></div></div></div><p>With Brave 5.7 you have various options of providing customizers for your project. Brave ships with</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><code class="literal">TracingCustomizer</code> - allows configuration plugins to collaborate on building an instance of <code class="literal">Tracing</code>.</li><li class="listitem"><code class="literal">CurrentTraceContextCustomizer</code> - allows configuration plugins to collaborate on building an instance of <code class="literal">CurrentTraceContext</code>.</li><li class="listitem"><code class="literal">ExtraFieldCustomizer</code> - allows configuration plugins to collaborate on building an instance of <code class="literal">ExtraFieldPropagation.Factory</code>.</li></ul></div><p>Sleuth will search for beans of those types and automatically apply customizations.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_http" href="#_http"></a>12.2&nbsp;HTTP</h2></div></div></div><p>If a customization of client / server parsing of the HTTP related spans is required,
just register a bean of type <code class="literal">brave.http.HttpClientParser</code> or
<title>12.&nbsp;Customizations</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><link rel="home" href="multi_spring-cloud-sleuth.html" title="Spring Cloud Sleuth"><link rel="up" href="multi_spring-cloud-sleuth.html" title="Spring Cloud Sleuth"><link rel="prev" href="multi__managing_spans_with_annotations.html" title="11.&nbsp;Managing Spans with Annotations"><link rel="next" href="multi__sending_spans_to_zipkin.html" title="13.&nbsp;Sending Spans to Zipkin"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">12.&nbsp;Customizations</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__managing_spans_with_annotations.html">Prev</a>&nbsp;</td><th width="60%" align="center">&nbsp;</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="multi__sending_spans_to_zipkin.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_customizations" href="#_customizations"></a>12.&nbsp;Customizations</h1></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_customizers" href="#_customizers"></a>12.1&nbsp;Customizers</h2></div></div></div><p>With Brave 5.7 you have various options of providing customizers for your project. Brave ships with</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><code class="literal">TracingCustomizer</code> - allows configuration plugins to collaborate on building an instance of <code class="literal">Tracing</code>.</li><li class="listitem"><code class="literal">CurrentTraceContextCustomizer</code> - allows configuration plugins to collaborate on building an instance of <code class="literal">CurrentTraceContext</code>.</li><li class="listitem"><code class="literal">ExtraFieldCustomizer</code> - allows configuration plugins to collaborate on building an instance of <code class="literal">ExtraFieldPropagation.Factory</code>.</li></ul></div><p>Sleuth will search for beans of those types and automatically apply customizations.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_http" href="#_http"></a>12.2&nbsp;HTTP</h2></div></div></div><p>If a customization of client / server parsing of the HTTP related spans is
required, just register a bean of type <code class="literal">brave.http.HttpClientParser</code> or
<code class="literal">brave.http.HttpServerParser</code>. If client /server sampling is required, just
register a bean of type <code class="literal">brave.http.HttpSampler</code> and name the bean
<code class="literal">sleuthClientSampler</code> for client sampler and <code class="literal">sleuthServerSampler</code> for server sampler.
For your convenience the <code class="literal">@ClientSampler</code> and <code class="literal">@ServerSampler</code>
annotations can be used to inject the proper beans or to
reference the bean names via their static String <code class="literal">NAME</code> fields.</p><p>Check out Brave&#8217;s code to see an example of how to make a path-based sampler
register a bean of type <code class="literal">brave.sampler.SamplerFunction&lt;HttpRequest&gt;</code> and name
the bean <code class="literal">sleuthHttpClientSampler</code> for client sampler and
<code class="literal">sleuthHttpServerSampler</code> for server sampler.</p><p>For your convenience the <code class="literal">@HttpClientSampler</code> and <code class="literal">@HttpServerSampler</code>
annotations can be used to inject the proper beans or to reference the bean
names via their static String <code class="literal">NAME</code> fields.</p><p>Check out Brave&#8217;s code to see an example of how to make a path-based sampler
<a class="link" href="https://github.com/openzipkin/brave/tree/master/instrumentation/http#sampling-policy" target="_top">https://github.com/openzipkin/brave/tree/master/instrumentation/http#sampling-policy</a></p><p>If you want to completely rewrite the <code class="literal">HttpTracing</code> bean you can use the <code class="literal">SkipPatternProvider</code>
interface to retrieve the URL <code class="literal">Pattern</code> for spans that should be not sampled. Below you can see
an example of usage of <code class="literal">SkipPatternProvider</code> inside a server side, <code class="literal">HttpSampler</code>.</p><pre class="programlisting"><xslthl:annotation xmlns:xslthl="http://xslthl.sourceforge.net/">@Configuration</xslthl:annotation>
an example of usage of <code class="literal">SkipPatternProvider</code> inside a server side, <code class="literal">Sampler&lt;HttpRequest&gt;</code>.</p><pre class="programlisting"><xslthl:annotation xmlns:xslthl="http://xslthl.sourceforge.net/">@Configuration</xslthl:annotation>
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span> Config {
<xslthl:annotation xmlns:xslthl="http://xslthl.sourceforge.net/">@Bean(name = ServerSampler.NAME)</xslthl:annotation>
HttpSampler myHttpSampler(SkipPatternProvider provider) {
<xslthl:annotation xmlns:xslthl="http://xslthl.sourceforge.net/">@Bean(name = HttpServerSampler.NAME)</xslthl:annotation>
SamplerFunction&lt;HttpRequest&gt; myHttpSampler(SkipPatternProvider provider) {
Pattern pattern = provider.skipPattern();
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> HttpSampler() {
<xslthl:annotation xmlns:xslthl="http://xslthl.sourceforge.net/">@Override</xslthl:annotation>
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> &lt;Req&gt; Boolean trySample(HttpAdapter&lt;Req, ?&gt; adapter, Req request) {
String url = adapter.path(request);
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">boolean</span> shouldSkip = pattern.matcher(url).matches();
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">if</span> (shouldSkip) {
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> false;
}
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> null;
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> request -&gt; {
String url = request.path();
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">boolean</span> shouldSkip = pattern.matcher(url).matches();
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">if</span> (shouldSkip) {
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> false;
}
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> null;
};
}
}</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_tracingfilter" href="#_tracingfilter"></a>12.3&nbsp;<code class="literal">TracingFilter</code></h2></div></div></div><p>You can also modify the behavior of the <code class="literal">TracingFilter</code>, which is the component that is responsible for processing the input HTTP request and adding tags basing on the HTTP response.
@@ -55,10 +51,28 @@ You can customize the tags or modify the response headers by registering your ow
chain.doFilter(request, response);
}
}</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_custom_service_name" href="#_custom_service_name"></a>12.4&nbsp;Custom service name</h2></div></div></div><p>By default, Sleuth assumes that, when you send a span to Zipkin, you want the span&#8217;s service name to be equal to the value of the <code class="literal">spring.application.name</code> property.
}</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_rpc" href="#_rpc"></a>12.4&nbsp;RPC</h2></div></div></div><p>Sleuth automatically configures the <code class="literal">RpcTracing</code> bean which serves as a
foundation for RPC instrumentation such as gRPC or Dubbo.</p><p>If a customization of client / server sampling of the RPC traces is required,
just register a bean of type <code class="literal">brave.sampler.SamplerFunction&lt;RpcRequest&gt;</code> and
name the bean <code class="literal">sleuthRpcClientSampler</code> for client sampler and
<code class="literal">sleuthRpcServerSampler</code> for server sampler.</p><p>For your convenience the <code class="literal">@RpcClientSampler</code> and <code class="literal">@RpcServerSampler</code>
annotations can be used to inject the proper beans or to reference the bean
names via their static String <code class="literal">NAME</code> fields.</p><p>Ex. Here&#8217;s a sampler that traces 100 "GetUserToken" server requests per second.
This doesn&#8217;t start new traces for requests to the health check service. Other
requests will use the global sampling configuration.</p><pre class="programlisting"><xslthl:annotation xmlns:xslthl="http://xslthl.sourceforge.net/">@Configuration</xslthl:annotation>
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span> Config {
<xslthl:annotation xmlns:xslthl="http://xslthl.sourceforge.net/">@Bean(name = RpcServerSampler.NAME)</xslthl:annotation>
SamplerFunction&lt;RpcRequest&gt; myRpcSampler() {
Matcher&lt;RpcRequest&gt; userAuth = and(serviceEquals(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"users.UserService"</span>),
methodEquals(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"GetUserToken"</span>));
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> RpcRuleSampler.newBuilder()
.putRule(serviceEquals(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"grpc.health.v1.Health"</span>), Sampler.NEVER_SAMPLE)
.putRule(userAuth, RateLimitingSampler.create(<xslthl:number xmlns:xslthl="http://xslthl.sourceforge.net/">100</xslthl:number>)).build();
}
}</pre><p>For more, see <a class="link" href="https://github.com/openzipkin/brave/tree/master/instrumentation/rpc#sampling-policy" target="_top">https://github.com/openzipkin/brave/tree/master/instrumentation/rpc#sampling-policy</a></p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_custom_service_name" href="#_custom_service_name"></a>12.5&nbsp;Custom service name</h2></div></div></div><p>By default, Sleuth assumes that, when you send a span to Zipkin, you want the span&#8217;s service name to be equal to the value of the <code class="literal">spring.application.name</code> property.
That is not always the case, though.
There are situations in which you want to explicitly provide a different service name for all spans coming from your application.
To achieve that, you can pass the following property to your application to override that value (the example is for a service named <code class="literal">myService</code>):</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">spring.zipkin.service.name</span>: myService</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_customization_of_reported_spans" href="#_customization_of_reported_spans"></a>12.5&nbsp;Customization of Reported Spans</h2></div></div></div><p>Before reporting spans (for example, to Zipkin) you may want to modify that span in some way.
To achieve that, you can pass the following property to your application to override that value (the example is for a service named <code class="literal">myService</code>):</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">spring.zipkin.service.name</span>: myService</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_customization_of_reported_spans" href="#_customization_of_reported_spans"></a>12.6&nbsp;Customization of Reported Spans</h2></div></div></div><p>Before reporting spans (for example, to Zipkin) you may want to modify that span in some way.
You can do so by using the <code class="literal">FinishedSpanHandler</code> interface.</p><p>In Sleuth, we generate spans with a fixed name.
Some users want to modify the name depending on values of tags.
You can implement the <code class="literal">FinishedSpanHandler</code> interface to alter that name.</p><p>The following example shows how to register two beans that implement <code class="literal">FinishedSpanHandler</code>:</p><pre class="programlisting"><xslthl:annotation xmlns:xslthl="http://xslthl.sourceforge.net/">@Bean</xslthl:annotation>
@@ -81,7 +95,7 @@ FinishedSpanHandler handlerTwo() {
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> true; <span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">// keep this span</span>
}
};
}</pre><p>The preceding example results in changing the name of the reported span to <code class="literal">foo bar</code>, just before it gets reported (for example, to Zipkin).</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_host_locator" href="#_host_locator"></a>12.6&nbsp;Host Locator</h2></div></div></div><div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Important"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="images/important.png"></td><th align="left">Important</th></tr><tr><td align="left" valign="top"><p>This section is about defining <span class="strong"><strong>host</strong></span> from service discovery.
}</pre><p>The preceding example results in changing the name of the reported span to <code class="literal">foo bar</code>, just before it gets reported (for example, to Zipkin).</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_host_locator" href="#_host_locator"></a>12.7&nbsp;Host Locator</h2></div></div></div><div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Important"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="images/important.png"></td><th align="left">Important</th></tr><tr><td align="left" valign="top"><p>This section is about defining <span class="strong"><strong>host</strong></span> from service discovery.
It is <span class="strong"><strong>NOT</strong></span> about finding Zipkin through service discovery.</p></td></tr></table></div><p>To define the host that corresponds to a particular span, we need to resolve the host name and port.
The default approach is to take these values from server properties.
If those are not set, we try to retrieve the host name from the network interfaces.</p><p>If you have the discovery client enabled and prefer to retrieve the host address from the registered instance in a service registry, you have to set the <code class="literal">spring.zipkin.locator.discovery.enabled</code> property (it is applicable for both HTTP-based and Stream-based span reporting), as follows:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">spring.zipkin.locator.discovery.enabled</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">true</span></pre></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__managing_spans_with_annotations.html">Prev</a>&nbsp;</td><td width="20%" align="center">&nbsp;</td><td width="40%" align="right">&nbsp;<a accesskey="n" href="multi__sending_spans_to_zipkin.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">11.&nbsp;Managing Spans with Annotations&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-sleuth.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;13.&nbsp;Sending Spans to Zipkin</td></tr></table></div></body></html>

View File

@@ -73,9 +73,9 @@ You can configure which URIs you would like to skip by using the <code class="li
If you have <code class="literal">ManagementServerProperties</code> on the classpath, its value of <code class="literal">contextPath</code> gets appended to the provided skip pattern.
If you want to reuse Sleuth&#8217;s default skip patterns and append your own, pass those patterns by using the <code class="literal">spring.sleuth.web.additionalSkipPattern</code>.</p><p>To change the order of tracing filter registration, please set the
<code class="literal">spring.sleuth.web.filter-order</code> property.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_dubbo_rpc_support" href="#_dubbo_rpc_support"></a>15.5.5&nbsp;Dubbo RPC support</h3></div></div></div><p>Via the integration with Brave, Spring Cloud Sleuth supports <a class="link" href="https://dubbo.apache.org/" target="_top">Dubbo</a>.
It&#8217;s enough to add the <code class="literal">brave-instrumentation-dubbo-rpc</code> dependency:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">&lt;dependency&gt;</span>
It&#8217;s enough to add the <code class="literal">brave-instrumentation-dubbo</code> dependency:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">&lt;dependency&gt;</span>
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">&lt;groupId&gt;</span>io.zipkin.brave<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">&lt;/groupId&gt;</span>
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">&lt;artifactId&gt;</span>brave-instrumentation-dubbo-rpc<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">&lt;/artifactId&gt;</span>
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">&lt;artifactId&gt;</span>brave-instrumentation-dubbo<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">&lt;/artifactId&gt;</span>
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">&lt;/dependency&gt;</span></pre><p>You need to also set a <code class="literal">dubbo.properties</code> file with the following contents:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">dubbo.provider.filter</span>=tracing
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">dubbo.consumer.filter</span>=tracing</pre><p>You can read more about Brave - Dubbo integration <a class="link" href="https://github.com/openzipkin/brave/tree/master/instrumentation/dubbo-rpc" target="_top">here</a>.
An example of Spring Cloud Sleuth and Dubbo can be found <a class="link" href="https://github.com/openzipkin/sleuth-webmvc-example/compare/add-dubbo-tracing" target="_top">here</a>.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_http_client_integration" href="#_http_client_integration"></a>15.6&nbsp;HTTP Client Integration</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_synchronous_rest_template" href="#_synchronous_rest_template"></a>15.6.1&nbsp;Synchronous Rest Template</h3></div></div></div><p>We inject a <code class="literal">RestTemplate</code> interceptor to ensure that all the tracing information is passed to the requests.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1555,35 +1555,32 @@ public void getAnnotationForArgumentToString(@SpanTag("test") Long param) {
</section>
<section xml:id="_http">
<title>HTTP</title>
<simpara>If a customization of client / server parsing of the HTTP related spans is required,
just register a bean of type <literal>brave.http.HttpClientParser</literal> or
<simpara>If a customization of client / server parsing of the HTTP related spans is
required, just register a bean of type <literal>brave.http.HttpClientParser</literal> or
<literal>brave.http.HttpServerParser</literal>. If client /server sampling is required, just
register a bean of type <literal>brave.http.HttpSampler</literal> and name the bean
<literal>sleuthClientSampler</literal> for client sampler and <literal>sleuthServerSampler</literal> for server sampler.
For your convenience the <literal>@ClientSampler</literal> and <literal>@ServerSampler</literal>
annotations can be used to inject the proper beans or to
reference the bean names via their static String <literal>NAME</literal> fields.</simpara>
register a bean of type <literal>brave.sampler.SamplerFunction&lt;HttpRequest&gt;</literal> and name
the bean <literal>sleuthHttpClientSampler</literal> for client sampler and
<literal>sleuthHttpServerSampler</literal> for server sampler.</simpara>
<simpara>For your convenience the <literal>@HttpClientSampler</literal> and <literal>@HttpServerSampler</literal>
annotations can be used to inject the proper beans or to reference the bean
names via their static String <literal>NAME</literal> fields.</simpara>
<simpara>Check out Brave&#8217;s code to see an example of how to make a path-based sampler
<link xl:href="https://github.com/openzipkin/brave/tree/master/instrumentation/http#sampling-policy">https://github.com/openzipkin/brave/tree/master/instrumentation/http#sampling-policy</link></simpara>
<simpara>If you want to completely rewrite the <literal>HttpTracing</literal> bean you can use the <literal>SkipPatternProvider</literal>
interface to retrieve the URL <literal>Pattern</literal> for spans that should be not sampled. Below you can see
an example of usage of <literal>SkipPatternProvider</literal> inside a server side, <literal>HttpSampler</literal>.</simpara>
an example of usage of <literal>SkipPatternProvider</literal> inside a server side, <literal>Sampler&lt;HttpRequest&gt;</literal>.</simpara>
<programlisting language="java" linenumbering="unnumbered">@Configuration
class Config {
@Bean(name = ServerSampler.NAME)
HttpSampler myHttpSampler(SkipPatternProvider provider) {
@Bean(name = HttpServerSampler.NAME)
SamplerFunction&lt;HttpRequest&gt; myHttpSampler(SkipPatternProvider provider) {
Pattern pattern = provider.skipPattern();
return new HttpSampler() {
@Override
public &lt;Req&gt; Boolean trySample(HttpAdapter&lt;Req, ?&gt; adapter, Req request) {
String url = adapter.path(request);
boolean shouldSkip = pattern.matcher(url).matches();
if (shouldSkip) {
return false;
}
return null;
return request -&gt; {
String url = request.path();
boolean shouldSkip = pattern.matcher(url).matches();
if (shouldSkip) {
return false;
}
return null;
};
}
}</programlisting>
@@ -1621,6 +1618,33 @@ class MyFilter extends GenericFilterBean {
}</programlisting>
</section>
<section xml:id="_rpc">
<title>RPC</title>
<simpara>Sleuth automatically configures the <literal>RpcTracing</literal> bean which serves as a
foundation for RPC instrumentation such as gRPC or Dubbo.</simpara>
<simpara>If a customization of client / server sampling of the RPC traces is required,
just register a bean of type <literal>brave.sampler.SamplerFunction&lt;RpcRequest&gt;</literal> and
name the bean <literal>sleuthRpcClientSampler</literal> for client sampler and
<literal>sleuthRpcServerSampler</literal> for server sampler.</simpara>
<simpara>For your convenience the <literal>@RpcClientSampler</literal> and <literal>@RpcServerSampler</literal>
annotations can be used to inject the proper beans or to reference the bean
names via their static String <literal>NAME</literal> fields.</simpara>
<simpara>Ex. Here&#8217;s a sampler that traces 100 "GetUserToken" server requests per second.
This doesn&#8217;t start new traces for requests to the health check service. Other
requests will use the global sampling configuration.</simpara>
<programlisting language="java" linenumbering="unnumbered">@Configuration
class Config {
@Bean(name = RpcServerSampler.NAME)
SamplerFunction&lt;RpcRequest&gt; myRpcSampler() {
Matcher&lt;RpcRequest&gt; userAuth = and(serviceEquals("users.UserService"),
methodEquals("GetUserToken"));
return RpcRuleSampler.newBuilder()
.putRule(serviceEquals("grpc.health.v1.Health"), Sampler.NEVER_SAMPLE)
.putRule(userAuth, RateLimitingSampler.create(100)).build();
}
}</programlisting>
<simpara>For more, see <link xl:href="https://github.com/openzipkin/brave/tree/master/instrumentation/rpc#sampling-policy">https://github.com/openzipkin/brave/tree/master/instrumentation/rpc#sampling-policy</link></simpara>
</section>
<section xml:id="_custom_service_name">
<title>Custom service name</title>
<simpara>By default, Sleuth assumes that, when you send a span to Zipkin, you want the span&#8217;s service name to be equal to the value of the <literal>spring.application.name</literal> property.
@@ -1857,10 +1881,10 @@ If you want to reuse Sleuth&#8217;s default skip patterns and append your own, p
<section xml:id="_dubbo_rpc_support">
<title>Dubbo RPC support</title>
<simpara>Via the integration with Brave, Spring Cloud Sleuth supports <link xl:href="https://dubbo.apache.org/">Dubbo</link>.
It&#8217;s enough to add the <literal>brave-instrumentation-dubbo-rpc</literal> dependency:</simpara>
It&#8217;s enough to add the <literal>brave-instrumentation-dubbo</literal> dependency:</simpara>
<programlisting language="xml" linenumbering="unnumbered">&lt;dependency&gt;
&lt;groupId&gt;io.zipkin.brave&lt;/groupId&gt;
&lt;artifactId&gt;brave-instrumentation-dubbo-rpc&lt;/artifactId&gt;
&lt;artifactId&gt;brave-instrumentation-dubbo&lt;/artifactId&gt;
&lt;/dependency&gt;</programlisting>
<simpara>You need to also set a <literal>dubbo.properties</literal> file with the following contents:</simpara>
<programlisting language="properties" linenumbering="unnumbered">dubbo.provider.filter=tracing