Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Tracing Microservices with Zipkin

8,886 views

Published on

#渋谷java

Published in: Software
  • Be the first to comment

Tracing Microservices with Zipkin

  1. 1. Tracing Microservices with Zipkin Naoki Takezoe @takezoen #渋谷java
  2. 2. What's Zipkin? ● Distributed tracing system ● Created by Twitter and open-sourced in 2012 ● Design based on the Google Dapper paper
  3. 3. Zipkin UI
  4. 4. How? Service1 Zipkin server Service2 Service3 In-Memory / MySQL / Cassandra / Elasticsearch Send tracing data via HTTP / Kafka / Scribe to Zipkin server
  5. 5. 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
  6. 6. HTTP headrs ● X-B3-TraceId ● X-B3-SpanId ● X-B3-ParentSpanId ● X-B3-Sampled (set from sampling rate) ● X-B3-Flags (debug flag)
  7. 7. Trace and Span Span Trace
  8. 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
  9. 9. Tracing points ServletFilter HTTP client library Interceptor Application Begin Begin End End
  10. 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. 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();
  12. 12. Notes Brave uses ThreadLocal to carry tracing data Displayed as independent traces...
  13. 13. Zipkin API ● /api/v1 ○ /dependencies ○ /services ○ /spans ○ /trace/{traceId} ○ /traces
  14. 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. 15. Libraries for other languages ● zipkin-go-opentracing ● brave (Java) ● zipkin-js ● zipkin-ruby ● zipkin-finagle
  16. 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. 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
  18. 18. Today's sample application is here: https://github.com/takezoe/zipkin-sample-webapp

×