eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – LJB – NPI EA (cat = Core Java)
announcement - icon

Code your way through and build up a solid, practical foundation of Java:

>> Learn Java Basics

1. Introduction

Apache Camel is a Java-based integration framework that implements Enterprise Integration Patterns (EIPs).

In this article, we’ll demonstrate how to use Apache Camel observability-related components to monitor application health and performance.

2. Maven Dependencies

The two variants of this application, Spring Boot and Standalone, send spans and traces by utilizing different tools. To that end, it’s crucial to present the dependency lists separately.

2.1. Spring Boot

To start, for the Spring Boot examples, we need to define the dependencies for spring-boot-starter, camel-spring-boot-starter, spring-boot-starter-actuator, camel-observation-starter, micrometer, and zipkin:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <version>3.5.11</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>3.5.11</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel.springboot</groupId>
        <artifactId>camel-spring-boot-starter</artifactId>
        <version>4.18.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
        <version>3.5.11</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-actuator-autoconfigure</artifactId>
        <version>3.5.11</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel.springboot</groupId>
        <artifactId>camel-observation-starter</artifactId>
        <version>4.18.0</version>
    </dependency>

    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-tracing</artifactId>
        <version>1.5.0</version>
    </dependency>
    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-tracing-bridge-brave</artifactId>
        <version>1.5.0</version>
    </dependency>
    <dependency>
        <groupId>io.zipkin.reporter2</groupId>
        <artifactId>zipkin-reporter-brave</artifactId>
    </dependency>
    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-registry-prometheus</artifactId>
        <version>1.5.0</version>
    </dependency>

    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-core</artifactId>
        <version>1.15.9</version>
    </dependency>

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-core</artifactId>
        <version>1.5.32</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.5.32</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

For the Spring Boot variant, the application generates observations using Micrometer, which the micrometer-tracing-bridge-brave transforms to Brave spans. The zipkin-reporter-brave then sends the transformed spans to the Zipkin backend, which is Jaeger in our case. Finally, the spring-boot-actuator-autoconfigure dependency binds everything together by configuring and instantiating the components that send the spans to Jaeger.

2.2. Camel Standalone

Likewise, for the Camel Standalone application monitoring, we need camel-core, camel-main, camel-observability-services, and camel-opentelemetry2:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-core</artifactId>
    <version>4.17.0</version>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-main</artifactId>
    <version>4.17.0</version>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-observability-services</artifactId>
    <version>4.17.0</version>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-opentelemetry2</artifactId>
    <version>4.17.0</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.5.29</version>
    <scope>compile</scope>
</dependency>

In this version, the camel-observability-services dependency provides preconfigured components for exporting traces and health metrics. In the examples, we employ the OpenTelemetry Java agent to send the traces to Jaeger.

3. Application Under Monitoring

Now, let’s ensure we have a subject for the observations. To begin with, we create an application that reads XML files from a directory, processes them by adding the current timestamp, and copies them to another directory.

In a Camel application, Routes define how data is processed, and the RouteBuilder interface enables us to configure the application routes using Java-DSL. Before we create the RouteBuilder, let’s write the SimpleProcessor, which gets utilized by the RouteBuilder, and is identical for both application variants:

public class SimpleProcessor implements Processor {

    private static final DocumentBuilderFactory factory = DocumentBuilderFactory.newDefaultInstance();

    @Override
    public void process(Exchange exchange) throws Exception {
        String body = exchange.getMessage().getBody(String.class);
        String processedAt = LocalDateTime.now().toString();
        InputStream stream = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8));
        Document document = factory.newDocumentBuilder().parse(stream);
        Element root = document.getDocumentElement();
        Element newElemeent = document.createElement("processed");
        newElemeent.setTextContent(processedAt);
        root.appendChild(newElemeent);
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        StringWriter stringWriter = new StringWriter();
        transformer.transform(new DOMSource(document), new StreamResult(stringWriter));
        String newBody = stringWriter.toString();
        exchange.getMessage().setBody(newBody);
    }
}

With the processor in place, it’s now time to write the RouteBuilder component, which is almost the same for both Spring Boot and Standalone applications, except for the dependency injection code. Moreover, the Spring Boot RouteBuilder, named SimpleRouteBuilder, uses the constructor injection approach:

public class SimpleRouteBuilder extends RouteBuilder {

    private final SimpleProcessor simpleProcessor;

    @Autowired
    public SimpleRouteBuilder(SimpleProcessor simpleProcessor) {
        this.simpleProcessor = simpleProcessor;
    }

    public void configure() {
        from("file://src/data?noop=true")
          .choice()
          .when(xpath("/person/city = 'London'"))
            .log("UK message")
            .to("file:target/messages/uk")
            .log("UK message 2")
            .process(simpleProcessor)
            .to("file:target/messages/general-sink")
          .otherwise()
            .log("Other message")
            .to("file:target/messages/others")
            .log("Other message 2")
            .process(simpleProcessor)
            .to("file:target/messages/general-sink");
    }

}

For the Standalone application RouteBuilder, we use the @BeanInject annotation, which injects a registered component from the Camel Registry:

public class SimpleRouteBuilder extends RouteBuilder {

    @BeanInject("SimpleProcessor")
    SimpleProcessor simpleProcessor;

// the rest of the file is the same as the Spring Boot SimpleRouteBuilder

Finally, we implement the application that combines all the moving parts. Let’s start by writing the @SpringBootApplication annotated main class:

@CamelObservation
@SpringBootApplication
public class CamelSpringBootApplication {

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

	@Bean
	SimpleProcessor simpleProcessor() {
	    return new SimpleProcessor();
	}

	@Bean
	SimpleRouteBuilder simpleRouteBuilder(SimpleProcessor simpleProcessor) {
	    return new SimpleRouteBuilder(simpleProcessor);
	}

}

The CamelSpringBootApplication is annotated with the @CamelObservation annotation and defines the required Spring beans. Additionally, the @CamelObservation annotation, which is included in the camel-observation-starter dependency, configures Micrometer Observation to generate metrics and traces for Camel routes.

Similarly, in the Standalone application that we called MainApp, we configure the Camel context using SimpleRouteBuilder and SimpleProcessor:

public class MainApp {

    public static void main(String... args) throws Exception {
        Main main = new Main();
        main.configure().addRoutesBuilder(new SimpleRouteBuilder());
        main.bind("SimpleProcessor", new SimpleProcessor());
        main.run(args);
    }

}

Furthermore, to execute the MainApp.main() method, we configure the camel-maven-plugin:

<plugin>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-maven-plugin</artifactId>
    <version>3.18.4</version>
    <configuration>
        <logClasspath>true</logClasspath>
        <mainClass>com.baeldung.camel.observability.MainApp</mainClass>
    </configuration>
</plugin>

Indeed, camel-maven-plugin enables us to start the Camel Standalone application by executing a simple mvn command:

mvn camel:run

Also, let’s enable opentelemetry2 components via config properties in the application.yml:

camel:
  opentelemetry2:
    enabled: true
    trace-processors: true
    trace-headers-inclusion: true

Lastly, to ensure that every application interaction gets reported, sampling probability needs tweaking as well:

management:
  tracing:
    sampling:
      probability: 1.0

On the other hand, the Standalone variant requires only the opentelemetry2 enablement:

camel.opentelemetry2.enabled=true

Thus, we should be ready for monitoring.

4. Monitoring Setup and Presentation

Conveniently, we monitor traces on the Jaeger server for both application variants.

4.1. Jaeger Deployment

Let’s deploy the Jaeger server as a Docker container:

docker run --name jaeger -p 16686:16686 -p 4317:4317 -p 4318:4318 -p 5778:5778 -p 9411:9411 cr.jaegertracing.io/jaegertracing/jaeger:2.15.0

This way, we can have a ready deployment without the hassle of manual setup.

4.2. Spring Boot

There are no additional steps needed for the Spring Boot application monitoring, so let’s start the application:

mvn spring-boot:run

Now, it’s time to navigate to Jaeger’s dashboard to find the traces. The dashboard URL is http://localhost:16686. To find the relevant traces, we use the application name as a service filter and file as the operation filter:

Jaeger Dashboard Overview

 

Subsequently, by clicking and expanding the first trace, we can inspect its contents in detail:

Parent Trace Details

 

The nested spans contain the individual file operations:

Detailed Span Information

 

Once again, it’s important to mention that all this functionality is the out-of-the-box behavior of the dependencies we’ve used.

4.2. Standalone

To enable tracing for the Standalone application, let’s use a slightly different mvn command, so that the opentelemetry-java agent sends traces to Jaeger:

MAVEN_OPTS="-javaagent:path/to/opentelemetry-javaagent.jar -Dotel.service.name=camel-standalone" mvn camel:run

In the Jaeger dashboard, we use the Camel Standalone application name as a value for the service filter:

Jaeger Dashboard for Camel Standalone

 

As expected, the span contents for the Camel Standalone application are no different from the Spring Boot application spans.

5. Conclusion

In this article, we demonstrated how to configure a Camel application to generate and send traces to a Jaeger server.

Specifically, we provided examples for both Spring Boot and Camel Standalone applications to ensure a good comparison between the two variants.

In summary, with the proper setup and regardless of the application architecture, using Apache Camel is a fairly straightforward way to monitor an application.

Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – LS – NPI (cat=Java)
announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

eBook Jackson – NPI EA – 3 (cat = Jackson)