0

I am trying to integrate my Application with Spring sleuth. I am able to do a successfull integration and I can see spans getting exported to Zipkin.
I am exporting zipkin over http.

Spring boot version - 1.5.10.RELEASE
Sleuth - 1.3.2.RELEASE
Cloud- Edgware.SR2

But now I need to do this in a more controlled way as application is already running in production and people are scared about the overhead which sleuth can have by adding @NewSpan on the methods.

  1. I need to decide on runtime wether the Trace should be added or not (Not talking about exporting). Like for actuator trace is not getting added at all. I assume this will have no overhead on the application. Putting X-B3-Sampled = 0 is not exporting but adding tracing information. Something like skipPattern property but at runtime.

  2. Always export the trace if service exceeds a certain threshold or in case of Exception.

  3. If I am not exporting Spans to zipkin then will there be any overhead by tracing information?

What about this solution? I guess this will work in sampling specific request at runtime.

    @Bean
    public Sampler customSampler(){
    return new Sampler() {
        @Override
        public boolean isSampled(Span span) {
            logger.info("Inside sampling "+span.getTraceId());
            HttpServletRequest httpServletRequest=HttpUtils.getRequest();
            if(httpServletRequest!=null && httpServletRequest.getServletPath().startsWith("/test")){
                return true;
            }else
                return false;

        }
    };
}
Art
  • 414
  • 7
  • 24

1 Answers1

1

people are scared about the overhead which sleuth can have by adding @NewSpan on the methods.

Do they have any information about the overhead? Have they turned it on and the application started to lag significantly? What are they scared of? Is this a high-frequency trading application that you're doing where every microsecond counts?

I need to decide on runtime whether the Trace should be added or not (Not talking about exporting). Like for actuator trace is not getting added at all. I assume this will have no overhead on the application. Putting X-B3-Sampled = 0 is not exporting but adding tracing information. Something like skipPattern property but at runtime.

I don't think that's possible. The instrumentation is set up by adding interceptors, aspects etc. They are started upon application initialization.

Always export the trace if service exceeds a certain threshold or in case of Exception.

With the new Brave tracer instrumentation (Sleuth 2.0.0) you will be able to do it in a much easier way. Prior to this version you would have to implement your own version of a SpanReporter that verifies the tags (if it contains an error tag), and if that's the case send it to zipkin, otherwise not.

If I am not exporting Spans to zipkin then will there be any overhead by tracing information?

Yes, there is cause you need to pass tracing data. However, the overhead is small.

Marcin Grzejszczak
  • 10,624
  • 1
  • 16
  • 32
  • Thanks for the reply. Why cant i intercept and add a skip url at runtime as code does in trace filter. Wouldnt this be a good feature to have. If not at runtime, is there a way to programatically skip all urls and allow few which i need to trace then i cn do @Refresh for that bean and add urls dynamically. – Art Feb 20 '18 at 04:55
  • Mainly sampling percentage different for each url and user should be given a choice to decide sampling and define percentage based on business needs. – Art Feb 20 '18 at 05:59
  • You will be able to do that with Sleuth 2.0 and Brave – Marcin Grzejszczak Feb 20 '18 at 07:12
  • 1
    If i am using boot 1.5.10, can I use sleuth 2.0? Also, can you please give me some pointers in sleuth 2.0, how to do that. – Art Feb 20 '18 at 07:14
  • I am also curious to know how sleuth decides wether Trace needs to be exported or not? Can I have that power to decide i sleuth 2.0? – Art Feb 20 '18 at 07:15
  • Just read Braves docs https://github.com/openzipkin/brave/blob/master/brave/README.md#sampling – Marcin Grzejszczak Feb 20 '18 at 07:21
  • Thanks!!! Can i use sleuth 2.0 with boot 1.5.10? Or it can be used only with Boot 2.0 – Art Feb 20 '18 at 07:22
  • You can use Sleuth with Boot 1.5 but it won't have Brave tracer. You can simulate a similar behavior via the skip pattern to pass a static list of urls you want to skip. – Marcin Grzejszczak Feb 20 '18 at 07:24
  • Can you please validate if my solution will work or not? Posted the solution. – Art Feb 20 '18 at 09:16
  • Maybe it will work but I have already told you to use the skip pattern for this use case - https://cloud.spring.io/spring-cloud-static/Edgware.SR2/single/spring-cloud.html#_http_filter . Please read the documentation. – Marcin Grzejszczak Feb 20 '18 at 09:24
  • I did spring.sleuth.web.skipPattern=(api/2.0*| api/test*) My server contextPath is /api. but Still i can see span getting generated and exported to Zipkin. Log line [server,71b1f2d2e12094c2,71b1f2d2e12094c2,true]. Url which i am hitting is http://localhost:8002/api/2.0/test/call – Art Feb 20 '18 at 09:57
  • I also have a confusion that if i say spring.sleuth.sampler.percentage= 0.5 then 50% of Trace info will go to Zipkin or 50% of random spans will be exported. So, for one Trace it possible that some spans are missed out while exporting to Zipkin? Have already read PercentageBasedSampler.java – Art Feb 20 '18 at 12:21
  • Please read the docs of Sleuth 1.3.x https://cloud.spring.io/spring-cloud-static/Edgware.SR2/single/spring-cloud.html#_sampling and Brave docs for Sleuth 2.0 https://github.com/openzipkin/brave/tree/master/brave#sampling . For more questions please ask the community here https://gitter.im/spring-cloud/spring-cloud-sleuth .I think I answered your questions so could you please mark this as answered? Thank you. – Marcin Grzejszczak Feb 20 '18 at 12:24