Skip to content

Commit 8c8a736

Browse files
committed
add example for spring with declarative config
1 parent d8b3a7b commit 8c8a736

13 files changed

Lines changed: 202 additions & 0 deletions

File tree

.github/renovate.json5

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@
4040
"matchUpdateTypes": ["major"],
4141
"enabled": false
4242
},
43+
{
44+
// Spring starter doesn't support Spring Boot 4 yet
45+
"matchPackageNames": ["org.springframework.boot"],
46+
"matchFilePatterns": [
47+
"spring-declarative-configuration/build.gradle.kts"
48+
],
49+
"matchUpdateTypes": ["major"],
50+
"enabled": false
51+
},
4352
{
4453
// Skip locally built dice image used in logging-k8s-stdout-otlp-json
4554
"matchManagers": ["kubernetes"],

.github/workflows/oats-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- .mise/tasks/oats-tests.sh
1111
- 'logging-k8s-stdout-otlp-json/**'
1212
- 'javaagent-declarative-configuration/**'
13+
- 'spring-declarative-configuration/**'
1314
- 'doc-snippets/extensions-minimal/**'
1415
workflow_dispatch:
1516

.mise/tasks/oats-tests.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@ pushd javaagent-declarative-configuration
1111
../gradlew clean bootJar
1212
popd
1313

14+
pushd spring-declarative-configuration
15+
../gradlew clean bootJar
16+
popd
17+
1418
oats -timeout 5m logging-k8s-stdout-otlp-json/
1519
oats -timeout 5m javaagent-declarative-configuration/oats/
20+
oats -timeout 5m spring-declarative-configuration/oats/

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ To build the all of examples, run:
8686
OpenTelemetry SDK to use a Zipkin exporter and send spans to a
8787
Zipkin backend using the OpenTelemetry API.
8888
- Note: This example requires Docker to be installed.
89+
- [Declarative Configuration with the OpenTelemetry Java Agent](javaagent-declarative-configuration)
90+
- This module demonstrates how to use declarative configuration with the
91+
OpenTelemetry Java Agent to configure tracing behavior, including
92+
excluding specific endpoints from tracing.
93+
- Note: This example requires Java 17 or higher.
94+
- [Declarative Configuration with the OpenTelemetry Spring Boot Starter](spring-declarative-configuration)
95+
- This module demonstrates how to use declarative configuration with the
96+
OpenTelemetry Spring Boot Starter to configure tracing behavior,
97+
including excluding specific endpoints from tracing.
98+
- Note: This example requires Java 17 or higher.
8999

90100
## Contributing
91101

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ include(
7171
":opentelemetry-examples-telemetry-testing",
7272
":opentelemetry-examples-zipkin",
7373
":opentelemetry-examples-spring-native",
74+
":opentelemetry-examples-spring-declarative-configuration",
7475
":opentelemetry-examples-kotlin-extension",
7576
":opentelemetry-examples-grpc",
7677
":opentelemetry-examples-resource-detection-gcp",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import org.gradle.kotlin.dsl.named
2+
import org.springframework.boot.gradle.plugin.SpringBootPlugin
3+
import org.springframework.boot.gradle.tasks.bundling.BootJar
4+
5+
plugins {
6+
id("java")
7+
id("org.springframework.boot") version "3.5.7"
8+
}
9+
10+
description = "OpenTelemetry Example for Spring Boot with Declarative Configuration"
11+
12+
java {
13+
toolchain {
14+
languageVersion.set(JavaLanguageVersion.of(17))
15+
}
16+
}
17+
18+
dependencies {
19+
implementation(platform(SpringBootPlugin.BOM_COORDINATES))
20+
implementation(platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:2.22.0"))
21+
implementation("org.springframework.boot:spring-boot-starter-actuator")
22+
implementation("org.springframework.boot:spring-boot-starter-web")
23+
implementation("io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter")
24+
}
25+
26+
tasks.named<BootJar>("bootJar") {
27+
archiveFileName = "spring-declarative-configuration.jar"
28+
}
29+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM eclipse-temurin:21.0.9_10-jre@sha256:4332b7939ba5b7fabde48f4da21ebe45a4f8943d5b3319720c321ac577e65fb1
2+
3+
WORKDIR /usr/src/app/
4+
5+
ADD ./build/libs/spring-declarative-configuration.jar ./app.jar
6+
7+
EXPOSE 8080
8+
ENTRYPOINT [ "java", "-jar", "./app.jar" ]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: '3'
2+
services:
3+
app:
4+
build:
5+
context: ../
6+
dockerfile: oats/Dockerfile
7+
environment:
8+
SPRING_OTEL_EXPORTER_OTLP_ENDPOINT: http://lgtm:4318
9+
ports:
10+
- "8080:8080"
11+
healthcheck:
12+
test: ["CMD", "curl", "-f", "http://localhost:8080/actuator/health"]
13+
interval: 10s
14+
timeout: 5s
15+
retries: 3
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# OATS is an acceptance testing framework for OpenTelemetry - https://github.com/grafana/oats
2+
3+
docker-compose:
4+
files:
5+
- ./docker-compose.yml
6+
app-service: app
7+
app-docker-tag: javaagent-declarative-config:latest
8+
app-docker-port: 8080
9+
10+
input:
11+
# This endpoint should be traced normally
12+
- path: /api/example
13+
# This endpoint should NOT be traced (excluded by declarative config)
14+
# We send the request but don't assert spans for it - the absence of spans
15+
# for /actuator/health demonstrates the sampling rule is working
16+
- path: /actuator/health
17+
18+
expected:
19+
traces:
20+
# Verify that /api/example creates a trace with SERVER span
21+
- traceql: '{ span.http.route = "/api/example" }'
22+
spans:
23+
- name: "GET /api/example"
24+
attributes:
25+
http.request.method: "GET"
26+
http.route: "/api/example"

0 commit comments

Comments
 (0)