165 lines
8.4 KiB
HTML
165 lines
8.4 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en-us">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<title>Sky Walking API Guide</title>
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||
<link rel="stylesheet" type="text/css" href="../stylesheets/normalize.css" media="screen">
|
||
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
|
||
<link rel="stylesheet" type="text/css" href="../stylesheets/stylesheet.css" media="screen">
|
||
<link rel="stylesheet" type="text/css" href="../stylesheets/github-light.css" media="screen">
|
||
</head>
|
||
<body style="font-family:'Open Sans','Helvetica Neue',Helvetica,Arial,sans-serif;margin:0;padding:0;font-size:16px;line-height:1.5">
|
||
<section class="page-header" style="background-image: url(../images/backgroud.png);padding: 0.5rem 1rem;text-align:center;">
|
||
<h2 style="color:#fff;font-family:'Open Sans','Helvetica Neue',Helvetica,Arial,sans-serif;line-height:1.5">Sky Walking API Guide</h2>
|
||
</section>
|
||
|
||
<section class="main-content">
|
||
<h3>
|
||
<a id="useInSpring" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>如何追踪注册在Spring中类实例的方法调用?
|
||
</h3>
|
||
<p>1.在需要追踪的方法上,加上@Tracing标识。</p>
|
||
<pre>
|
||
public class TracingAspectBean {
|
||
|
||
@Tracing
|
||
public String doBusiness() {
|
||
System.out.println("do business");
|
||
return "Hello World";
|
||
}
|
||
}</pre>
|
||
<p><span style="color:red">注意:对于方法的追踪,仅限于实例级的public方法。其他方法由于Java运行时原因,无法追踪。</span></p>
|
||
<p>2.Spring配置文件中,配置所需如下信息。</p>
|
||
<pre>
|
||
<bean id="tracingEnhance" class="com.ai.cloud.skywalking.plugin.spring.TracingEnhanceProcessor"></pre>
|
||
|
||
<p>3.通过Spring标注,或配置文件将TracingAspectBean注册到Spring Context上下文中</p>
|
||
<h3>
|
||
<a id="useInDubbo" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>如何追踪dubbo调用?
|
||
</h3>
|
||
<p>这里的dubbo,专指阿里发布的,已停止维护的标准dubbo版本(<a href='http://dubbo.io'>dubbo.io</a>)。扩展版本dubbox请参考相关章节。</p>
|
||
<p>在客户端和服务端配置全局filter:swEnhanceFilter。</p>
|
||
<pre>
|
||
//客户端Spring配置文件
|
||
<dubbo:consumer filter="swEnhanceFilter"/>
|
||
|
||
//服务端Spring配置文件
|
||
<dubbo:provider filter="swEnhanceFilter"/></pre>
|
||
|
||
<h3>
|
||
<a id="useInDubbox" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>如何追踪dubbox 2.8.4 调用?
|
||
</h3>
|
||
<p>dubbox 2.8.4 较为符合dubbo的服务规范,这里指dubbox支持RpcContext中的attachment。追踪方式和dubbo相同。</p>
|
||
<p>在客户端和服务端配置全局filter:swEnhanceFilter。</p>
|
||
<pre>
|
||
//客户端Spring配置文件
|
||
<dubbo:consumer filter="swEnhanceFilter"/>
|
||
|
||
//服务端Spring配置文件
|
||
<dubbo:provider filter="swEnhanceFilter"/></pre>
|
||
|
||
<h3>
|
||
<a id="useInDubbox283" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>如何追踪dubbox 2.8.3 以及之前的调用?
|
||
</h3>
|
||
<p>由于引入dubbox,主要目的是使用rest+json协议,所以以下方案都是在此种调用模式下的解决方案。其他协议未测试,请谅解,望大家提供测试结果与反馈。</p>
|
||
<p>dubbox 2.8.3 以及之前版本不能正确的支持RpcContext中的attachment,存在BUG(2.8.4已修复)。采用扩展参数对象的方法支持追踪的传递性。</p>
|
||
<p><span style="color:red">注意:依然推荐升级到dubbox 2.8.4,此时能更好的进行追踪,并对程序侵入性更小。</span></p>
|
||
<p>1.在客户端和服务端配置全局filter:swEnhanceFilter。</p>
|
||
<pre>
|
||
//客户端Spring配置文件
|
||
<dubbo:consumer filter="swEnhanceFilter"/>
|
||
|
||
//服务端Spring配置文件
|
||
<dubbo:provider filter="swEnhanceFilter"/></pre>
|
||
<p>2.在客户端和服务端启动时,开启dubbox 2.8.3之前版本的修复功能。在服务启动前调用如下代码,或将com.ai.cloud.skywalking.plugin.dubbox.bugfix.below283.BugFixAcitve注册到Spring中。</p>
|
||
<pre>
|
||
new com.ai.cloud.skywalking.plugin.dubbox.bugfix.below283.BugFixAcitve();</pre>
|
||
|
||
<p>3.dubbox调用参数包含javabean参数,并继承com.ai.cloud.skywalking.plugin.dubbox.bugfix.below283.SWBaseBean。<span style="color:red">只包含java基础类型(如:String、Integer等)的调用,无法支持追踪传递</span></p>
|
||
|
||
<p>4.客户端如果直接使用非dubbox客户端发起调用,需要在发送的参数中设置contextData。</p>
|
||
|
||
<h3>
|
||
<a id="useInMySQL" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>如何追踪MySQL访问?
|
||
</h3>
|
||
<p>1.设置特定的JDBC Driver</p>
|
||
<pre>Driver="com.ai.cloud.skywalking.plugin.jdbc.mysql.MySQLTracingDriver"</pre>
|
||
<p>2.设置特定的JDBC URL</p>
|
||
<p></p>
|
||
<pre>jdbc.url=tracing:jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8</pre>
|
||
|
||
<h3>
|
||
<a id="useInJDBC" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>如何追踪MySQL之外的其他JDBC?
|
||
</h3>
|
||
<p>1.轻松实现自定义的JDBC Driver扩展</p>
|
||
<pre>import java.sql.Driver;
|
||
import java.sql.DriverManager;
|
||
import java.sql.SQLException;
|
||
|
||
import com.ai.cloud.skywalking.plugin.jdbc.TracingDriver;
|
||
|
||
public class XXXDBTracingDriver extends TracingDriver {
|
||
static {
|
||
try {
|
||
DriverManager.registerDriver(new MySQLTracingDriver());
|
||
} catch (SQLException e) {
|
||
throw new RuntimeException("register "
|
||
+ MySQLTracingDriver.class.getName() + " driver failure.");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 继承自TracingDriver,返回真实的Driver
|
||
*/
|
||
@Override
|
||
protected Driver registerTracingDriver() {
|
||
try {
|
||
//示例:return new com.mysql.jdbc.Driver();
|
||
return new Driver();
|
||
} catch (SQLException e) {
|
||
throw new RuntimeException("create Driver failure.");
|
||
}
|
||
}
|
||
|
||
}
|
||
</pre>
|
||
<p>2.设置新实现的JDBC Driver</p>
|
||
<pre>Driver="XXXDBTracingDriver"</pre>
|
||
<p>3.设置特定的JDBC URL</p>
|
||
<pre>jdbc.url=tracing:jdbc:xxxdb://localhost:3306/test</pre>
|
||
|
||
<h3>
|
||
<a id="useInWebFilter" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>如何追踪web服务端访问?
|
||
</h3>
|
||
<p>服务端使用Filter追踪web请求</p>
|
||
<pre> <filter>
|
||
<filter-namer>tracingFilter</filter-namer>
|
||
<filter-classr>com.ai.cloud.skywalking.plugin.web.SkyWalkingFilter</filter-class>
|
||
<init-param>
|
||
<param-name>tracing-name</param-name>
|
||
<!--分布式埋点信息,默认放在request的header中,key=SkyWalking-TRACING-NAME,可根据需要修改-->
|
||
<param-value>SkyWalking-TRACING-NAME</param-value>
|
||
</init-param>
|
||
</filterr>
|
||
<filter-mappingr>
|
||
<filter-name>tracingFilter</filter-namer>
|
||
<!--追踪路径应为MVC的请求路径,不建议包括js/css/图片等资源路径-->
|
||
<url-patternr>/request-uri</url-patternr>
|
||
</filter-mappingr></pre>
|
||
|
||
<h3>
|
||
<a id="useInHttpClient" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>如何通过HttpClient追踪HTTP调用?
|
||
</h3>
|
||
<p>使用SWTracingHttpClient封装所需的httpClient,此httpClient所有调用都会被监控</p>
|
||
<pre>HttpClient httpclient = new SWTracingHttpClient(new DefaultHttpClient());</pre>
|
||
<p>上下文将被存储在http request head,中,默认名称和SkyWalkingFilter保持一致。<br/>如果服务端使用dubbox 2.4.3 的提供的http-rest,请使用方法重载</p>
|
||
<pre>HttpClient httpclient = new SWTracingHttpClient(new DefaultHttpClient(), "Dubbo-Attachments");</pre>
|
||
|
||
<footer class="site-footer">
|
||
<span class="site-footer-owner"><a href="http://wu-sheng.github.io/sky-walking">Sky Walking</a> is maintained by <a href="https://github.com/wu-sheng">吴晟</a>,<a href="https://github.com/ascrutae">张鑫</a>,<a href="https://github.com/tanzhen84">谭真</a>.</span>
|
||
</footer>
|
||
</section>
|
||
</body>
|
||
|
||
</html> |