File tree Expand file tree Collapse file tree
spring-declarative-configuration
src/main/java/io/opentelemetry/examples/fileconfig Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ This Spring Boot application includes two endpoints:
3030### Prerequisites
3131
3232- Java 17 or higher
33- - OpenTelemetry Spring Boot Starter ** 2.22 .0+** on the classpath of this application (already
33+ - OpenTelemetry Spring Boot Starter ** 2.30 .0+** on the classpath of this application (already
3434 configured in this example’s [ build file] ( ./build.gradle.kts ) )
3535
3636### Step 1: Build the Application
@@ -203,6 +203,18 @@ environment variable is not set.
203203
204204When copying configuration from non-Spring examples, always convert `:-` to `:` in placeholders.
205205
206+ # # Read instrumentation configuration programmatically
207+
208+ Starting with version 2.30.0, the OpenTelemetry Spring Boot Starter exposes a `ConfigProvider`
209+ Spring bean. The [`ReadInstrumentationConfig`](./src/main/java/io/opentelemetry/examples/fileconfig/ReadInstrumentationConfig.java)
210+ component demonstrates how application code can inject this bean and read instrumentation
211+ configuration.
212+
213+ ` ConfigProvider#getInstrumentationConfig()` returns the `instrumentation/development` configuration
214+ tree. This example walks through `java.common.db.query_sanitization` and reads the `enabled` value,
215+ defaulting to `true` when it is not configured. The same tree is used whether the setting comes from
216+ an `otel.instrumentation.*` property or the equivalent declarative YAML configuration.
217+
206218# # Declarative vs Programmatic Configuration
207219
208220Declarative configuration, as used in this example, allows you to express routing and sampling rules
Original file line number Diff line number Diff line change 1717
1818dependencies {
1919 implementation(platform(SpringBootPlugin .BOM_COORDINATES ))
20- implementation(platform(" io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:2.29 .0" ))
20+ implementation(platform(" io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:2.30 .0" ))
2121 implementation(" org.springframework.boot:spring-boot-starter-actuator" )
2222 implementation(" org.springframework.boot:spring-boot-starter-web" )
2323 implementation(" io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter" )
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright The OpenTelemetry Authors
3+ * SPDX-License-Identifier: Apache-2.0
4+ */
5+
6+ package io .opentelemetry .examples .fileconfig ;
7+
8+ import io .opentelemetry .api .incubator .config .ConfigProvider ;
9+ import io .opentelemetry .api .incubator .config .DeclarativeConfigProperties ;
10+ import org .springframework .stereotype .Component ;
11+
12+ /** Example of reading instrumentation configuration from application code. */
13+ @ Component
14+ public class ReadInstrumentationConfig {
15+
16+ private final ConfigProvider configProvider ;
17+
18+ public ReadInstrumentationConfig (ConfigProvider configProvider ) {
19+ this .configProvider = configProvider ;
20+ }
21+
22+ public boolean isDbQuerySanitizationEnabled () {
23+ DeclarativeConfigProperties dbConfig =
24+ configProvider
25+ .getInstrumentationConfig ()
26+ .get ("java" )
27+ .get ("common" )
28+ .get ("db" )
29+ .get ("query_sanitization" );
30+ return dbConfig .getBoolean ("enabled" , true );
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments