diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c8bc930ae..d1b4d3fa75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +* Feat: Merge external map properties (#1656) + ## 5.1.0 * Feat: Spring WebClient integration (#1621) diff --git a/sentry/src/main/java/io/sentry/config/CompositePropertiesProvider.java b/sentry/src/main/java/io/sentry/config/CompositePropertiesProvider.java index 3414c62a53..8e0449306a 100644 --- a/sentry/src/main/java/io/sentry/config/CompositePropertiesProvider.java +++ b/sentry/src/main/java/io/sentry/config/CompositePropertiesProvider.java @@ -31,12 +31,10 @@ public CompositePropertiesProvider(@NotNull List providers) @Override public @NotNull Map getMap(final @NotNull String property) { + final Map result = new ConcurrentHashMap<>(); for (final PropertiesProvider provider : providers) { - final Map result = provider.getMap(property); - if (!result.isEmpty()) { - return result; - } + result.putAll(provider.getMap(property)); } - return new ConcurrentHashMap<>(); + return result; } } diff --git a/sentry/src/test/java/io/sentry/config/CompositePropertiesProviderTest.kt b/sentry/src/test/java/io/sentry/config/CompositePropertiesProviderTest.kt index 087c53b745..b05fb2583b 100644 --- a/sentry/src/test/java/io/sentry/config/CompositePropertiesProviderTest.kt +++ b/sentry/src/test/java/io/sentry/config/CompositePropertiesProviderTest.kt @@ -31,4 +31,18 @@ class CompositePropertiesProviderTest { whenever(second.getProperty("property")).thenReturn(null) assertNull(provider.getProperty("property")) } + + @Test + fun `combines map results from multiple providers into single map`() { + whenever(first.getMap("tags")).thenReturn(mapOf("first_tag" to "val1")) + whenever(second.getMap("tags")).thenReturn(mapOf("second_tag" to "val2")) + assertEquals(mapOf("first_tag" to "val1", "second_tag" to "val2"), provider.getMap("tags")) + } + + @Test + fun `when multiple providers return same map entries, the last one takes the precedence`() { + whenever(first.getMap("tags")).thenReturn(mapOf("first_tag" to "val1", "conflicting_tag" to "val3")) + whenever(second.getMap("tags")).thenReturn(mapOf("second_tag" to "val2", "conflicting_tag" to "val4")) + assertEquals(mapOf("first_tag" to "val1", "second_tag" to "val2", "conflicting_tag" to "val4"), provider.getMap("tags")) + } }