Skip to content

Commit e540811

Browse files
authored
Fix Spring Boot OpenTelemetry example (#50)
Signed-off-by: Jeremy Parr-Pearson <jeremy.parr-pearson@improving.com>
1 parent b80893f commit e540811

9 files changed

Lines changed: 43 additions & 23 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This project provides both the [core Spring Data Valkey library](spring-data-val
1111
* Connection package as low-level abstraction across multiple drivers ([Valkey GLIDE](https://github.com/valkey-io/valkey-glide), [Lettuce](https://github.com/lettuce-io/lettuce-core), and [Jedis](https://github.com/redis/jedis)).
1212
* Exception translation to Spring's portable Data Access exception hierarchy for driver exceptions.
1313
* `ValkeyTemplate` that provides a high level abstraction for performing various Valkey operations, exception translation and serialization support.
14-
* Pubsub support (such as a MessageListenerContainer for message-driven POJOs). Available with Jedis and Lettuce, with Valkey GLIDE support WIP for version 1.0.0.
14+
* Pubsub support (such as a MessageListenerContainer for message-driven POJOs).
1515
* OpenTelemetry instrumentation support when using the Valkey GLIDE client for emitting traces and metrics for Valkey operations.
1616
* Valkey Sentinel support is currently available in Jedis and Lettuce, while support in Valkey GLIDE is planned for a future release.
1717
* Reactive API using Lettuce.
@@ -30,10 +30,10 @@ This project provides both the [core Spring Data Valkey library](spring-data-val
3030
* Support for multiple Valkey drivers ([Valkey GLIDE](https://github.com/valkey-io/valkey-glide), [Lettuce](https://github.com/lettuce-io/lettuce-core), and [Jedis](https://github.com/redis/jedis)).
3131
* Connection pooling configuration for all supported clients.
3232
* Valkey Cluster auto-configuration and support.
33-
* Property-based OpenTelemetry configuration for Valkey GLIDE, enabling automatic trace and metric export without application code changes.
3433
* Valkey Sentinel configuration support (Lettuce and Jedis only).
3534
* SSL/TLS connection support with Spring Boot SSL bundles.
3635
* Spring Boot Actuator health indicators and metrics for Valkey connections.
36+
* Property-based OpenTelemetry configuration for Valkey GLIDE, enabling automatic trace and metric export without application code changes.
3737
* `@DataValkeyTest` slice test annotation for focused Valkey testing.
3838
* Testcontainers integration with `@ServiceConnection` annotation.
3939
* Docker Compose support for automatic service detection and startup.

examples/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Replace `quickstart` with any example name below. To run from project root, use
3939
| **streams** | Valkey Streams for event sourcing and message queues (XADD, XREAD, consumer groups) |
4040
| **collections** | Valkey-backed Java collections (ValkeyList, ValkeySet, ValkeyMap) and atomic counters |
4141
| **scripting** | Lua script execution (EVAL, EVALSHA) for atomic operations |
42+
| **telemetry** | OpenTelemetry instrumentation with manual SDK setup for tracing and metrics |
43+
| **boot-telemetry** | Spring Boot with OpenTelemetry enabled via configuration properties and Docker Compose |
4244

4345
## Notes
4446

examples/boot-telemetry/README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ This example demonstrates using **Spring Boot** with **Spring Data Valkey**, bac
44

55
On startup, the application executes a small number of Valkey `SET` / `GET` commands using `StringValkeyTemplate`. Each command is automatically instrumented by GLIDE and exported via OpenTelemetry.
66

7-
---
8-
97
## How it works
108

119
- Spring Boot auto-configures all Valkey beans
@@ -16,17 +14,28 @@ On startup, the application executes a small number of Valkey `SET` / `GET` comm
1614

1715
No explicit OpenTelemetry SDK or client setup code is required.
1816

19-
---
20-
2117
## Running the example
2218

19+
From the project root:
20+
2321
```bash
24-
../../mvnw clean compile exec:java
25-
````
22+
$ ./mvnw -q compile exec:java -pl examples/boot-telemetry
23+
```
24+
25+
Or from this boot-telemetry folder:
26+
27+
```bash
28+
$ ../../mvnw -q compile exec:java -Dspring.docker.compose.file=compose.yaml
29+
```
2630

2731
Docker Compose is started automatically and kept running after the application exits.
2832

29-
---
33+
When finished, stop and remove the container:
34+
35+
```bash
36+
$ docker stop boot-telemetry-otel-collector-1 && docker rm boot-telemetry-otel-collector-1
37+
```
38+
3039

3140
## Key configuration properties
3241

@@ -40,16 +49,14 @@ spring.data.valkey.valkey-glide.open-telemetry.metrics-endpoint=http://localhost
4049
spring.docker.compose.lifecycle-management=start-only
4150
```
4251

43-
---
44-
4552
## Inspecting OpenTelemetry
4653

4754
```bash
48-
docker logs -f spring-boot-opentelemetry-otel-collector-1
55+
$ docker logs -f boot-telemetry-otel-collector-1
4956
```
5057

51-
If yoy change the configuration of the docker shutdown the existing containers first and then run the example again:
58+
If you change the configuration of the docker shutdown the existing containers first and then run the example again:
5259

5360
```bash
54-
docker compose down --remove-orphans
61+
$ docker compose down --remove-orphans
5562
```

examples/boot-telemetry/src/main/java/example/springboot/SpringBootTelemetryExample.java renamed to examples/boot-telemetry/src/main/java/example/boottelemetry/SpringBootTelemetryExample.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* for example by viewing the collector logs:</p>
2020
*
2121
* <pre>
22-
* docker logs -f spring-boot-opentelemetry-otel-collector-1
22+
* docker logs -f boot-telemetry-otel-collector-1
2323
* </pre>
2424
*/
2525
@SpringBootApplication
@@ -43,10 +43,14 @@ public void run(String... args) {
4343

4444
valkeyTemplate.opsForValue().set(key, value);
4545
String readBack = valkeyTemplate.opsForValue().get(key);
46-
47-
// System.out.println("Iteration " + i + ": " + key + "=" + readBack);
46+
System.out.println("Iteration " + i + ": " + key + "=" + readBack);
4847
}
4948

5049
System.out.println("Completed " + iterations + " iterations of Valkey commands.");
50+
51+
// Cleanup
52+
for (int i = 0; i < iterations; i++) {
53+
valkeyTemplate.delete("key" + i);
54+
}
5155
}
5256
}

examples/boot-telemetry/src/main/resources/application.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ spring.data.valkey.host=localhost
22
spring.data.valkey.port=6379
33
spring.data.valkey.client-type=valkeyglide
44

5+
# Docker Compose configuration
6+
spring.docker.compose.file=examples/boot-telemetry/compose.yaml
57
# Keep the Docker Compose services running after the example stops
68
# Provide the option to inspect the services if needed
79
# Run `docker logs -f spring-boot-opentelemetry-otel-collector-1` to see the OpenTelemetry Collector logs
@@ -13,4 +15,4 @@ spring.data.valkey.valkey-glide.open-telemetry.enabled=true
1315
spring.data.valkey.valkey-glide.open-telemetry.traces-endpoint=http://localhost:4318/v1/traces
1416
spring.data.valkey.valkey-glide.open-telemetry.metrics-endpoint=http://localhost:4318/v1/metrics
1517
spring.data.valkey.valkey-glide.open-telemetry.sample-percentage=10
16-
spring.data.valkey.valkey-glide.open-telemetry.flush-interval-ms=1000
18+
spring.data.valkey.valkey-glide.open-telemetry.flush-interval-ms=50

examples/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
<description>Example projects demonstrating Spring Data Valkey features</description>
1919

2020
<modules>
21+
<module>boot-telemetry</module>
2122
<module>cache</module>
2223
<module>cluster</module>
2324
<module>collections</module>
24-
<module>telemetry</module>
2525
<module>operations</module>
2626
<module>pipeline</module>
2727
<module>quickstart</module>
@@ -30,6 +30,7 @@
3030
<module>serialization</module>
3131
<module>spring-boot</module>
3232
<module>streams</module>
33+
<module>telemetry</module>
3334
<module>transactions</module>
3435
</modules>
3536

examples/telemetry/src/main/java/example/telemetry/OpenTelemetryExample.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* for example by viewing the collector logs:</p>
3535
*
3636
* <pre>
37-
* docker logs -f spring-boot-opentelemetry-otel-collector-1
37+
* docker logs -f boot-telemetry-otel-collector-1
3838
* </pre>
3939
*/
4040
public class OpenTelemetryExample {
@@ -70,12 +70,15 @@ public static void main(String[] args) {
7070

7171
template.opsForValue().set(key, value);
7272
String readBack = template.opsForValue().get(key);
73-
74-
// System.out.println("Iteration " + i + ": " + key + "=" + readBack);
73+
System.out.println("Iteration " + i + ": " + key + "=" + readBack);
7574
}
7675

7776
System.out.println("Completed " + iterations + " iterations of Valkey commands.");
7877

78+
// Cleanup
79+
for (int i = 0; i < iterations; i++) {
80+
template.delete("key" + i);
81+
}
7982
} finally {
8083
connectionFactory.destroy();
8184
}

spring-boot-starter-data-valkey/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The project is a fork of Spring Boot Starter Data Redis 3.5.1 (part of the [Spri
1515
* Valkey Sentinel configuration support (Lettuce and Jedis only).
1616
* SSL/TLS connection support with Spring Boot SSL bundles.
1717
* Spring Boot Actuator health indicators and metrics for Valkey connections.
18+
* Property-based OpenTelemetry configuration for Valkey GLIDE, enabling automatic trace and metric export without application code changes.
1819
* `@DataValkeyTest` slice test annotation for focused Valkey testing.
1920
* Testcontainers integration with `@ServiceConnection` annotation.
2021
* Docker Compose support for automatic service detection and startup.

spring-data-valkey/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Spring Data Valkey provides Spring Data integration for [Valkey](https://valkey.
77
* Connection package as low-level abstraction across multiple drivers ([Valkey GLIDE](https://github.com/valkey-io/valkey-glide), [Lettuce](https://github.com/lettuce-io/lettuce-core), and [Jedis](https://github.com/redis/jedis))
88
* Exception translation to Spring's portable Data Access exception hierarchy
99
* `ValkeyTemplate` for high-level abstraction with serialization support
10-
* Pubsub support with MessageListenerContainer (Jedis and Lettuce, GLIDE support planned)
10+
* Pubsub support with MessageListenerContainer
1111
* Valkey Sentinel support (Jedis and Lettuce, GLIDE support planned)
1212
* Reactive API using Lettuce
1313
* JDK, String, JSON and Spring Object/XML mapping serializers

0 commit comments

Comments
 (0)