Skip to content

Commit 2879bbe

Browse files
mcarlettCroway
authored andcommitted
Adds observability-services example
1 parent 4b4a617 commit 2879bbe

File tree

10 files changed

+423
-1
lines changed

10 files changed

+423
-1
lines changed

README.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ readme's instructions.
2727
=== Examples
2828

2929
// examples: START
30-
Number of Examples: 66 (0 deprecated)
30+
Number of Examples: 67 (0 deprecated)
3131

3232
[width="100%",cols="4,2,4",options="header"]
3333
|===
@@ -168,6 +168,8 @@ Number of Examples: 66 (0 deprecated)
168168
| link:salesforce/README.adoc[Salesforce] (salesforce) | SaaS | How to work with Salesforce contacts using REST endpoints and Streaming API
169169

170170
| link:twitter-salesforce/README.adoc[Twitter Salesforce] (twitter-salesforce) | SaaS | Twitter mentions is created as contacts in Salesforce
171+
172+
| link:observability-services/README.adoc[Observability Services] | Management and Monitoring | An example showing how to use Camel with Observability Services
171173
|===
172174
// examples: END
173175

observability-services/README.adoc

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
== Spring Boot Example with Camel Observability Services
2+
3+
=== Introduction
4+
5+
This example illustrates how to use https://projects.spring.io/spring-boot/[Spring Boot] with http://camel.apache.org[Camel] to demonstrate observability capabilities. It implements a REST service that generates random numbers with variable response times, showcasing distributed tracing, metrics collection, and monitoring through OpenTelemetry.
6+
7+
The project uses `camel-observability-services-starter` component for automatic instrumentation, `camel-platform-http-starter` for REST endpoints, and integrates with OpenTelemetry Java agent for comprehensive observability.
8+
9+
For additional information there is https://camel.apache.org/blog/2025/03/camel-observability[blog post]
10+
11+
=== Observability Stack
12+
13+
To run the complete observability stack with Jaeger and Prometheus:
14+
15+
[source,bash]
16+
----
17+
docker-compose up
18+
----
19+
20+
This will start:
21+
22+
- OpenTelemetry Collector (ports 4317/4318) - collects traces and metrics
23+
- Jaeger UI (http://localhost:16686) - distributed tracing visualization
24+
- Prometheus (http://localhost:9090) - metrics collection and storage
25+
26+
The application, using agent, sends telemetry data to the OpenTelemetry Collector, which exports traces to Jaeger and metrics to Prometheus.
27+
28+
=== Run
29+
30+
You can run this example using:
31+
32+
[source,bash]
33+
----
34+
mvn spring-boot:run
35+
----
36+
37+
After the Spring Boot application is started, you can execute the following HTTP requests:
38+
39+
[source,bash]
40+
----
41+
curl http://localhost:8080/api/random
42+
----
43+
44+
The command will call the random number generator endpoint. Each call will:
45+
- Generate a random number between 1-1000
46+
- Simulate a random delay between 100-2000ms
47+
- Return the number as response body
48+
- Create traces and metrics for observability
49+
50+
You should see output similar to:
51+
52+
----
53+
INFO 101511 --- [ task-1] generate-random-number : Generated random number: 742 with delay: 1250ms
54+
----
55+
56+
=== Exposed Observability endpoints
57+
58+
The `camel-observability-services-starter` will configure the application and overrides the actuator setup so the health and metrics (in prometheus format) endpoints will be
59+
60+
```
61+
http://localhost:9876/observe/health
62+
63+
http://localhost:9876/observe/metrics
64+
```
65+
66+
even if in this example the metrics will be distributed using OpenTelemetry agent and not scraping the `/observe/metrics` endpoint
67+
68+
=== Testing Observability
69+
70+
1. **Generate some traffic:**
71+
[source,bash]
72+
----
73+
for i in {1..10}; do curl http://localhost:8080/api/random; echo; sleep 1; done
74+
----
75+
76+
2. **View traces in Jaeger:**
77+
- Open http://localhost:16686
78+
- Select service and search for traces
79+
80+
3. **View metrics in Prometheus:**
81+
- Open http://localhost:9090
82+
- Query metrics like `camel_route_exchange_completed_total`
83+
84+
85+
The Spring Boot application can be stopped pressing `[CTRL] + [C]` in the shell.
86+
87+
=== Help and contributions
88+
89+
If you hit any problem using Camel or have some feedback, then please
90+
https://camel.apache.org/community/support/[let us know].
91+
92+
We also love contributors, so
93+
https://camel.apache.org/community/contributing/[get involved] :-)
94+
95+
The Camel riders!
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
version: "3.9"
2+
3+
services:
4+
5+
otel-collector:
6+
image: otel/opentelemetry-collector:latest
7+
command:
8+
- --config=/etc/otelcol-cont/otel-collector.yml
9+
volumes:
10+
- ./otel-collector.yml:/etc/otelcol-cont/otel-collector.yml
11+
ports:
12+
- "4318:4318" # OTLP http receiver
13+
- "4317:4317" # OTLP grpc receiver
14+
depends_on:
15+
- jaeger-all-in-one
16+
- prometheus
17+
18+
jaeger-all-in-one:
19+
image: quay.io/jaegertracing/all-in-one:latest
20+
restart: always
21+
ports:
22+
- "16686:16686"
23+
24+
prometheus:
25+
image: prom/prometheus:latest
26+
container_name: prometheus
27+
restart: always
28+
ports:
29+
- "9090:9090"
30+
volumes:
31+
- ./prometheus.yml:/etc/prometheus/prometheus.yml
32+
command:
33+
- '--config.file=/etc/prometheus/prometheus.yml'
34+
- '--storage.tsdb.path=/prometheus'
35+
- '--web.console.libraries=/etc/prometheus/console_libraries'
36+
- '--web.console.templates=/etc/prometheus/consoles'
37+
- '--storage.tsdb.retention.time=200h'
38+
- '--web.enable-lifecycle'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
receivers:
2+
otlp:
3+
protocols:
4+
grpc:
5+
endpoint: 0.0.0.0:4317
6+
http:
7+
endpoint: 0.0.0.0:4318
8+
9+
processors:
10+
batch:
11+
12+
exporters:
13+
debug:
14+
verbosity: detailed
15+
otlp/jaeger:
16+
endpoint: jaeger-all-in-one:4317
17+
tls:
18+
insecure: true
19+
prometheus:
20+
endpoint: "0.0.0.0:8889"
21+
22+
service:
23+
pipelines:
24+
traces:
25+
receivers: [otlp]
26+
processors: [batch]
27+
exporters: [debug,otlp/jaeger]
28+
metrics:
29+
receivers: [otlp]
30+
processors: [batch]
31+
exporters: [debug,prometheus]

observability-services/pom.xml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one or more
5+
contributor license agreements. See the NOTICE file distributed with
6+
this work for additional information regarding copyright ownership.
7+
The ASF licenses this file to You under the Apache License, Version 2.0
8+
(the "License"); you may not use this file except in compliance with
9+
the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
22+
<modelVersion>4.0.0</modelVersion>
23+
24+
<parent>
25+
<groupId>org.apache.camel.springboot.example</groupId>
26+
<artifactId>examples</artifactId>
27+
<version>4.15.0-SNAPSHOT</version>
28+
</parent>
29+
30+
<artifactId>camel-example-spring-boot-observability-services</artifactId>
31+
<name>Camel SB Examples :: Observability Services</name>
32+
<description>This example shows how to work with Apache Camel observability services using Spring Boot</description>
33+
34+
<properties>
35+
<category>Management and Monitoring</category>
36+
<opentelemetry-agent.version>2.19.0</opentelemetry-agent.version>
37+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
38+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
39+
</properties>
40+
41+
<dependencyManagement>
42+
<dependencies>
43+
<!-- Camel BOM -->
44+
<dependency>
45+
<groupId>org.apache.camel.springboot</groupId>
46+
<artifactId>camel-spring-boot-bom</artifactId>
47+
<version>${project.version}</version>
48+
<type>pom</type>
49+
<scope>import</scope>
50+
</dependency>
51+
<!-- Spring Boot BOM -->
52+
<dependency>
53+
<groupId>org.springframework.boot</groupId>
54+
<artifactId>spring-boot-dependencies</artifactId>
55+
<version>${spring-boot-version}</version>
56+
<type>pom</type>
57+
<scope>import</scope>
58+
</dependency>
59+
</dependencies>
60+
</dependencyManagement>
61+
62+
<dependencies>
63+
<!-- spring-boot -->
64+
<dependency>
65+
<groupId>org.springframework.boot</groupId>
66+
<artifactId>spring-boot-starter</artifactId>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.springframework.boot</groupId>
70+
<artifactId>spring-boot-starter-web</artifactId>
71+
</dependency>
72+
<dependency>
73+
<groupId>org.springframework.boot</groupId>
74+
<artifactId>spring-boot-starter-actuator</artifactId>
75+
</dependency>
76+
77+
<!-- Camel -->
78+
<dependency>
79+
<groupId>org.apache.camel.springboot</groupId>
80+
<artifactId>camel-spring-boot-starter</artifactId>
81+
</dependency>
82+
<dependency>
83+
<groupId>org.apache.camel.springboot</groupId>
84+
<artifactId>camel-observability-services-starter</artifactId>
85+
</dependency>
86+
<dependency>
87+
<groupId>org.apache.camel.springboot</groupId>
88+
<artifactId>camel-platform-http-starter</artifactId>
89+
</dependency>
90+
91+
</dependencies>
92+
93+
<build>
94+
<plugins>
95+
<plugin>
96+
<groupId>org.apache.maven.plugins</groupId>
97+
<artifactId>maven-dependency-plugin</artifactId>
98+
<executions>
99+
<execution>
100+
<id>copy-javaagent</id>
101+
<phase>process-resources</phase>
102+
<goals>
103+
<goal>copy</goal>
104+
</goals>
105+
<configuration>
106+
<artifactItems>
107+
<artifactItem>
108+
<groupId>io.opentelemetry.javaagent</groupId>
109+
<artifactId>opentelemetry-javaagent</artifactId>
110+
<version>${opentelemetry-agent.version}</version>
111+
<overWrite>true</overWrite>
112+
<outputDirectory>${project.build.directory}/javaagents</outputDirectory>
113+
<destFileName>javaagent.jar</destFileName>
114+
</artifactItem>
115+
</artifactItems>
116+
</configuration>
117+
</execution>
118+
</executions>
119+
</plugin>
120+
<plugin>
121+
<groupId>org.springframework.boot</groupId>
122+
<artifactId>spring-boot-maven-plugin</artifactId>
123+
<version>${spring-boot-version}</version>
124+
<configuration>
125+
<agents>
126+
<agent>${project.build.directory}/javaagents/javaagent.jar</agent>
127+
</agents>
128+
<environmentVariables>
129+
<OTEL_LOGS_EXPORTER>none</OTEL_LOGS_EXPORTER>
130+
<OTEL_SERVICE_NAME>camel-observability-services</OTEL_SERVICE_NAME>
131+
<OTEL_JMX_TARGET_SYSTEM>camel</OTEL_JMX_TARGET_SYSTEM>
132+
</environmentVariables>
133+
</configuration>
134+
<executions>
135+
<execution>
136+
<goals>
137+
<goal>repackage</goal>
138+
</goals>
139+
</execution>
140+
</executions>
141+
</plugin>
142+
</plugins>
143+
</build>
144+
145+
</project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
global:
2+
scrape_interval: 15s
3+
evaluation_interval: 15s
4+
5+
scrape_configs:
6+
- job_name: 'otel-collector'
7+
static_configs:
8+
- targets: ['otel-collector:8889']
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.camel.example.observability;
18+
19+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.boot.autoconfigure.SpringBootApplication;
21+
22+
//CHECKSTYLE:OFF
23+
@SpringBootApplication
24+
public class CamelObservabilityApplication {
25+
26+
public static void main(String[] args) {
27+
SpringApplication.run(CamelObservabilityApplication.class, args);
28+
}
29+
}
30+
// CHECKSTYLE:ON

0 commit comments

Comments
 (0)