Search code examples
springnetflix-zuulzipkin

hosting zipkin inside proxy/zuul-gateway


zipkin is a tool for tracing request as well as tracking the span of time a service took to process the request useful in multi-service projects it doesnt require much effort for setting up u just have to add zipkin dependency in your services and define a sampler bean.

add the following dependency in project

compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-zipkin', version: '1.3.2.RELEASE'

add sampler bean inside ur project

`    @Value("${spring.sleuth.sampler.percentage}")
  String percentage;

  @Bean 
  public PercentageBasedSampler defaultSampler() { 
    SamplerProperties configuration= new SamplerProperties();
    configuration.setPercentage(Float.parseFloat(percentage));
    return new PercentageBasedSampler(configuration); 
  }  

`

add above bean when u want only fraction of ur requests traces to send to zipkin else define a bean

` @Bean 
  public AlwaysSampler defaultSampler() { return new AlwaysSampler();
  }  
`

add spring.zipkin.base-url=localhost:9411 in ur properties file and host the zipkin server on the same port defined above.

but if u r using api-gateway for accessing zipkin (in case of deplyment in cloud ) or inside proxy u may face the issue of broken ui elements when accessing thru gateway in this case im using zuul with propertis as:

zuul.routes.zipkin.path=/zipkin/* zuul.routes.zipkin.url=http://localhost:9411


Solution

  • the simplest solution i have found for solving broken ui for zipkin thru gateway is by changing following property of zipkin-server-shared.yml file inside zipkin server

    zipkin: ui: base-path: /zipkin change above property to

    zipkin: ui: base-path: /api/tracing/zipkin

    and change ur zuul path to following zuul.routes.zipkin.path=/api/tracing/*

    and than access zipkin using follwing url

    https://gatewayhost:port/api/tracing/zipkin/

    give attention to small details in config and dont forget to put trailing "/" after zipkin in url