fix spring declarative config with env var substitution#15775
fix spring declarative config with env var substitution#15775trask merged 25 commits intoopen-telemetry:mainfrom
Conversation
trask
left a comment
There was a problem hiding this comment.
I'd prefer if we can find a way to map to typed data based on the yaml content only instead of dynamically coercing based on whether getInt or getString happens to be called by the user
...tation/spring/spring-boot-autoconfigure/src/testDeclarativeConfig/resources/application.yaml
Show resolved
Hide resolved
...Config/java/io/opentelemetry/instrumentation/spring/autoconfigure/DeclarativeConfigTest.java
Show resolved
Hide resolved
15656d2 to
722ccd6
Compare
|
@trask please have a look |
|
@trask please have a look |
trask
left a comment
There was a problem hiding this comment.
sent a possible simplification: zeitlinger#8
...io/opentelemetry/instrumentation/spring/autoconfigure/SpringDeclarativeConfigProperties.java
Outdated
Show resolved
Hide resolved
instrumentation/spring/spring-boot-autoconfigure/build.gradle.kts
Outdated
Show resolved
Hide resolved
...io/opentelemetry/instrumentation/spring/autoconfigure/SpringDeclarativeConfigProperties.java
Outdated
Show resolved
Hide resolved
...io/opentelemetry/instrumentation/spring/autoconfigure/SpringDeclarativeConfigProperties.java
Outdated
Show resolved
Hide resolved
- Delete SpringConfigProvider, use lambda for ConfigProvider since it's a functional interface - Make CoercingDeclarativeConfigProperties.wrap() handle null - Merge duplicate withType<Test>().configureEach blocks in build.gradle.kts Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
In CoercingDeclarativeConfigProperties, try getString() first before the typed getter (getBoolean, getInt, etc). This avoids triggering the warning in YamlDeclarativeConfigProperties when a value is stored as String instead of its native type. Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
c52e7ec to
c8b74c7
Compare
CI fixThe Root cause: Fix: Flip the order in |
...va/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java
Outdated
Show resolved
Hide resolved
.../src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/EmbeddedConfigFile.java
Show resolved
Hide resolved
.../opentelemetry/instrumentation/spring/autoconfigure/CoercingDeclarativeConfigProperties.java
Outdated
Show resolved
Hide resolved
.../opentelemetry/instrumentation/spring/autoconfigure/CoercingDeclarativeConfigProperties.java
Outdated
Show resolved
Hide resolved
…simplify getString Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
… SpringConfigProvider The CoercingDeclarativeConfigProperties wrapper triggers noisy WARN logs from YamlDeclarativeConfigProperties when values are stored as strings. Revert to the original approach of SpringDeclarativeConfigProperties + SpringConfigProvider which handles type coercion directly. Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Address review: remove cross-type conversions (Long->Integer, Integer->Long, Float->Double, Boolean native) and only coerce from String, since that's the only case Spring produces. Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
...rc/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/SpringConfigProvider.java
Outdated
Show resolved
Hide resolved
...io/opentelemetry/instrumentation/spring/autoconfigure/SpringDeclarativeConfigProperties.java
Outdated
Show resolved
Hide resolved
...io/opentelemetry/instrumentation/spring/autoconfigure/SpringDeclarativeConfigProperties.java
Outdated
Show resolved
Hide resolved
...io/opentelemetry/instrumentation/spring/autoconfigure/SpringDeclarativeConfigProperties.java
Outdated
Show resolved
Hide resolved
...va/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java
Outdated
Show resolved
Hide resolved
...rc/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/SpringConfigProvider.java
Outdated
Show resolved
Hide resolved
…oader passthrough Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
...va/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java
Outdated
Show resolved
Hide resolved
...io/opentelemetry/instrumentation/spring/autoconfigure/SpringDeclarativeConfigProperties.java
Show resolved
Hide resolved
…es in coercion Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
|
Addressed both review comments:
|
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
...io/opentelemetry/instrumentation/spring/autoconfigure/SpringDeclarativeConfigProperties.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Reverts the prior declarative-config “wrapper” approach for Spring Boot and restores a Spring-specific DeclarativeConfigProperties implementation to avoid noisy WARN logs when Spring resolves values as strings (notably with env var substitution).
Changes:
- Add Spring-specific
DeclarativeConfigProperties+ConfigProviderto coerce scalar types without triggering YAML-type warnings. - Adjust Spring embedded-config extraction to treat resolved Spring properties as
Stringvalues and convert them into anOpenTelemetryConfigurationModel. - Expand declarative-config tests (including env var substitution/overrides) and update Gradle JVM args to support env var mutation in tests.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| instrumentation/spring/spring-boot-autoconfigure/src/testDeclarativeConfig/resources/application.yaml | Expands declarative-config sample properties to cover scalar types and env var substitution (quoted/unquoted). |
| instrumentation/spring/spring-boot-autoconfigure/src/testDeclarativeConfig/java/io/opentelemetry/instrumentation/spring/autoconfigure/DeclarativeConfigTest.java | Updates tests to assert typed access/coercion and validates env var overrides in both Spring-style and Otel-style forms. |
| instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/EmbeddedConfigFileTest.java | Aligns tests with the flat-props map now being Map<String, String>. |
| instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/SpringDeclarativeConfigProperties.java | Introduces Spring-specific declarative properties implementation with scalar coercion logic. |
| instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/SpringConfigProvider.java | Adds Spring-specific ConfigProvider that feeds the coerced declarative properties to SpringOpenTelemetrySdk. |
| instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java | Wires declarative-config startup to return SpringOpenTelemetrySdk backed by the new Spring config provider. |
| instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/EmbeddedConfigFile.java | Changes extraction to collect resolved Spring properties as strings and converts them into the OTel configuration model. |
| instrumentation/spring/spring-boot-autoconfigure/build.gradle.kts | Adds an additional --add-opens needed for env var mutation via JUnit Pioneer on newer JDKs. |
Reverts the "simplify" approach (commit
7fc9b04808) that replacedSpringDeclarativeConfigProperties+SpringConfigProviderwithCoercingDeclarativeConfigPropertieswrappingYamlDeclarativeConfigProperties.The wrapper approach triggers noisy WARN logs from
YamlDeclarativeConfigPropertieswhen values are stored as strings (which is the case with Spring property resolution).Reverting to the original approach avoids this issue. The upstream fix can be revisited via open-telemetry/opentelemetry-java#8101.