Skip to content

Commit 2d89b60

Browse files
authored
Add declarative configuration docs for Spring Boot starter (#9448)
1 parent c4c8aa7 commit 2d89b60

11 files changed

Lines changed: 777 additions & 163 deletions

File tree

content/en/blog/2024/spring-starter-stable/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Here are some scenarios where you might want to use the Spring Starter:
4343
doesn't work with the OpenTelemetry Java agent
4444
- **Programmatic configuration** of the OpenTelemetry Spring Boot starter, such
4545
as
46-
[dynamic auth headers](/docs/zero-code/java/spring-boot-starter/sdk-configuration/#configure-the-exporter-programmatically),
46+
[dynamic auth headers](/docs/zero-code/java/spring-boot-starter/programmatic-configuration/#configure-the-exporter-programmatically),
4747
using Spring beans (the OpenTelemetry Java agent requires an
4848
[extension](/docs/zero-code/java/agent/extensions/) for this)
4949
- **Uses code dependencies**: You don't need to add any JVM options (e.g. in

content/en/docs/zero-code/java/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ cascade:
88
vers:
99
instrumentation: 2.27.0
1010
otel: 1.61.0
11+
contrib: 1.54.0
1112
---
1213

1314
Common options for zero-code instrumentation with Java are the Java agent JAR,

content/en/docs/zero-code/java/agent/declarative-configuration.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ getting started guide for declarative configuration.
7676
7777
This page focuses on specifics for the
7878
[OpenTelemetry Java agent](https://github.com/open-telemetry/opentelemetry-java-instrumentation).
79+
For the Spring Boot starter, see
80+
[Spring Boot starter declarative configuration](/docs/zero-code/java/spring-boot-starter/declarative-configuration/).
7981
8082
## Mapping of configuration options
8183
@@ -222,14 +224,6 @@ Contrib features that are not yet supported by declarative configuration:
222224
- [GCP authentication](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/gcp-auth-extension)
223225
- [Inferred Spans](https://github.com/open-telemetry/opentelemetry-java-contrib/blob/main/inferred-spans)
224226

225-
### Spring Boot starter limitations
226-
227-
Lastly, the [Spring Boot starter](/docs/zero-code/java/spring-boot-starter) does
228-
not yet support declarative configuration:
229-
230-
- however, you can already use `application.yaml` to configure the OpenTelemetry
231-
Spring Boot starter
232-
233227
## Extension API
234228

235229
Extensions use a new declarative configuration API.

content/en/docs/zero-code/java/spring-boot-starter/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ OpenTelemetry.
2424
- **Spring Boot configuration files** (`application.properties`,
2525
`application.yml`) to configure the OpenTelemetry Spring Boot starter which
2626
doesn't work with the OpenTelemetry Java agent
27+
- **[Declarative configuration](declarative-configuration/)** using a
28+
structured YAML format inside `application.yaml`

content/en/docs/zero-code/java/spring-boot-starter/additional-instrumentations.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,33 @@ You can find more configuration options for the OpenTelemetry appender in the
2929
[Log4j](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/log4j/log4j-appender-2.17/library/README.md)
3030
instrumentation library.
3131

32-
| System property | Type | Default | Description |
33-
| --------------------------------------------- | ------- | ------- | ----------------------------------------------------------------------------------------------- |
34-
| `otel.instrumentation.log4j-appender.enabled` | Boolean | true | Enables the configuration of the Log4j OpenTelemetry appender with an `OpenTelemetry` instance. |
32+
{{< tabpane text=true >}} {{% tab "Properties" %}}
33+
34+
Enables the configuration of the Log4j OpenTelemetry appender with an
35+
`OpenTelemetry` instance:
36+
37+
```yaml
38+
otel:
39+
instrumentation:
40+
log4j-appender:
41+
enabled: true # default: true
42+
```
43+
44+
{{% /tab %}} {{% tab "Declarative Configuration" %}}
45+
46+
In [declarative configuration](../declarative-configuration/), use the
47+
centralized instrumentation lists to enable or disable Log4j:
48+
49+
```yaml
50+
otel:
51+
distribution:
52+
spring_starter:
53+
instrumentation:
54+
disabled:
55+
- log4j_appender
56+
```
57+
58+
{{% /tab %}} {{< /tabpane >}}
3559
3660
## Instrumentation libraries
3761

content/en/docs/zero-code/java/spring-boot-starter/annotations.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ dependencies {
116116
You can disable the OpenTelemetry annotations by setting the
117117
`otel.instrumentation.annotations.enabled` property to `false`.
118118

119+
In [declarative configuration](../declarative-configuration/), use the
120+
centralized instrumentation lists instead:
121+
122+
```yaml
123+
otel:
124+
distribution:
125+
spring_starter:
126+
instrumentation:
127+
disabled:
128+
- annotations
129+
```
130+
119131
You can customize the span by using the elements of the `WithSpan` annotation:
120132

121133
| Name | Type | Description | Default Value |
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
---
2+
title: Declarative configuration
3+
weight: 25
4+
cSpell:ignore: Customizer Dotel
5+
---
6+
7+
Declarative configuration uses the
8+
[OpenTelemetry declarative configuration schema](/docs/languages/sdk-configuration/declarative-configuration/)
9+
inside your `application.yaml`.
10+
11+
This approach is useful when:
12+
13+
- You have many configuration options to set
14+
- You want to use configuration options that are not available with
15+
`application.properties` or `application.yaml`
16+
- You want to use the same configuration format as the
17+
[Java agent](/docs/zero-code/java/agent/declarative-configuration/)
18+
19+
> [!WARNING]
20+
>
21+
> Declarative configuration is experimental.
22+
23+
## Supported versions
24+
25+
Declarative configuration is supported in the **OpenTelemetry Spring Boot
26+
starter version 2.26.0 and later**.
27+
28+
## Getting started
29+
30+
Add `otel.file_format: "1.0"` (or the current or desired version) to your
31+
`application.yaml` to opt in to declarative configuration:
32+
33+
```yaml
34+
otel:
35+
file_format: '1.0'
36+
37+
resource:
38+
detection/development:
39+
detectors:
40+
- service:
41+
attributes:
42+
- name: service.name
43+
value: my-spring-app
44+
45+
propagator:
46+
composite:
47+
- tracecontext:
48+
- baggage:
49+
50+
tracer_provider:
51+
processors:
52+
- batch:
53+
exporter:
54+
otlp_http:
55+
endpoint: ${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT:http://localhost:4318/v1/traces}
56+
57+
meter_provider:
58+
readers:
59+
- periodic:
60+
exporter:
61+
otlp_http:
62+
endpoint: ${OTEL_EXPORTER_OTLP_METRICS_ENDPOINT:http://localhost:4318/v1/metrics}
63+
64+
logger_provider:
65+
processors:
66+
- batch:
67+
exporter:
68+
otlp_http:
69+
endpoint: ${OTEL_EXPORTER_OTLP_LOGS_ENDPOINT:http://localhost:4318/v1/logs}
70+
```
71+
72+
Note that `${VAR:default}` uses a single colon (Spring syntax), not the
73+
`${VAR:-default}` syntax used in the agent's standalone YAML file.
74+
75+
## Mapping of configuration options
76+
77+
The following rules describe how `application.properties` / `application.yaml`
78+
configuration options map to their declarative configuration equivalents:
79+
80+
### Instrumentation enable/disable
81+
82+
In declarative configuration, instrumentation enable/disable uses centralized
83+
lists instead of individual properties. The instrumentation name uses `_`
84+
(snake_case), not `-` (kebab-case).
85+
86+
| Properties | Declarative Configuration |
87+
| ----------------------------------------------------- | ------------------------------------------------------------------------------- |
88+
| `otel.instrumentation.jdbc.enabled=true` | `otel.distribution.spring_starter.instrumentation.enabled: [jdbc]` |
89+
| `otel.instrumentation.logback-appender.enabled=false` | `otel.distribution.spring_starter.instrumentation.disabled: [logback_appender]` |
90+
| `otel.instrumentation.common.default-enabled=false` | `otel.distribution.spring_starter.instrumentation.default_enabled: false` |
91+
92+
Example:
93+
94+
```yaml
95+
otel:
96+
distribution:
97+
spring_starter:
98+
instrumentation:
99+
default_enabled: false
100+
enabled:
101+
- jdbc
102+
- spring_web
103+
disabled:
104+
- logback_appender
105+
```
106+
107+
### Instrumentation configuration
108+
109+
Configuration options under `otel.instrumentation.*` (other than enable/disable)
110+
map to `otel.instrumentation/development.java.*`:
111+
112+
1. Strip the `otel.instrumentation.` prefix
113+
2. Per segment: replace `-` with `_`
114+
3. Place under `otel.instrumentation/development.java.`
115+
4. A `/development` suffix on a key indicates an experimental feature (see the
116+
`translateName` method in `ConfigPropertiesBackedDeclarativeConfigProperties`
117+
for the reverse mapping)
118+
119+
For example:
120+
121+
| Properties | Declarative Configuration |
122+
| ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
123+
| `otel.instrumentation.logback-appender.experimental-log-attributes` | `otel.instrumentation/development.java.logback_appender.experimental_log_attributes/development` |
124+
125+
Some options have special mappings that don't follow the default algorithm:
126+
127+
| Properties | Declarative Configuration |
128+
| ----------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
129+
| `otel.instrumentation.common.db-statement-sanitizer.enabled` | `otel.instrumentation/development.java.common.database.statement_sanitizer.enabled` |
130+
| `otel.instrumentation.http.client.capture-request-headers` | `otel.instrumentation/development.general.http.client.request_captured_headers` |
131+
| `otel.instrumentation.http.client.capture-response-headers` | `otel.instrumentation/development.general.http.client.response_captured_headers` |
132+
| `otel.instrumentation.http.server.capture-request-headers` | `otel.instrumentation/development.general.http.server.request_captured_headers` |
133+
| `otel.instrumentation.http.server.capture-response-headers` | `otel.instrumentation/development.general.http.server.response_captured_headers` |
134+
| `otel.instrumentation.http.client.emit-experimental-telemetry` | `otel.instrumentation/development.java.common.http.client.emit_experimental_telemetry/development` |
135+
| `otel.instrumentation.http.server.emit-experimental-telemetry` | `otel.instrumentation/development.java.common.http.server.emit_experimental_telemetry/development` |
136+
| `otel.instrumentation.http.known-methods` | `otel.instrumentation/development.java.common.http.known_methods` |
137+
| `otel.instrumentation.messaging.experimental.receive-telemetry.enabled` | `otel.instrumentation/development.java.common.messaging.receive_telemetry/development.enabled` |
138+
| `otel.jmx.enabled` | `otel.instrumentation/development.java.jmx.enabled` |
139+
140+
The `instrumentation/development` section has two top-level groups:
141+
142+
- `general.*` — Cross-language configuration (HTTP headers, semantic convention
143+
stability)
144+
- `java.*` — Java-specific instrumentation configuration
145+
146+
### Disable the SDK
147+
148+
| Properties | Declarative Configuration |
149+
| ------------------------ | ------------------------- |
150+
| `otel.sdk.disabled=true` | `otel.disabled: true` |
151+
152+
### SDK configuration
153+
154+
SDK-level configuration (exporters, propagators, resources) follows the standard
155+
[declarative configuration schema](/docs/languages/sdk-configuration/declarative-configuration/)
156+
directly under `otel:`, as shown in the [Getting started](#getting-started)
157+
example.
158+
159+
## Differences from agent declarative configuration
160+
161+
| Aspect | Agent | Spring Boot starter |
162+
| --------------- | -------------------------------------------------------- | ------------------------------------------------------------- |
163+
| Config location | Separate file (`-Dotel.config.file=...`) | Inside `application.yaml` |
164+
| Variable syntax | `${VAR:-default}` (double-colon) | `${VAR:default}` (single colon, Spring) |
165+
| Profiles | Not supported | Spring profiles work normally |
166+
| Enable/disable | `distribution.javaagent.instrumentation.*` | `distribution.spring_starter.instrumentation.*` |
167+
| Default-enabled | `distribution.javaagent.instrumentation.default_enabled` | `distribution.spring_starter.instrumentation.default_enabled` |
168+
169+
## Environment variable overrides
170+
171+
Spring's relaxed binding lets you override any part of the declarative
172+
configuration YAML via environment variables:
173+
174+
```shell
175+
# Override a scalar under instrumentation/development
176+
OTEL_INSTRUMENTATION/DEVELOPMENT_JAVA_FOO_STRING_KEY=new_value
177+
178+
# Override an indexed list element (e.g. exporter endpoint)
179+
OTEL_TRACER_PROVIDER_PROCESSORS_0_BATCH_EXPORTER_OTLP_HTTP_ENDPOINT=http://custom:4318/v1/traces
180+
```
181+
182+
Rules: uppercase, replace `.` with `_`, keep `/` as-is (e.g.
183+
`INSTRUMENTATION/DEVELOPMENT`), use `_0_`, `_1_` for list indices.
184+
185+
This is a standard Spring feature — it works for any key in `application.yaml`.
186+
187+
## Duration format
188+
189+
Declarative configuration **only supports durations in milliseconds** (e.g.
190+
`5000` for 5 seconds). You will get an error if you use a duration string like
191+
`5s`.
192+
193+
## Programmatic configuration
194+
195+
With declarative configuration, `AutoConfigurationCustomizerProvider` (see
196+
[Programmatic configuration](../programmatic-configuration/)) is replaced by
197+
`DeclarativeConfigurationCustomizerProvider`. Components such as span exporters
198+
use the `ComponentProvider` API. See the
199+
[agent Extension API section](/docs/zero-code/java/agent/declarative-configuration/)
200+
for details and examples — the same APIs apply to the Spring Boot starter.

content/en/docs/zero-code/java/spring-boot-starter/other-spring-autoconfig.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,32 @@ dependencies {
5050

5151
### Configurations
5252

53-
| Property | Default Value | ConditionalOnClass |
54-
| ------------------------------ | ------------- | -------------------- |
55-
| `otel.exporter.zipkin.enabled` | true | `ZipkinSpanExporter` |
53+
{{< tabpane text=true >}} {{% tab "Properties" %}}
54+
55+
Enables the Zipkin exporter (requires `ZipkinSpanExporter` on the classpath):
56+
57+
```yaml
58+
otel:
59+
exporter:
60+
zipkin:
61+
enabled: true # default: true
62+
```
63+
64+
{{% /tab %}} {{% tab "Declarative Configuration" %}}
65+
66+
With [declarative configuration](../declarative-configuration/), the Zipkin
67+
exporter is configured as part of the standard
68+
[declarative configuration schema](/docs/languages/sdk-configuration/declarative-configuration/)
69+
under `tracer_provider.processors`:
70+
71+
```yaml
72+
otel:
73+
tracer_provider:
74+
processors:
75+
- batch:
76+
exporter:
77+
zipkin:
78+
endpoint: http://localhost:9411/api/v2/spans
79+
```
80+
81+
{{% /tab %}} {{< /tabpane >}}

0 commit comments

Comments
 (0)