content/references/java-chassis/en_US/general-development/customized-tracing/index.html (369 lines of code) (raw):

<!DOCTYPE html> <html class="writer-html5" lang="en" > <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="shortcut icon" href="../../img/favicon.ico" /> <title>Customized-Tracing - ServiceComb Java Chassis Developers Guide</title> <link rel="stylesheet" href="../../css/theme.css" /> <link rel="stylesheet" href="../../css/theme_extra.css" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/github.min.css" /> <script> // Current page data var mkdocs_page_name = "Customized-Tracing"; var mkdocs_page_input_path = "general-development/customized-tracing.md"; var mkdocs_page_url = null; </script> <script src="../../js/jquery-3.6.0.min.js" defer></script> <!--[if lt IE 9]> <script src="../../js/html5shiv.min.js"></script> <![endif]--> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js"></script> <script>hljs.initHighlightingOnLoad();</script> </head> <body class="wy-body-for-nav" role="document"> <div class="wy-grid-for-nav"> <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav"> <div class="wy-side-scroll"> <div class="wy-side-nav-search"> <a href="../.." class="icon icon-home"> ServiceComb Java Chassis Developers Guide </a><div role="search"> <form id ="rtd-search-form" class="wy-form" action="../../search.html" method="get"> <input type="text" name="q" placeholder="Search docs" title="Type search term here" /> </form> </div> </div> <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> <ul> <li class="toctree-l1"><a class="reference internal" href="../..">Introduction</a> </li> </ul> <p class="caption"><span class="caption-text">Getting Started</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../start/terminology/">Glossary</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../start/architecture/">Architecture</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../start/development-environment/">Development environment</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../start/first-sample/">Develop the first microservice</a> </li> </ul> <p class="caption"><span class="caption-text">Development Service Provider</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/definition/service-definition/">Service definition</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/define-contract/">Service contract definition</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/code-first/">Implicit API definition</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/swagger-annotation/">Use Swagger annotations</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/springmvc/">Develop with SpringMVC</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/jaxrs/">Develop with JAX-RS</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/transparent-rpc/">Develop with Transparent RPC</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/interface-constraints/">Interface definition and data type</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/listen-address-and-publish-address/">Service listening address and publishing address</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/thread-pool/">Thread pool</a> </li> <li class="toctree-l1"><a class="reference internal" href="#">Service Configuration</a> <ul> <li class="toctree-l2"><a class="reference internal" href="../../build-provider/configuration/ratelimite-strategy/">Rate Limiting Policy</a> </li> <li class="toctree-l2"><a class="reference internal" href="../../build-provider/configuration/downgrade-strategy/">Fallback Policy</a> </li> <li class="toctree-l2"><a class="reference internal" href="../../build-provider/configuration/parameter-validator/">Parameter Validator</a> </li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/bootup/">Boot-up Process</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-provider/access-log-configuration/">Access Log Configuration</a> </li> </ul> <p class="caption"><span class="caption-text">Writing Service Consumer</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../build-consumer/common-configuration/">Consumer common configuration</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-consumer/using-resttemplate/">Using Rest Template</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-consumer/using-AsyncRestTemplate/">Using AsyncRestTemplate</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-consumer/develop-consumer-using-rpc/">Using with RPC</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-consumer/with-contract/">Contract</a> </li> <li class="toctree-l1"><a class="reference internal" href="#">Invoke control</a> <ul> <li class="toctree-l2"><a class="reference internal" href="../../build-consumer/circuit-breaker/">Circuit Breaker</a> </li> <li class="toctree-l2"><a class="reference internal" href="../../build-consumer/flow-control/">Flow Control</a> </li> <li class="toctree-l2"><a class="reference internal" href="../../build-consumer/fault-injection/">Fault Injection</a> </li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="../../build-consumer/3rd-party-service-invoke/">Invoke 3rd-party REST services</a> </li> </ul> <p class="caption"><span class="caption-text">Transports</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../transports/rest-over-servlet/">REST over Servlet</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../transports/rest-over-vertx/">REST over Vertx</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../transports/highway-rpc/">Highway</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../transports/http2/">HTTP2</a> </li> </ul> <p class="caption"><span class="caption-text">General Development</span></p> <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="../visit-sc/">Access Service Center</a> </li> <li class="toctree-l1"><a class="reference internal" href="../metrics/">Metrics</a> </li> <li class="toctree-l1"><a class="reference internal" href="../microservice-invocation-chain/">Microservice invocation chain</a> </li> <li class="toctree-l1 current"><a class="reference internal current" href="./">Customized-Tracing</a> <ul class="current"> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="../local-develop-test/">Local development and testing</a> </li> <li class="toctree-l1"><a class="reference internal" href="../http-filter/">Http Filter</a> </li> <li class="toctree-l1"><a class="reference internal" href="../file-upload/">File Uploading</a> </li> <li class="toctree-l1"><a class="reference internal" href="../file-download/">File Downloading</a> </li> <li class="toctree-l1"><a class="reference internal" href="../reactive/">Reactive Programing</a> </li> <li class="toctree-l1"><a class="reference internal" href="../dnsconfig/">DNS Custom Configuration</a> </li> <li class="toctree-l1"><a class="reference internal" href="../dai-li-she-zhi/">Proxy Settings</a> </li> <li class="toctree-l1"><a class="reference internal" href="../report-framework-version/">Report framework version</a> </li> <li class="toctree-l1"><a class="reference internal" href="../cross-app-invocation/">Cross-application invocation</a> </li> <li class="toctree-l1"><a class="reference internal" href="../secret-field/">Customized serialization and deserialization</a> </li> <li class="toctree-l1"><a class="reference internal" href="../context/">Using Context to pass control messages</a> </li> <li class="toctree-l1"><a class="reference internal" href="../produceprocess/">Return value serialization extension</a> </li> <li class="toctree-l1"><a class="reference internal" href="../CORS/">CORS mechanism</a> </li> <li class="toctree-l1"><a class="reference internal" href="../AlarmEvent/">Get fuse and instance isolation alarm event information</a> </li> <li class="toctree-l1"><a class="reference internal" href="../shutdown/">Shutdown gracefully</a> </li> <li class="toctree-l1"><a class="reference internal" href="../error-handling/">Handling exceptions</a> </li> <li class="toctree-l1"><a class="reference internal" href="../multienvironment/">Multi-environment isolation between microservice instances</a> </li> <li class="toctree-l1"><a class="reference internal" href="../thread-model/">Thread Model</a> </li> </ul> <p class="caption"><span class="caption-text">Configuration</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../config/general-config/">General config</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../config/inject-config/">Configuration injection</a> </li> </ul> <p class="caption"><span class="caption-text">Service Capability Open</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../edge/open-service/">Intruductions</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../edge/by-servicecomb-sdk/">Using Edge Service</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../edge/nginx/">Using confd and Nginx as edge services</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../edge/zuul/">Use zuul as edge services</a> </li> </ul> <p class="caption"><span class="caption-text">Service Packing and Running</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../packaging/standalone/">Standalone mode</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../packaging/web-container/">WEB container mode</a> </li> </ul> <p class="caption"><span class="caption-text">Micro Service Security</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../security/tls/">Using TLS</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../security/rsa/">Using RSA certification</a> </li> </ul> <p class="caption"><span class="caption-text">Using java chassis in Spring Boot</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/using-java-chassis-in-spring-boot/">Intruductions</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/components-for-spring-boot/">spring boot starter for java-chassis</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/java-application/">JAVA application development</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/web-application/">Web development method development</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/diff-between-java-web/">The difference between JAVA application method and Web development method</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/diff-spring-mvc/">The difference in Spring MVC mode</a> </li> </ul> <p class="caption"><span class="caption-text">Handlers reference</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../references-handlers/intruduction/">Intruductions</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../references-handlers/loadbalance/">Load Balancing</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../references-handlers/publickey/">Public key authentication</a> </li> </ul> <p class="caption"><span class="caption-text">FAQ</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="../../question-and-answer/question_answer/">Q & A</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../question-and-answer/faq/">FAQ</a> </li> <li class="toctree-l1"><a class="reference internal" href="../../question-and-answer/interface-compatibility/">Micro Service Interface Compatibility FAQ</a> </li> </ul> </div> </div> </nav> <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> <nav class="wy-nav-top" role="navigation" aria-label="Mobile navigation menu"> <i data-toggle="wy-nav-top" class="fa fa-bars"></i> <a href="../..">ServiceComb Java Chassis Developers Guide</a> </nav> <div class="wy-nav-content"> <div class="rst-content"><div role="navigation" aria-label="breadcrumbs navigation"> <ul class="wy-breadcrumbs"> <li><a href="../.." class="icon icon-home" alt="Docs"></a> &raquo;</li> <li>General Development &raquo;</li> <li>Customized-Tracing</li> <li class="wy-breadcrumbs-aside"> </li> </ul> <hr/> </div> <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> <div class="section" itemprop="articleBody"> <h2 id="concept-description">Concept Description</h2> <p>Distributed call chain tracking provides timing information for calls between services, but the link call information inside the service is equally important to the developer. If you can combine the two into one, you can provide a more complete call chain, which is easier to locate. Errors and potential performance issues.</p> <h2 id="prerequisites">Prerequisites</h2> <ul> <li>Using the custom dot function requires first configuring and enabling the Java Chassis microservice call chain.</li> </ul> <h2 id="precautions">Precautions</h2> <ul> <li>The custom dot function using the <code>@Span</code> annotation only supports method calls that are requesting the same thread as the Java Chassis call.</li> <li>The method to add the <code>@Span</code> annotation must be a Spring-managed bean, otherwise you need to press the [Methods mentioned] (https://stackoverflow.com/questions/41383941/load-time-weaving-for-non-spring -beans-in-a-spring-application) configuration.</li> </ul> <h2 id="custom-call-chain-management">Custom call chain management</h2> <p>This feature integrates Zipkin and provides the <code>@Span</code> annotation for custom tracking of methods that need to be tracked. Java Chassis will automatically track all methods that add <code>@Span</code> annotations, linking the local call information of each method to the call information between services.</p> <h2 id="steps-for-usage">Steps for usage:</h2> <h3 id="adding-dependencies">Adding dependencies</h3> <p>Microservices based on ServiceComb Java Chassis only need to add the following dependency to pom.xml:</p> <pre><code class="language-xml"> &lt;dependency&gt; &lt;groupId&gt;org.apache.servicecomb&lt;/groupId&gt; &lt;artifactId&gt;tracing-zipkin&lt;/artifactId&gt; &lt;/dependency&gt; </code></pre> <h3 id="enable-custom-management-function-configure-tracking-processing-and-data-collection">Enable custom management function {#Configure tracking processing and data collection}</h3> <p>Add the <code>@EnableZipkinTracing</code> annotation to the application portal or Spring configuration class:</p> <pre><code class="language-java">@SpringBootApplication @EnableZipkinTracing public class ZipkinSpanTestApplication { public static void main(String[] args) { SpringApplication.run(ZipkinSpanTestApplication.class); } } </code></pre> <h3 id="customized-management">Customized management</h3> <p>Add the <code>@Span</code> annotation to the method that requires custom management:</p> <pre><code class="language-java">@Component public class SlowRepoImpl implements SlowRepo { private static final Logger logger = LoggerFactory.getLogger(SlowRepoImpl.class); private final Random random = new Random(); @Span @Override public String crawl() throws InterruptedException { logger.info(&quot;in /crawl&quot;); Thread.sleep(random.nextInt(200)); return &quot;crawled&quot;; } } </code></pre> <p>In this way, by using the <code>@Span</code> annotation, we started the Zipkin-based custom management function.</p> <h2 id="customized-reported-data">Customized reported data</h2> <p>The call chain that is escalated by custom management contains two pieces of data:</p> <ul> <li><strong>span name</strong> defaults to the full name of the method currently being annotated.</li> <li><strong>call.path</strong> defaults to the method signature of the current annotation.</li> </ul> <p>For example, the data reported in the above example <code>SlowRepoImp</code> is as follows:</p> <table> <thead> <tr> <th align="left">key</th> <th align="left">value</th> </tr> </thead> <tbody> <tr> <td align="left">span name</td> <td align="left">crawl</td> </tr> <tr> <td align="left">call.path</td> <td align="left">public abstract java.lang.String org.apache.servicecomb.tests.tracing.SlowRepo.crawl() throws java.lang.InterruptedException</td> </tr> </tbody> </table> <p>If you need to customize the reported data content, you can pass in the custom parameters:</p> <pre><code class="language-java"> public static class CustomSpanTask { @Span(spanName = &quot;transaction1&quot;, callPath = &quot;startA&quot;) public String invoke() { return &quot;invoke the method&quot;; } } </code></pre> </div> </div><footer> <div class="rst-footer-buttons" role="navigation" aria-label="Footer Navigation"> <a href="../microservice-invocation-chain/" class="btn btn-neutral float-left" title="Microservice invocation chain"><span class="icon icon-circle-arrow-left"></span> Previous</a> <a href="../local-develop-test/" class="btn btn-neutral float-right" title="Local development and testing">Next <span class="icon icon-circle-arrow-right"></span></a> </div> <hr/> <div role="contentinfo"> <!-- Copyright etc --> </div> Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. </footer> </div> </div> </section> </div> <div class="rst-versions" role="note" aria-label="Versions"> <span class="rst-current-version" data-toggle="rst-current-version"> <span><a href="../microservice-invocation-chain/" style="color: #fcfcfc">&laquo; Previous</a></span> <span><a href="../local-develop-test/" style="color: #fcfcfc">Next &raquo;</a></span> </span> </div> <script>var base_url = '../..';</script> <script src="../../js/theme_extra.js" defer></script> <script src="../../js/theme.js" defer></script> <script src="../../search/main.js" defer></script> <script defer> window.onload = function () { SphinxRtdTheme.Navigation.enable(true); }; </script> </body> </html>