Search code examples
spring-cloud-sleuthzipkin

How to force Zipkin/Brave/Spring-Cloud-Sleuth span to be exportable?


How can I force a Zipkin span to be exportable? In below code spans are sometimes exportable, sometimes not in a non repeatable manner.

It seems to me that if I comment first scopedSpan, than second manually created spanInScope is exportable, but how can first scopedSpan prevent second spanInScope from being exportable? How do they interfere?

    @SneakyThrows
    private void debugScopedSpan(final String label) {
        ScopedSpan scopedSpan = tracer.startScopedSpan(label + "_1").tag("type", "manual");
        try {
            log.info("===== debugScopedSpan_1 {}", label);
        } catch (RuntimeException | Error e) {
            scopedSpan.error(e);
            throw e;
        } finally {
            scopedSpan.finish();
        }

        // Why both above scopedSpan and below spanInScope cant be exportable at the same time??? How do they iterfere with each other?

        Span trace = tracer.nextSpan().name(label+"_2").tag("type", "manual").start();
        final Tracer.SpanInScope spanInScope = tracer.withSpanInScope(trace);
        log.info("===== debugScopedSpan_2 {}", label);
        spanInScope.close();
        trace.finish();
    }

Solution

  • It's because of sampling. Please create a bean of sampler type whose value can be Sampler.ALWAYS or set the probability property to 1.0