opentracingjaeger

Jaeger Service not shown in Jaeger UI


I installed the jaeger all in one in Docker with:

docker run --rm --name jaeger -p 5775:5775/udp -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778 -p  16686:16686 -p 14267:14267 -p 14268:14268 -p 9411:9411 jaegertracing/all-in-one:1.7   

And below is the sample code on how I initialize the tracer and spans. I get the logs in my console but it does not reflect in my Jaeger UI.

Could anyone please help me with this?

logging = new LoggingReporter();

SamplerConfiguration sampler = new SamplerConfiguration();
sampler.withType("const");
sampler.withParam(1);

ReporterConfiguration reporter = new ReporterConfiguration();
reporter.withLogSpans(true);
reporter.withSender(sender);        

tracer = Configuration.fromEnv("sample_jaeger").withSampler(sampler).withReporter(reporter).getTracer();

Scope scope = tracer.buildSpan("parent-span").startActive(true);
Tags.SAMPLING_PRIORITY.set(scope.span(), 1);
scope.span().setTag("this-is-test", "YUP");

logging.report((JaegerSpan) scope.span());

Solution

  • Are you closing the tracer and the scope? If you are using a version before 0.32.0, you should manually call tracer.close() before your process terminates, otherwise the spans in the buffer might not get dispatched.

    As for the scope, it's common to wrap it in a try-with-resources statement:

    try (Scope scope = tracer.buildSpan("parent-span").startActive(true)) {
      Tags.SAMPLING_PRIORITY.set(scope.span(), 1);
      scope.span().setTag("this-is-test", "YUP");
    
      logging.report((JaegerSpan) scope.span());
    }
    

    You might also want to check the OpenTracing tutorial at https://github.com/yurishkuro/opentracing-tutorial or the Katacoda-based version at https://www.katacoda.com/courses/opentracing

    -- EDIT

    and is deployed on a different hostname and port

    Then you do need to tell the tracer where to send the traces. Either export the JAEGER_ENDPOINT environment variable, pointing to a collector endpoint, or set JAEGER_AGENT_HOST/JAEGER_AGENT_PORT, with the location of the agent. You can check the available environment variables for your client on the following URL: https://www.jaegertracing.io/docs/1.7/client-features/