Search code examples
spring-cloud-streamzipkinspring-cloud-sleuth

spring-cloud-sleuth Trace via spring-cloud-stream with rabbitmq-binder: how to finish the Trace


I have setup a demo project using spring-cloud-stream with RabbitMQ-binders and spring-cloud-sleuth.

dependencies {
    annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" // for @ConfigurationProperties, make sure compileJava.dependsOn(processResources)
    compile 'org.springframework.boot:spring-boot-starter-security'
    compile 'org.springframework.boot:spring-boot-starter-actuator'
    compile 'org.springframework.cloud:spring-cloud-starter-config'
    compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
    compile 'org.springframework.cloud:spring-cloud-starter-sleuth'
    compile "org.springframework.boot:spring-boot-starter-web-services" // I also have some REST endpoints
    compile 'org.springframework.cloud:spring-cloud-stream-binder-rabbit'
}

I have a scheduled spring-cloud-stream source:

@Scheduled(fixedDelay = 2500, initialDelay = 500)
@HystrixCommand(fallbackMethod = "fallbackTimerMessageSource")
@SendTo(SourceChannels.OUTPUT)
public void timerMessageSource() {
     ...

and then a middle tier, similar to the final sink layer looking like:

@Autowired
private Tracer sleuthTracer;


@StreamListener(SinkChannels.INPUT)
public void sinked(MessageDTO payload) {
    logger.info("[{}]sinked by {} with '{}'", instanceIndex, Sink.class.getSimpleName(), payload);
    ...

I nicely see the TraceId and SpanId automagically passed through the RabbitMQ queues across all processes down to the sink process in the logfiles:

2018-03-20 20:55:10.580  INFO [circuitbreakers_sink,820fcab9830191c7,a388974ea57dac3a,true] 43379 --- [k27JdIWK8axsQ-1] c.d.minimal.circuitbreaker.sinks.Sink    : [0]sinked by Sink with 'Tue Mar 20 20:55:06 CET 2018 MESSAGE: 'fromSource transformed by tier1 transformed by tier2' modifiers: ' modBy:tier1:i0 modBy:tier2:i0''

so at this point the final sink tier wants to (explicitly) signal, that this trace (instance of my business process) is finished here.

How do I signal that the whole Trace has finished?

I only found sleuthTracer.currentSpan().finish(); but this only finishes the Span ... not explicitly signalling, that the whole trace is finalized here.

Did I miss something? (quite new to zipkin, brave and sleuth)


Solution

  • There's no concept of a trace finishing in zipkin. A span within a trace can start and finish. We don't start and stop spans on different hosts, so unfinished spans probably are accidental. You can chat more here if you like https://gitter.im/spring-cloud/spring-cloud-sleuth