Skip to content

Commit bfafc1d

Browse files
committed
fix
1 parent fa73f33 commit bfafc1d

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/EmbeddedConfigFile.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.util.Objects;
1414
import java.util.regex.Matcher;
1515
import java.util.regex.Pattern;
16-
import javax.annotation.Nullable;
1716
import org.springframework.core.env.ConfigurableEnvironment;
1817
import org.springframework.core.env.EnumerablePropertySource;
1918
import org.springframework.core.env.MutablePropertySources;
@@ -87,8 +86,8 @@ static Map<String, Object> convertFlatPropsToNested(Map<String, String> flatProp
8786
boolean isLast = (i == parts.length - 1);
8887

8988
// Check if this part contains an array index like "list[0]"
90-
Matcher matcher = getArrayMatcher(part, isLast);
91-
if (matcher != null) {
89+
Matcher matcher = ARRAY_PATTERN.matcher(part);
90+
if (matcher.matches()) {
9291
String arrayName = matcher.group(1);
9392
int index = Integer.parseInt(matcher.group(2));
9493

@@ -127,12 +126,4 @@ static Map<String, Object> convertFlatPropsToNested(Map<String, String> flatProp
127126
return result;
128127
}
129128

130-
@Nullable
131-
private static Matcher getArrayMatcher(String part, boolean isLast) {
132-
if (!isLast) {
133-
return null;
134-
}
135-
Matcher matcher = ARRAY_PATTERN.matcher(part);
136-
return matcher.matches() ? matcher : null;
137-
}
138129
}

instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/EmbeddedConfigFileTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class EmbeddedConfigFileTest {
1717
@Test
1818
void convertFlatPropsToNested_simpleProperties() {
1919
Map<String, String> flatProps = new HashMap<>();
20-
flatProps.put("resource.service[0].name", "my-service");
20+
flatProps.put("resource.service.name", "my-service");
2121
flatProps.put("traces.exporter", "otlp");
2222

2323
Map<String, Object> result = EmbeddedConfigFile.convertFlatPropsToNested(flatProps);
@@ -33,12 +33,12 @@ void convertFlatPropsToNested_simpleProperties() {
3333
@SuppressWarnings("unchecked")
3434
Map<String, Object> resourceMap = (Map<String, Object>) resource;
3535
assertThat(resourceMap)
36-
.containsOnlyKeys("service[0]")
36+
.containsOnlyKeys("service")
3737
.satisfies(
3838
m -> {
3939
@SuppressWarnings("unchecked")
4040
Map<String, Object> serviceMap =
41-
(Map<String, Object>) m.get("service[0]");
41+
(Map<String, Object>) m.get("service");
4242
assertThat(serviceMap).containsEntry("name", "my-service");
4343
});
4444
});

0 commit comments

Comments
 (0)