Skip to content

Commit 4019099

Browse files
committed
manual review
1 parent fdc0e59 commit 4019099

File tree

1 file changed

+24
-78
lines changed

1 file changed

+24
-78
lines changed

spring-declarative-configuration/README.md

Lines changed: 24 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ Instead of using the OpenTelemetry Java Agent, this module uses the
99
[OpenTelemetry Spring Boot Starter](https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/spring/spring-boot-autoconfigure)
1010
and configures declarative behavior via standard Spring Boot configuration in `application.yaml`.
1111

12-
> **Requirement:** Declarative configuration via the Spring Boot Starter requires version **2.22.0
13-
or newer** of the
14-
> OpenTelemetry Spring Boot Starter.
15-
1612
The main configuration file for this example is:
1713

1814
- [`src/main/resources/application.yaml`](./src/main/resources/application.yaml)
@@ -21,8 +17,7 @@ For the underlying declarative configuration schema and additional examples, see
2117
[opentelemetry-configuration](https://github.com/open-telemetry/opentelemetry-configuration)
2218
repository.
2319
Remember that when you copy examples from that repository into a Spring Boot app, you must nest them
24-
under the
25-
`otel:` root node (two-space indentation for all keys shown below).
20+
under the `otel:` root node (two-space indentation for all keys shown below).
2621

2722
This Spring Boot application includes two endpoints:
2823

@@ -36,12 +31,11 @@ This Spring Boot application includes two endpoints:
3631

3732
- Java 17 or higher
3833
- OpenTelemetry Spring Boot Starter **2.22.0+** on the classpath of this application (already
39-
configured in this
40-
example’s build files)
34+
configured in this example’s [build file](./build.gradle.kts))
4135

4236
### Step 1: Build the Application
4337

44-
From the `spring-declarative-configuration` directory:
38+
From this `spring-declarative-configuration` directory:
4539

4640
```bash
4741
../gradlew bootJar
@@ -96,8 +90,7 @@ listening on
9690

9791
## Declarative Configuration with Spring Boot
9892

99-
The declarative configuration used by this example lives in [
100-
`application.yaml`](./src/main/resources/application.yaml)
93+
The declarative configuration used by this example lives in [`application.yaml`](./src/main/resources/application.yaml)
10194
under the `otel:` root key.
10295

10396
```yaml
@@ -107,20 +100,17 @@ otel:
107100

108101
This layout follows the declarative configuration schema defined in the
109102
[opentelemetry-configuration](https://github.com/open-telemetry/opentelemetry-configuration)
110-
repository, but adapted
111-
for Spring Boot:
103+
repository, but adapted for Spring Boot:
112104

113105
- All OpenTelemetry configuration keys live under the `otel:` root
114106
- Configuration blocks from the reference repo (such as `tracer_provider`, `meter_provider`,
115-
`logger_provider`, etc.)
116-
are indented by **two spaces** beneath `otel:`
107+
`logger_provider`, etc.) are indented by **two spaces** beneath `otel:`
117108
- The configuration is loaded via the OpenTelemetry Spring Boot Starter instead of the Java Agent
118109

119110
### Opting In with `file_format`
120111

121112
Declarative configuration is **opt-in**. In this Spring Boot example, you enable declarative
122-
configuration by setting
123-
`file_format` under `otel:` in `application.yaml`:
113+
configuration by setting `file_format` under `otel:` in `application.yaml`:
124114

125115
```yaml
126116
otel:
@@ -135,36 +125,14 @@ If `file_format` is missing, declarative configuration is not applied.
135125
### Example: Exporters and Sampler Rules (Spring Style)
136126

137127
Below is a simplified view of the configuration used in this module. All keys are indented under
138-
`otel:` as required by
139-
Spring Boot declarative configuration. Refer to the actual
128+
`otel:` as required by Spring Boot declarative configuration. Refer to the actual
140129
[`application.yaml`](./src/main/resources/application.yaml) for the complete version.
141130

142131
```yaml
143132
otel:
144133
file_format: "1.0-rc.2"
145134

146-
resource:
147-
attributes:
148-
- name: service.name
149-
value: spring-boot-declarative-config-example
150-
151-
propagator:
152-
composite:
153-
- tracecontext:
154-
- baggage:
155-
156135
tracer_provider:
157-
processors:
158-
- batch:
159-
exporter:
160-
otlp_http:
161-
# Note: Spring uses : instead of :- as separator for the default value
162-
endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT:http://localhost:4318}/v1/traces
163-
164-
- batch:
165-
exporter:
166-
console:
167-
168136
sampler:
169137
rule_based_routing:
170138
fallback_sampler:
@@ -174,30 +142,13 @@ otel:
174142
- action: DROP
175143
attribute: url.path
176144
pattern: /actuator.*
177-
178-
meter_provider:
179-
readers:
180-
- periodic:
181-
exporter:
182-
otlp_http:
183-
endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT:http://localhost:4318}/v1/metrics
184-
185-
logger_provider:
186-
processors:
187-
- batch:
188-
exporter:
189-
otlp_http:
190-
endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT:http://localhost:4318}/v1/logs
191145
```
192146
193-
This configuration is conceptually equivalent to the Java Agent example’s `rule_based_routing`
194-
sampler (from
195-
`javaagent-declarative-configuration/otel-agent-config.yaml`):
196-
197-
- It uses the `rule_based_routing` sampler contribution
198-
- It restricts evaluation to `SERVER` spans
199-
- It drops (`DROP`) spans whose `url.path` matches `/actuator.*` (e.g., `/actuator/health`)
200-
- All other server requests are sampled by the `always_on` fallback sampler
147+
This configuration:
148+
- Uses the `rule_based_routing` sampler from the OpenTelemetry contrib extension
149+
- Excludes health check endpoints (`/actuator.*`) from tracing using the `DROP` action
150+
- Samples all other requests using the `always_on` fallback sampler
151+
- Only applies to `SERVER` span kinds
201152

202153
## Spring Boot Starter–Specific Notes
203154

@@ -206,14 +157,13 @@ sampler (from
206157
- Declarative configuration is supported by the OpenTelemetry Spring Boot Starter starting with
207158
version **2.22.0**
208159
- Ensure your dependencies use at least this version; otherwise, `file_format` and other declarative
209-
config features
210-
may be ignored
160+
config features may be ignored
211161

212162
### Property Metadata and IDE Auto-Completion
213163

214164
Most IDEs derive auto-completion for Spring properties from Spring Boot configuration metadata. At
215-
the time of this
216-
example, that metadata is primarily based on the **non-declarative** configuration schema.
165+
the time of this example, that metadata is primarily based on the **non-declarative** configuration
166+
schema.
217167

218168
As a result:
219169

@@ -247,15 +197,15 @@ otel:
247197
endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT:http://localhost:4318}/v1/traces
248198
```
249199

250-
Here, `http://localhost:4318` is used as the default if `OTEL_EXPORTER_OTLP_ENDPOINT` is not set.
200+
Here, `http://localhost:4318` is used as the default if the `OTEL_EXPORTER_OTLP_ENDPOINT`
201+
environment variable is not set.
251202

252203
When copying configuration from non-Spring examples, always convert `:-` to `:` in placeholders.
253204

254205
## Declarative vs Programmatic Configuration
255206

256207
Declarative configuration, as used in this example, allows you to express routing and sampling rules
257-
entirely in
258-
configuration files. This is ideal for:
208+
entirely in configuration files. This is ideal for:
259209

260210
- Operational teams that need to adjust sampling or filtering without changing code
261211
- Environments where configuration is managed externally (Kubernetes ConfigMaps, Spring Cloud
@@ -266,15 +216,12 @@ For more advanced or dynamic scenarios, you can still use **programmatic** confi
266216
this repository contains an example of this:
267217

268218
- See `configureSampler` in
269-
[
270-
`OpenTelemetryConfig`](../spring-native/src/main/java/io/opentelemetry/example/graal/OpenTelemetryConfig.java)
271-
- It uses `RuleBasedRoutingSampler` programmatically to drop spans for actuator endpoints (
272-
`/actuator*`), replicating
273-
the behavior we achieve declaratively via YAML in this module
219+
[`OpenTelemetryConfig`](../spring-native/src/main/java/io/opentelemetry/example/graal/OpenTelemetryConfig.java)
220+
- It uses `RuleBasedRoutingSampler` programmatically to drop spans for actuator endpoints
221+
(`/actuator*`), replicating the behavior we achieve declaratively via YAML in this module
274222

275223
In many cases, you can start with declarative configuration (as in this module) and only fall back
276-
to programmatic
277-
customization for highly dynamic or application-specific logic.
224+
to programmatic customization for highly dynamic or application-specific logic.
278225

279226
## Troubleshooting and Tips
280227

@@ -300,7 +247,6 @@ If the behavior is not what you expect, here are a few things to check:
300247
If issues persist, compare your configuration to:
301248

302249
- This module’s [`application.yaml`](./src/main/resources/application.yaml)
303-
- The Java Agent example in [
304-
`javaagent-declarative-configuration`](../javaagent-declarative-configuration)
250+
- The Java Agent example in [`javaagent-declarative-configuration`](../javaagent-declarative-configuration)
305251
- The reference schemas and examples in
306252
[opentelemetry-configuration](https://github.com/open-telemetry/opentelemetry-configuration)

0 commit comments

Comments
 (0)