zipkin对于dubbo的支持
对于Web端:
1. 需要在applicationContext的头部添加中添加prefix引用:
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="...http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"
2. 添加dubbo的过滤器(可以和webhttpTracing公用一个Tracing)
<dubbo:consumer filter="tracing" />
3. 在pom中添加dubbo rpc的引用
<dependencyManagement> <dependencies> <dependency> <groupId>io.zipkin.brave</groupId> <artifactId>brave-bom</artifactId> <version>${brave.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>y <dependency> <groupId>io.zipkin.brave</groupId> <artifactId>brave</artifactId> </dependency> <dependency> <groupId>io.zipkin.brave</groupId> <artifactId>brave-spring-beans</artifactId> </dependency> <dependency> <groupId>io.zipkin.reporter2</groupId> <artifactId>zipkin-sender-okhttp3</artifactId> </dependency> <dependency> <groupId>io.zipkin.brave</groupId> <artifactId>brave-context-log4j12</artifactId> </dependency> <dependency> <groupId>io.zipkin.brave</groupId> <artifactId>brave-instrumentation-spring-web</artifactId> </dependency> <dependency> <groupId>io.zipkin.brave</groupId> <artifactId>brave-instrumentation-spring-webmvc</artifactId> </dependency> <dependency> <groupId>io.zipkin.brave</groupId> <artifactId>brave-instrumentation-dubbo-rpc</artifactId> </dependency>
在Provider端:
1. applicationContext.xml文件(或者自定义的bean文件)中添加prefix引用以及添加tracing bean:
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="...http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
1 <bean id="tracing" class="brave.spring.beans.TracingFactoryBean"> 2 <property name="localServiceName" value="rpc-double" /> 3 <property name="spanReporter"> 4 <bean class="zipkin2.reporter.beans.AsyncReporterFactoryBean"> 5 <property name="encoder" value="JSON_V2" /> 6 <property name="sender"> 7 <bean class="zipkin2.reporter.beans.URLConnectionSenderFactoryBean"> 8 <property name="endpoint" value="http://10.4.120.77:9411/api/v2/spans" /> 9 </bean> 10 </property> 11 <!-- wait up to half a second for any in-flight spans on close --> 12 <property name="closeTimeout" value="500" /> 13 </bean> 14 </property> 15 <property name="propagationFactory"> 16 <bean id="propagationFactory" class="brave.propagation.ExtraFieldPropagation" 17 factory-method="newFactory"> 18 <constructor-arg index="0"> 19 <util:constant static-field="brave.propagation.B3Propagation.FACTORY" /> 20 </constructor-arg> 21 <constructor-arg index="1"> 22 <list> 23 <value>user-name</value> 24 </list> 25 </constructor-arg> 26 </bean> 27 </property> 28 <property name="currentTraceContext"> 29 <bean class="brave.context.log4j12.MDCCurrentTraceContext" 30 factory-method="create" /> 31 </property> 32 </bean>
2. 添加tracing bean
<dependencyManagement> <dependencies> <dependency> <groupId>io.zipkin.brave</groupId> <artifactId>brave-bom</artifactId> <version>${brave.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependency> <groupId>io.zipkin.brave</groupId> <artifactId>brave</artifactId> </dependency> <dependency> <groupId>io.zipkin.brave</groupId> <artifactId>brave-spring-beans</artifactId> </dependency> <dependency> <groupId>io.zipkin.reporter2</groupId> <artifactId>zipkin-reporter-spring-beans</artifactId> </dependency> <dependency> <groupId>io.zipkin.reporter2</groupId> <artifactId>zipkin-sender-urlconnection</artifactId> </dependency> <dependency> <groupId>io.zipkin.reporter2</groupId> <artifactId>zipkin-sender-okhttp3</artifactId> </dependency> <dependency> <groupId>io.zipkin.brave</groupId> <artifactId>brave-instrumentation-dubbo-rpc</artifactId> </dependency> <dependency> <groupId>io.zipkin.brave</groupId> <artifactId>brave-context-log4j12</artifactId> </dependency>
坑
下午卡在了一个问题,迁移dubbo到一个单独的工程就是找不到zipkin.Endpoint;
扒拉源码也没有;后来才发现原来在dubbo的工程里面的parent中有一个io.zipkin.java.zipkin里面有这个类(之前接触的都是io.zipkin.zipkin)。坑啊。