如何强制Zipkin / Brave / Spring-Cloud-Sleuth跨度可导出?

问题描述

如何强制Zipkin跨度可导出? 在下面的代码段中,有时可以导出,有时不能以不可重复的方式导出。

在我看来,如果我评论一个scopedSpan,那么第二个手动创建的spanInScope可以导出,但是第一个scopedSpan如何阻止第二个spanInScope导出?他们如何干涉?

    @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();
    }

解决方法

是因为采样。请创建一个采样器类型的bean,其值可以为Sampler.ALWAYS或将概率属性设置为1.0