Rajesh Bhardwaj
Rajesh Bhardwaj

Reputation: 85

Open tracer Jaeger Trace not getting reflect for apache camel

I am new to apache camel and open tracing with Jaeger, I trying to get the traces for apache camel in Jaeger UI but its not getting captured through Open Tracing.

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.springframework.stereotype.Component;

@Component
public class RouteBuilderClient {

    public void test() throws Exception {

        DefaultCamelContext camelContext = new DefaultCamelContext();
        camelContext.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("timer:first-timer")
                        .to("log:first-timer");
            }
        });
        camelContext.start();
        camelContext.stop();

    }


}

However if if I extend the RouteBuilder class(Below is the sample code) and then I override the configure method then traces are getting generated for Apache camel. Is there any way without extending the routeBuilder I can get the traces?

import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;

@Component
public class RouteBuilderClient extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("timer:first-timer")
                .to("log:first-timer");
    }
}

My controller class:

import org.apache.camel.opentracing.starter.CamelOpenTracing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@CamelOpenTracing
public class JaegarClientApplication {

    public static void main(String[] args) {
        SpringApplication.run(JaegarClientApplication.class, args);

    }

}

Upvotes: 0

Views: 452

Answers (2)

Rajesh Bhardwaj
Rajesh Bhardwaj

Reputation: 85

Below is my code that Worked successfully.

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.opentracing.OpenTracingTracer;

public class RouteBuilderClient3 {
    public void test() throws Exception {


        RouteBuilder builder = new RouteBuilder() {
            public void configure() {
                from("timer:first-timer3").transform().constant("Rajesh client 3")
                        .to("log:first-timer3");
            }

        };
        CamelContext myCamelContext = new DefaultCamelContext();
        myCamelContext.addRoutes(builder);

        OpenTracingTracer ottracer = new OpenTracingTracer();
        ottracer.init(myCamelContext);
        myCamelContext.start();

//        myCamelContext.stop();
    }
}

Upvotes: 0

TacheDeChoco
TacheDeChoco

Reputation: 3913

Try adding this in your setup() method, before starting the Camel context:

OpenTracingTracer ottracer = new OpenTracingTracer();
ottracer.init(camelContext);

camelContext.start();

Upvotes: 1

Related Questions