-
Notifications
You must be signed in to change notification settings - Fork 6
useOpenTelemetry and OpenTelemetry config inside the configuration #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Spring Boot + Valkey-GLIDE + OpenTelemetry | ||
|
|
||
| This example demonstrates using **Spring Boot** with **Spring Data Valkey**, backed by the **Valkey-GLIDE** client, with **OpenTelemetry tracing and metrics enabled via configuration**. | ||
|
|
||
| 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. | ||
|
|
||
| --- | ||
|
|
||
| ## How it works | ||
|
|
||
| - Spring Boot auto-configures all Valkey beans | ||
| - Valkey-GLIDE is selected using `client-type=valkeyglide` | ||
| - OpenTelemetry is enabled inside GLIDE using Spring Boot properties | ||
| - An OpenTelemetry Collector is started using Docker Compose | ||
| - Traces and metrics are exported through the collector | ||
|
|
||
| No explicit OpenTelemetry SDK or client setup code is required. | ||
|
|
||
| --- | ||
|
|
||
| ## Running the example | ||
|
|
||
| ```bash | ||
| ../../mvnw clean compile exec:java | ||
| ```` | ||
|
|
||
| Docker Compose is started automatically and kept running after the application exits. | ||
|
|
||
| --- | ||
|
|
||
| ## Key configuration properties | ||
|
|
||
| ```properties | ||
| spring.data.valkey.client-type=valkeyglide | ||
|
|
||
| spring.data.valkey.valkey-glide.open-telemetry.enabled=true | ||
| spring.data.valkey.valkey-glide.open-telemetry.traces-endpoint=http://localhost:4318/v1/traces | ||
| spring.data.valkey.valkey-glide.open-telemetry.metrics-endpoint=http://localhost:4318/v1/metrics | ||
|
|
||
| spring.docker.compose.lifecycle-management=start-only | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Inspecting OpenTelemetry | ||
|
|
||
| ```bash | ||
| docker logs -f spring-boot-opentelemetry-otel-collector-1 | ||
| ``` | ||
|
|
||
| If yoy change the configuration of the docker shutdown the existing containers first and then run the example again: | ||
|
|
||
| ```bash | ||
| docker compose down --remove-orphans | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| services: | ||
|
|
||
| otel-collector: | ||
| image: otel/opentelemetry-collector-contrib:latest | ||
| command: ["--config=/etc/otelcol/config.yaml"] | ||
| volumes: | ||
| - ./otel-collector-config.yaml:/etc/otelcol/config.yaml:ro | ||
| ports: | ||
| - "4318:4318" # OTLP HTTP receiver | ||
| - "4317:4317" # OTLP gRPC receiver |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| receivers: | ||
| otlp: | ||
| protocols: | ||
| grpc: | ||
| endpoint: 0.0.0.0:4317 # OTLP gRPC endpoint | ||
| http: | ||
| endpoint: 0.0.0.0:4318 # OTLP HTTP endpoint (used by Spring Boot) | ||
|
|
||
| processors: | ||
| batch: {} # Required for efficient exporting | ||
|
|
||
| exporters: | ||
| debug: | ||
| verbosity: detailed # Optional: remove in production | ||
|
|
||
| # Uncomment the following exporters to enable AWS X-Ray and CloudWatch exporting | ||
| # awsxray: | ||
| # region: "us-east-1" # X-Ray traces | ||
|
|
||
| # awsemf: | ||
| # region: "us-east-1" | ||
| # log_group_name: "/spring/metrics" # Change to your CloudWatch log group | ||
| # namespace: "opentelemetry" # CloudWatch metrics namespace | ||
|
|
||
|
|
||
| service: | ||
| pipelines: | ||
| traces: | ||
| receivers: [otlp] | ||
| processors: [batch] | ||
| exporters: [debug] # [awsxray, debug] # Uncomment awsxray to enable X-Ray exporting | ||
|
|
||
| metrics: | ||
| receivers: [otlp] | ||
| processors: [batch] | ||
| exporters: [debug] # [awsemf, debug] # Uncomment awsemf to enable CloudWatch exporting |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <groupId>io.valkey.springframework</groupId> | ||
| <artifactId>spring-data-valkey-examples</artifactId> | ||
| <version>0.1.0</version> | ||
| </parent> | ||
|
|
||
| <artifactId>spring-data-valkey-example-boot-telemetry</artifactId> | ||
| <name>Spring Data Valkey - Spring Boot OpenTelemetry Example</name> | ||
|
|
||
| <properties> | ||
| <exec.mainClass>example.boottelemetry.SpringBootTelemetryExample</exec.mainClass> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.valkey.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-data-valkey</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-docker-compose</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <extensions> | ||
| <extension> | ||
| <groupId>kr.motd.maven</groupId> | ||
| <artifactId>os-maven-plugin</artifactId> | ||
| <version>1.7.1</version> | ||
| </extension> | ||
| </extensions> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.codehaus.mojo</groupId> | ||
| <artifactId>exec-maven-plugin</artifactId> | ||
| <configuration> | ||
| <mainClass>example.boottelemetry.SpringBootTelemetryExample</mainClass> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
52 changes: 52 additions & 0 deletions
52
examples/boot-telemetry/src/main/java/example/springboot/SpringBootTelemetryExample.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package example.boottelemetry; | ||
|
|
||
| import io.valkey.springframework.data.valkey.core.StringValkeyTemplate; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.CommandLineRunner; | ||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
|
||
| /** | ||
| * Minimal Spring Boot example that demonstrates OpenTelemetry integration | ||
| * with Valkey-GLIDE via {@link StringValkeyTemplate}. | ||
| * | ||
| * <p>This example exists to verify and showcase that Valkey commands executed | ||
| * through Spring Data Valkey automatically emit OpenTelemetry signals when | ||
| * OpenTelemetry is enabled via application properties.</p> | ||
| * | ||
| * <p>Telemetry is emitted while the application runs and Valkey commands are | ||
| * executed. Traces can be inspected via the configured OpenTelemetry backend, | ||
| * for example by viewing the collector logs:</p> | ||
| * | ||
| * <pre> | ||
| * docker logs -f spring-boot-opentelemetry-otel-collector-1 | ||
| * </pre> | ||
| */ | ||
| @SpringBootApplication | ||
| public class SpringBootTelemetryExample implements CommandLineRunner { | ||
|
|
||
| @Autowired | ||
| private StringValkeyTemplate valkeyTemplate; | ||
|
|
||
| public static void main(String[] args) { | ||
| SpringApplication.run(SpringBootTelemetryExample.class, args); | ||
| } | ||
|
|
||
| @Override | ||
| public void run(String... args) { | ||
|
|
||
| // Increase this number to generate more Valkey commands/traces | ||
| int iterations = 10; | ||
| for (int i = 0; i < iterations; i++) { | ||
| String key = "key" + i; | ||
| String value = "value" + i; | ||
|
|
||
| valkeyTemplate.opsForValue().set(key, value); | ||
| String readBack = valkeyTemplate.opsForValue().get(key); | ||
|
|
||
| // System.out.println("Iteration " + i + ": " + key + "=" + readBack); | ||
| } | ||
|
|
||
| System.out.println("Completed " + iterations + " iterations of Valkey commands."); | ||
Maayanshani25 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
16 changes: 16 additions & 0 deletions
16
examples/boot-telemetry/src/main/resources/application.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| spring.data.valkey.host=localhost | ||
| spring.data.valkey.port=6379 | ||
| spring.data.valkey.client-type=valkeyglide | ||
|
|
||
| # Keep the Docker Compose services running after the example stops | ||
| # Provide the option to inspect the services if needed | ||
| # Run `docker logs -f spring-boot-opentelemetry-otel-collector-1` to see the OpenTelemetry Collector logs | ||
| # If you changed the docker logs run `docker compose down --remove-orphans` to stop and remove the containers | ||
| spring.docker.compose.lifecycle-management=start-only | ||
|
|
||
| # Enable OpenTelemetry inside GLIDE | ||
| spring.data.valkey.valkey-glide.open-telemetry.enabled=true | ||
| spring.data.valkey.valkey-glide.open-telemetry.traces-endpoint=http://localhost:4318/v1/traces | ||
| spring.data.valkey.valkey-glide.open-telemetry.metrics-endpoint=http://localhost:4318/v1/metrics | ||
| spring.data.valkey.valkey-glide.open-telemetry.sample-percentage=10 | ||
| spring.data.valkey.valkey-glide.open-telemetry.flush-interval-ms=1000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <configuration> | ||
|
|
||
| <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> | ||
| <encoder> | ||
| <pattern>%d %5p %40.40c:%4L - %m%n</pattern> | ||
| </encoder> | ||
| </appender> | ||
|
|
||
| <logger name="io.valkey.springframework.data" level="error" /> | ||
|
|
||
| <root level="info"> | ||
| <appender-ref ref="console" /> | ||
| </root> | ||
|
|
||
| </configuration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <groupId>io.valkey.springframework</groupId> | ||
| <artifactId>spring-data-valkey-examples</artifactId> | ||
| <version>0.1.0</version> | ||
| </parent> | ||
|
|
||
| <artifactId>spring-data-valkey-example-telemetry</artifactId> | ||
| <name>Spring Data Valkey - OpenTelemetry Example</name> | ||
|
|
||
| <properties> | ||
| <exec.mainClass>example.telemetry.OpenTelemetryExample</exec.mainClass> | ||
| </properties> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.codehaus.mojo</groupId> | ||
| <artifactId>exec-maven-plugin</artifactId> | ||
| <configuration> | ||
| <mainClass>example.telemetry.OpenTelemetryExample</mainClass> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
83 changes: 83 additions & 0 deletions
83
examples/telemetry/src/main/java/example/telemetry/OpenTelemetryExample.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * Copyright 2025 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package example.telemetry; | ||
|
|
||
| import io.valkey.springframework.data.valkey.connection.ValkeyStandaloneConfiguration; | ||
| import io.valkey.springframework.data.valkey.connection.valkeyglide.ValkeyGlideClientConfiguration; | ||
| import io.valkey.springframework.data.valkey.connection.valkeyglide.ValkeyGlideClientConfiguration.OpenTelemetryForGlide; | ||
| import io.valkey.springframework.data.valkey.connection.valkeyglide.ValkeyGlideConnectionFactory; | ||
| import io.valkey.springframework.data.valkey.core.StringValkeyTemplate; | ||
|
|
||
| /** | ||
| * Minimal example that demonstrates how to enable and emit OpenTelemetry traces | ||
| * from Valkey-GLIDE using {@link StringValkeyTemplate}. | ||
| * | ||
| * <p>This example exists to validate and showcase the OpenTelemetry integration | ||
| * in Valkey-GLIDE by executing a small number of Valkey commands and exporting | ||
| * traces to an OpenTelemetry Collector.</p> | ||
| * | ||
| * <p>Telemetry is emitted while the application runs and Valkey commands are | ||
| * executed. Traces can be inspected via the configured OpenTelemetry backend, | ||
| * for example by viewing the collector logs:</p> | ||
| * | ||
| * <pre> | ||
| * docker logs -f spring-boot-opentelemetry-otel-collector-1 | ||
| * </pre> | ||
| */ | ||
| public class OpenTelemetryExample { | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| ValkeyStandaloneConfiguration standaloneConfig = | ||
| new ValkeyStandaloneConfiguration(); | ||
|
|
||
| // Change the default tracesEndpoint / metricsEndpoint if needed | ||
| OpenTelemetryForGlide openTelemetry = | ||
| OpenTelemetryForGlide.defaults(); | ||
|
|
||
| ValkeyGlideClientConfiguration clientConfig = | ||
| ValkeyGlideClientConfiguration.builder() | ||
| .useOpenTelemetry(openTelemetry) | ||
| .build(); | ||
|
|
||
| ValkeyGlideConnectionFactory connectionFactory = | ||
| new ValkeyGlideConnectionFactory(standaloneConfig, clientConfig); | ||
|
|
||
| connectionFactory.afterPropertiesSet(); | ||
|
|
||
| try { | ||
| StringValkeyTemplate template = | ||
| new StringValkeyTemplate(connectionFactory); | ||
|
|
||
| // Increase this number to generate more Valkey commands/traces | ||
| int iterations = 10; | ||
| for (int i = 0; i < iterations; i++) { | ||
| String key = "key" + i; | ||
| String value = "value" + i; | ||
|
|
||
| template.opsForValue().set(key, value); | ||
| String readBack = template.opsForValue().get(key); | ||
|
|
||
| // System.out.println("Iteration " + i + ": " + key + "=" + readBack); | ||
| } | ||
|
|
||
| System.out.println("Completed " + iterations + " iterations of Valkey commands."); | ||
|
|
||
| } finally { | ||
| connectionFactory.destroy(); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.