Skip to content

Commit 5485755

Browse files
committed
Align SpringConfigProperties with DefaultConfigProperties
1 parent f235209 commit 5485755

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/SpringConfigProperties.java

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties;
77

8+
import io.opentelemetry.api.internal.ConfigUtil;
89
import io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil;
910
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
1011
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
@@ -65,8 +66,9 @@ public static ConfigProperties create(
6566
@Nullable
6667
@Override
6768
public String getString(String name) {
68-
String value = environment.getProperty(name, String.class);
69-
if (value == null && name.equals("otel.exporter.otlp.protocol")) {
69+
String normalizedName = ConfigUtil.normalizePropertyKey(name);
70+
String value = environment.getProperty(normalizedName, String.class);
71+
if (value == null && normalizedName.equals("otel.exporter.otlp.protocol")) {
7072
// SDK autoconfigure module defaults to `grpc`, but this module aligns with recommendation
7173
// in specification to default to `http/protobuf`
7274
return OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF;
@@ -77,35 +79,45 @@ public String getString(String name) {
7779
@Nullable
7880
@Override
7981
public Boolean getBoolean(String name) {
80-
return or(environment.getProperty(name, Boolean.class), otelSdkProperties.getBoolean(name));
82+
return or(
83+
environment.getProperty(ConfigUtil.normalizePropertyKey(name), Boolean.class),
84+
otelSdkProperties.getBoolean(name));
8185
}
8286

8387
@Nullable
8488
@Override
8589
public Integer getInt(String name) {
86-
return or(environment.getProperty(name, Integer.class), otelSdkProperties.getInt(name));
90+
return or(
91+
environment.getProperty(ConfigUtil.normalizePropertyKey(name), Integer.class),
92+
otelSdkProperties.getInt(name));
8793
}
8894

8995
@Nullable
9096
@Override
9197
public Long getLong(String name) {
92-
return or(environment.getProperty(name, Long.class), otelSdkProperties.getLong(name));
98+
return or(
99+
environment.getProperty(ConfigUtil.normalizePropertyKey(name), Long.class),
100+
otelSdkProperties.getLong(name));
93101
}
94102

95103
@Nullable
96104
@Override
97105
public Double getDouble(String name) {
98-
return or(environment.getProperty(name, Double.class), otelSdkProperties.getDouble(name));
106+
return or(
107+
environment.getProperty(ConfigUtil.normalizePropertyKey(name), Double.class),
108+
otelSdkProperties.getDouble(name));
99109
}
100110

101111
@SuppressWarnings("unchecked")
102112
@Override
103113
public List<String> getList(String name) {
104-
if (name.equals("otel.propagators")) {
114+
String normalizedName = ConfigUtil.normalizePropertyKey(name);
115+
116+
if (normalizedName.equals("otel.propagators")) {
105117
return propagationProperties.getPropagators();
106118
}
107119

108-
return or(environment.getProperty(name, List.class), otelSdkProperties.getList(name));
120+
return or(environment.getProperty(normalizedName, List.class), otelSdkProperties.getList(name));
109121
}
110122

111123
@Nullable
@@ -123,8 +135,10 @@ public Duration getDuration(String name) {
123135
@Override
124136
public Map<String, String> getMap(String name) {
125137
Map<String, String> otelSdkMap = otelSdkProperties.getMap(name);
138+
139+
String normalizedName = ConfigUtil.normalizePropertyKey(name);
126140
// maps from config properties are not supported by Environment, so we have to fake it
127-
switch (name) {
141+
switch (normalizedName) {
128142
case "otel.resource.attributes":
129143
return mergeWithOtel(resourceProperties.getAttributes(), otelSdkMap);
130144
case "otel.exporter.otlp.headers":
@@ -139,7 +153,7 @@ public Map<String, String> getMap(String name) {
139153
break;
140154
}
141155

142-
String value = environment.getProperty(name);
156+
String value = environment.getProperty(normalizedName);
143157
if (value == null) {
144158
return otelSdkMap;
145159
}

smoke-tests-otel-starter/spring-boot-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelSpringStarterSmokeTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ AutoConfigurationCustomizerProvider propagatorCustomizer() {
104104
Attributes.of(
105105
AttributeKey.booleanKey("keyFromResourceCustomizer"), true))));
106106
}
107+
108+
@Bean
109+
AutoConfigurationCustomizerProvider customizerUsingPropertyDefinedInASpringFile() {
110+
return customizer ->
111+
customizer.addResourceCustomizer(
112+
(resource, config) ->
113+
{
114+
String propValue = config.getString("APPLICATION-PROP");
115+
assertThat(propValue).isNotEmpty();
116+
return resource;
117+
}
118+
);
119+
}
107120
}
108121

109122
@Test

smoke-tests-otel-starter/spring-boot-common/src/main/resources/application.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ otel:
1919
attributes:
2020
attributeFromYaml: true # boolean will be automatically converted to string by spring
2121

22+
application:
23+
prop: propValue
24+
2225
spring:
2326
kafka:
2427
bootstrap-servers: localhost:9094

0 commit comments

Comments
 (0)