Contenu connexe Similaire à Tracing Microservices with Zipkin Similaire à Tracing Microservices with Zipkin (20) Tracing Microservices with Zipkin5. Storage configuration
STORAGE_TYPE=cassandra java -jar zipkin.jar
https://github.com/openzipkin/zipkin/blob/master/zipkin-server/README.md
STORAGE_TYPE=mysql MYSQL_USER=root java -jar zipkin.jar
STORAGE_TYPE=elasticsearch ES_HOSTS=http://localhost:9200 java -jar zipkin.jar
● Cassandra
● MySQL
● Elasticsearch
8. Brave
● A library to send tracing data to Zipkin server
for Java applications
● Provides a servlet filter and interceptors for
some HTTP client libraries
○ Apache HttpComponents / OkHttp
● Also framework integration is available
○ Jersey / RESTEasy / JAXRS2 / Spring
10. Register BraveServletFilter
@WebListener
public class RegisterBraveListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent servletContextEvent) {
// Create Reporter
String zipkinServerUrl = "http://localhost:9411/api/v1/spans";
Reporter reporter = AsyncReporter
.builder(OkHttpSender.create(zipkinServerUrl)).build();
// Create Brave instance
Brave brave = new Brave.Builder("zipkin-sample-webapp").reporter(reporter).build();
// Register BraveServletFilter
ServletContext context = servletContextEvent.getServletContext();
context.addFilter("BraveServletFilter", BraveServletFilter.builder(brave).build());
context.getFilterRegistration("BraveServletFilter")
.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
}
}
11. Register interceptor to OkHttp
// Create Brave instance
Brave brave = ...
// Create BraveTraceInterceptor
BraveTracingInterceptor intercaptor = BraveTracingInterceptor.create(brave);
// Create OkHttpClient with BraveTraceInterceptor
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(intercaptor)
.addNetworkInterceptor(intercaptor)
.build();
14. Zipkin API
curl -XGET http://localhost:9411/api/v1/trace/7d4d6ed9bc43c430
[{"traceId":"7d4d6ed9bc43c430","id":"7d4d6ed9bc43c430","name":"get","timestamp
":1484973234512932,"duration":36253,"binaryAnnotations":[{"key":"lc","value":"
okhttp","endpoint":{"serviceName":"client","ipv4":"192.168.0.1"}}]},{"traceId"
:"7d4d6ed9bc43c430","id":"2a12885cfd4fad6a","name":"get","parentId":"7d4d6ed9b
c43c430","timestamp":1484973234513711,"duration":35305,"annotations":[{"timest
amp":1484973234513711,"value":"cs","endpoint":{"serviceName":"client","ipv4":"
192.168.0.1"}},{"timestamp":1484973234535740,"value":"sr","endpoint":{"service
Name":"server","ipv4":"192.168.0.1"}},{"timestamp":1484973234536179,"value":"s
s","endpoint":{"serviceName":"server","ipv4":"192.168.0.1"}},{"timestamp":1484
973234549016,"value":"cr","endpoint":{"serviceName":"client","ipv4":"192.168.0
.1"}}],"binaryAnnotations":[{"key":"ca","value":true,"endpoint":{"serviceName"
:"","ipv4":"127.0.0.1","port":60213}},{"key":"http.status_code","value":"200",
"endpoint":{"serviceName":"server","ipv4":"192.168.0.1"}},{"key":"http.url","v
alue":"/sample3","endpoint":{"serviceName":"server","ipv4":"192.168.0.1"}},{"k
ey":"http.url","value":"http://localhost:8080/sample3","endpoint":{"serviceNam
e":"client","ipv4":"192.168.0.1"}},{"key":"sa","value":true,"endpoint":{"servi
ceName":"","ipv4":"127.0.0.1","port":8080}}]}]
15. Libraries for other languages
● zipkin-go-opentracing
● brave (Java)
● zipkin-js
● zipkin-ruby
● zipkin-finagle
16. In clojure
● clj-zipkin is available
○ Fundamental API
○ Scribe propagation only
(:require [clj-zipkin.tracer :as t)
(t/trace {:host "10.2.1.2"
:span "GET"
:scribe {:host "zipkin.host" :port 9410}}
(..code..)
(t/trace {:host "10.2.1.2" :span "OTHER"}
(..code..)))
17. Stackdriver Driver Zipkin Controller
● Google released an open-source zipkin server
○ Stackdriver is an monitoring service provided by
Google Cloud Platform
○ stackdriver-zipkin allows zipkin clients to send tracing
data to Google Stackdriver Trace