diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ResourceConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ResourceConfiguration.java index 010d219acba..21026fe75aa 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ResourceConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ResourceConfiguration.java @@ -21,9 +21,11 @@ import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.BiFunction; +import java.util.logging.Logger; /** * Auto-configuration for the OpenTelemetry {@link Resource}. @@ -32,12 +34,16 @@ */ public final class ResourceConfiguration { + private static final Logger logger = Logger.getLogger(ResourceConfiguration.class.getName()); + private static final AttributeKey SERVICE_NAME = AttributeKey.stringKey("service.name"); // Visible for testing static final String ATTRIBUTE_PROPERTY = "otel.resource.attributes"; static final String SERVICE_NAME_PROPERTY = "otel.service.name"; - static final String DISABLED_ATTRIBUTE_KEYS = "otel.experimental.resource.disabled.keys"; + static final String EXPERIMENTAL_DISABLED_ATTRIBUTE_KEYS = + "otel.experimental.resource.disabled.keys"; + static final String DISABLED_ATTRIBUTE_KEYS = "otel.resource.disabled.keys"; /** * Create a {@link Resource} from the environment. The resource contains attributes parsed from @@ -113,7 +119,16 @@ static Resource configureResource( // visible for testing static Resource filterAttributes(Resource resource, ConfigProperties configProperties) { - Set disabledKeys = new HashSet<>(configProperties.getList(DISABLED_ATTRIBUTE_KEYS)); + List disabledAttibuteKeys = configProperties.getList(DISABLED_ATTRIBUTE_KEYS); + // TODO: Remove this once the deprecated property is removed. + if (disabledAttibuteKeys.isEmpty()) { + disabledAttibuteKeys = configProperties.getList(EXPERIMENTAL_DISABLED_ATTRIBUTE_KEYS); + if (!disabledAttibuteKeys.isEmpty()) { + logger.warning( + "otel.experimental.resource.disabled.keys is deprecated and will be removed after 1.45.0 release. Please use otel.resource.disabled.keys instead."); + } + } + Set disabledKeys = new HashSet<>(disabledAttibuteKeys); ResourceBuilder builder = resource.toBuilder().removeIf(attributeKey -> disabledKeys.contains(attributeKey.getKey())); diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/ResourceConfigurationTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/ResourceConfigurationTest.java index 33cc9740639..8e6a42d3af6 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/ResourceConfigurationTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/ResourceConfigurationTest.java @@ -26,7 +26,28 @@ class ResourceConfigurationTest { @Test - void customConfigResource() { + void customConfigResourceWithDisabledKeys() { + Map props = new HashMap<>(); + props.put("otel.service.name", "test-service"); + props.put( + "otel.resource.attributes", "food=cheesecake,drink=juice,animal= ,color=,shape=square"); + props.put("otel.resource.disabled-keys", "drink"); + + assertThat( + ResourceConfiguration.configureResource( + DefaultConfigProperties.create(props), + SpiHelper.create(ResourceConfigurationTest.class.getClassLoader()), + (r, c) -> r)) + .isEqualTo( + Resource.getDefault().toBuilder() + .put(stringKey("service.name"), "test-service") + .put("food", "cheesecake") + .put("shape", "square") + .build()); + } + + @Test + void customConfigResourceWithExperimentalDisabledKeys() { Map props = new HashMap<>(); props.put("otel.service.name", "test-service"); props.put(