0

I am trying to create a tracer, then a span from the tracer. Performing work. Then closing the span. I would expect that the close action will call spanReporter.report, which should post the data to an available Zipkin server (default localhost)

However, that is not happening. Code below. I noticed that I was using NeverSampler. Changed it to AlwaysSampler (for now). I was also using NoOpSpanReporter as the default SpanReporter (which does nothing). I want to change it to a ZipkinSpanReporter. (Or something else). This is where I am stuck.

Questions:

  1. Based on the pasted code, what should be the correct type of default span report that I should use?
  2. Which jar will have the correct Span Reporter. I see class ZipkingSpanReporter in spring-cloud-sleuth-zipkin. So then, should I remove the spring-cloud-sleuth-* dependency and replace it with just the zipkin dependency?

public class TestClass {

    private TestClass() {
        // Default constructor
    }

    public static DefaultTracer createDefaultTracer() {
        boolean isTraceId128 = false;
        Sampler sampler = createDefaultTraceSampler();
        Random random = createDefaultRandomForSpanIds();
        SpanNamer spanNamer = createDefaultSpanNamer();
        SpanLogger spanLogger = createDefaultSpanLogger();
        SpanReporter spanReporter = createDefaultSpanReporter();
        TraceKeys traceKeys = new TraceKeys();

        return new DefaultTracer(sampler, random, spanNamer, spanLogger, spanReporter, isTraceId128, traceKeys);
    }

    public static Random createDefaultRandomForSpanIds() {
        return new Random();
    }

    public static Sampler createDefaultTraceSampler() {
        //return NeverSampler.INSTANCE;
        return new AlwaysSampler();
    }

    public static SpanNamer createDefaultSpanNamer() {
        return new DefaultSpanNamer();
    }

    public static SpanReporter createDefaultSpanReporter() {
        return new NoOpSpanReporter(); //What default span reporter should I use
    }

    public static SpanLogger createDefaultSpanLogger() {
        return new NoOpSpanLogger(); //I do not care about logging spans using slf4j for now
    }
}

Now the code snippet which uses the above:

DefaultTracer tracer = TestClass.createDefaultTracer();
Span mySpan=tracer.createSpan("testSpan");
 //Do work
tracer.close(mySpan);//This should stop the span and report the span to zipkin for display

Note:
This particular project does not have any http calls in any of its services. Its a data processing project.
@SpringBootApplication has not been used. (All zipkin examples use it though). Is it necessary?

alessandrio
  • 4,282
  • 2
  • 29
  • 40
Shommo
  • 1

1 Answers1

0

Appears that a sleuth span is not the same as a Zipkin span. Hence, in the above code there is no way to instantiate a default tracer with zipkin span reporter. I converted the sleuth span into a zipkin span and then reported it to zipkin. The class to convert it is available in spring-cloud-sleuth-stream. I used pretty much the same class with some tweaks.

Shommo
  • 1