Configuring Java libray to work with Multiple Jaeger Collectors

88 views
Skip to first unread message

Bikramjit Naha

unread,
Mar 23, 2021, 5:14:32 AM3/23/21
to Jaeger Tracing

Hello,
We have a requirement to configure multiple Jaeger Collectors using Java Open tracing Libraries.     
This is our dependency
<dependency>
            <groupId>io.opentracing.contrib</groupId>
            <artifactId>opentracing-spring-jaeger-cloud-starter</artifactId>
            <version>3.1.1</version>
        </dependency>

For Single Collector Configuration we are using this api call.
SenderConfiguration senderConfig = new SenderConfiguration().withEndpoint("http://localhost:14268/api/traces");
How to configure two collectors using this approach.?

Yuri Shkuro

unread,
Mar 23, 2021, 10:20:01 AM3/23/21
to Bikramjit Naha, Jaeger Tracing
Implement your own Reporter that takes two RemoteReporters in the constructor and invokes each of them for each span.

On Mar 23, 2021, at 5:14 AM, Bikramjit Naha <buro...@gmail.com> wrote:


--
You received this message because you are subscribed to the Google Groups "Jaeger Tracing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jaeger-tracin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jaeger-tracing/3fb2d86e-b4cb-4c5f-807c-d89c5dfd9697n%40googlegroups.com.
Message has been deleted

Bikramjit Naha

unread,
Mar 25, 2021, 3:27:00 AM3/25/21
to Jaeger Tracing
Hi Yury,
This is how we are trying to create 2 Reporter objects for two Collectors and then using the returned  Tracer object we are sending span information. But none of the span information seems to go to the collectors.
Attaching code that shows how Tracer object is getting created for 2 reporters

public Tracer jaegerTracer() {
// Get the Sampler configuration (one for all the reporters)
SamplerType samplerType = SamplerType.fromValue("const");
Number samplerParamNumber = getSamplerParamNumber(samplerType, "1");
Sampler sampler = getSampler(samplerType.getValue(), samplerParamNumber, "localhost:5778"); List<Reporter> reporters = new LinkedList<>();
if (logSpans) {
reporters.add(new LoggingReporter());
}
// reporters.addAll(getConfiguredReporters()); // Creating the CompositeReporter which holds all the other reporters
SenderConfiguration senderConfiguration = new SenderConfiguration(); Reporter reporter1 = new RemoteReporter.Builder()
.withSender(senderConfiguration.withEndpoint("http://localhost:14268/api/traces").getSender())
.withFlushInterval(io.jaegertracing.internal.reporters.RemoteReporter.DEFAULT_FLUSH_INTERVAL_MS)
.withMaxQueueSize(io.jaegertracing.internal.reporters.RemoteReporter.DEFAULT_MAX_QUEUE_SIZE).build();
reporters.add(reporter1);
Reporter reporter2 = new RemoteReporter.Builder()
.withSender(senderConfiguration.withEndpoint("http://9.402.10.9:14268/api/traces").getSender())
.withFlushInterval(io.jaegertracing.internal.reporters.RemoteReporter.DEFAULT_FLUSH_INTERVAL_MS)
.withMaxQueueSize(io.jaegertracing.internal.reporters.RemoteReporter.DEFAULT_MAX_QUEUE_SIZE).build();

reporters.add(reporter2); Reporter reporter = new CompositeReporter(reporters.toArray(new Reporter[reporters.size()])); final JaegerTracer.Builder builder = new JaegerTracer.Builder(serviceName).withReporter(reporter)
.withSampler(sampler); return builder.build();
}
Below code snippet that is showing how span is generated
Tracer myTracer = jaegerTracer();
Span span = null;
try {
SpanContext parentSpanCtx = myTracer.extract(Format.Builtin.HTTP_HEADERS, new TextMapAdapter(headers)); if (parentSpanCtx == null) {
span = myTracer.buildSpan(request.getRequestURI()).start();
} else {
span = myTracer.buildSpan(request.getRequestURI()).asChildOf(parentSpanCtx).start();
}
} catch (IllegalArgumentException e) {
span = myTracer.buildSpan(request.getRequestURI()).start();
}

Yuri Shkuro

unread,
Mar 25, 2021, 9:08:34 AM3/25/21
to Bikramjit Naha, Jaeger Tracing
I am not seeing any span.finish() calls or other practices for ensuring that the reporter buffer is flushed. I suggest you start with making your application generate traces with a normal reporter: https://github.com/yurishkuro/opentracing-tutorial

Arun Kumar

unread,
Mar 25, 2021, 1:24:45 PM3/25/21
to Jaeger Tracing
Hi Yuri,

I am working with buronaha.
I am posting the full code with multiple reporters and the API to invoke the span of the Tracer Object.
Requesting your support for helping us to resolve the issue.

Issue would be: Trace information not going to both collectors using Reporters
public Tracer jaegerTracer() {
// Get the Sampler configuration (one for all the reporters)
SamplerType samplerType = SamplerType.fromValue("const");
Number samplerParamNumber = getSamplerParamNumber(samplerType, "1");
Sampler sampler = getSampler(samplerType.getValue(), samplerParamNumber, "localhost:5778");

List<Reporter> reporters = new LinkedList<>();
if (logSpans) {
reporters.add(new LoggingReporter());
}

// Creating the CompositeReporter which holds all the other reporters
SenderConfiguration senderConfiguration = new SenderConfiguration();

Reporter reporter1 = new RemoteReporter.Builder()
.withSender(senderConfiguration.withEndpoint("http://localhost:14268/api/traces").getSender())
.withFlushInterval(io.jaegertracing.internal.reporters.RemoteReporter.DEFAULT_FLUSH_INTERVAL_MS)
.withMaxQueueSize(io.jaegertracing.internal.reporters.RemoteReporter.DEFAULT_MAX_QUEUE_SIZE).build();

Reporter reporter2 = new RemoteReporter.Builder()
.withSender(senderConfiguration.withEndpoint("http://xx.xx.xx.xx:14268/api/traces").getSender())
.withFlushInterval(io.jaegertracing.internal.reporters.RemoteReporter.DEFAULT_FLUSH_INTERVAL_MS)
.withMaxQueueSize(io.jaegertracing.internal.reporters.RemoteReporter.DEFAULT_MAX_QUEUE_SIZE).build();

reporters.add(reporter2);
reporters.add(reporter1);
System.out.println("Reporter reporter Before: " + reporters.toString());
Reporter reporter = new CompositeReporter(reporters.toArray(new Reporter[reporters.size()]));

System.out.println("Reporter reporter : " + reporter.toString());
final JaegerTracer.Builder builder = new JaegerTracer.Builder(serviceName).withReporter(reporter)
.withSampler(sampler);

return builder.build();
}

// This is how we retrieving the trace and span object 
Tracer myTracer = jaegerTracer();
         Span span = null
try {
SpanContext parentSpanCtx = myTracer.extract(Format.Builtin.HTTP_HEADERS, new TextMapAdapter(headers));

if (parentSpanCtx == null) {
span = myTracer.buildSpan(request.getRequestURI()).start();
} else {
span = myTracer.buildSpan(request.getRequestURI()).asChildOf(parentSpanCtx).start();
}
} catch (IllegalArgumentException e) {
span = myTracer.buildSpan(request.getRequestURI()).start();
}

String requestUri = request.getRequestURI().toString();

Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_SERVER);
Tags.HTTP_METHOD.set(span, request.getMethod());
Tags.HTTP_URL.set(span, requestUri);
span.finish();

Arun Kumar

unread,
Mar 26, 2021, 5:04:21 AM3/26/21
to Jaeger Tracing
Hi, 
Use the below code changes first report in the list is able to send the span information to the collector it is configured for. The second reporter is unable to send span to the collector it is configured for. If I change the order of adding reporters then the first only seems to send spans to collectors.

public JaegerTracer jaegerTracer() {
// Get the Sampler configuration (one for all the reporters)
SamplerType samplerType = SamplerType.fromValue("const");
Number samplerParamNumber = getSamplerParamNumber(samplerType, "1");
Sampler sampler = getSampler(samplerType.getValue(), samplerParamNumber, "");

List<Reporter> reporters = new LinkedList<>();
if (logSpans) {
reporters.add(new LoggingReporter());
}
// reporters.addAll(getConfiguredReporters());

// Creating the CompositeReporter which holds all the other reporters
SenderConfiguration senderConfiguration = new SenderConfiguration();
metricsFactory = new InMemoryMetricsFactory();
metrics = new Metrics(metricsFactory);

RemoteReporter reporter1 = new RemoteReporter.Builder()
.withSender(senderConfiguration.withEndpoint("http://x.x.x.x:14268/api/traces").getSender())
.withFlushInterval(flushInterval)
.withMaxQueueSize(maxQueueSize).withMetrics(new Metrics(metricsFactory)).build();
RemoteReporter reporter2 = new RemoteReporter.Builder()
.withSender(senderConfiguration.withEndpoint("http://localhost:14268/api/traces").getSender())
.withFlushInterval(flushInterval)
.withMaxQueueSize(maxQueueSize).withMetrics(new Metrics(metricsFactory)).build();

reporters.add(reporter1);
reporters.add(reporter2);

reporter = new CompositeReporter(reporters.toArray(new Reporter[reporters.size()]));

System.out.println("Reporter reporter : " + reporter.toString());
final JaegerTracer.Builder builder = new JaegerTracer.Builder(serviceName).withReporter(reporter)
.withSampler(sampler);

return builder.build();
}

/// Generating Trace and Span object code
 JaegerSpan span = null;
 JaegerTracer tracer = jaegerTracer();
try {
JaegerSpanContext parentSpanCtx = tracer.extract(Format.Builtin.HTTP_HEADERS, new TextMapAdapter(headers));

if (parentSpanCtx == null) {
span = tracer.buildSpan(request.getRequestURI()).start();
} else {
span = tracer.buildSpan(request.getRequestURI()).asChildOf(parentSpanCtx).start();
}
} catch (IllegalArgumentException e) {
//span = tracer.buildSpan(request.getRequestURI()).start();
}
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_SERVER);
Tags.HTTP_METHOD.set(span, request.getMethod());
Tags.HTTP_URL.set(span, requestUri);


span.finish();
reporter.close();


Thanks
Aruna

Bikramjit Naha

unread,
Mar 30, 2021, 4:40:38 AM3/30/21
to Arun Kumar, Jaeger Tracing
Ok with the above code shared by Aruna it is working now. The issue was were using an older version of dependency in pom.xml....thanks all


You received this message because you are subscribed to a topic in the Google Groups "Jaeger Tracing" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jaeger-tracing/Yo014mv_baQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jaeger-tracin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jaeger-tracing/ef96b6af-6f44-4d84-9875-5ae8b623e686n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages