Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilizing otel.experimental.resource.disabled.keys #6809

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -32,12 +34,16 @@
*/
public final class ResourceConfiguration {

private static final Logger logger = Logger.getLogger(ResourceConfiguration.class.getName());

private static final AttributeKey<String> 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";
jack-berg marked this conversation as resolved.
Show resolved Hide resolved

/**
* Create a {@link Resource} from the environment. The resource contains attributes parsed from
Expand Down Expand Up @@ -113,7 +119,16 @@ static Resource configureResource(

// visible for testing
static Resource filterAttributes(Resource resource, ConfigProperties configProperties) {
Set<String> disabledKeys = new HashSet<>(configProperties.getList(DISABLED_ATTRIBUTE_KEYS));
List<String> 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<String> disabledKeys = new HashSet<>(disabledAttibuteKeys);

ResourceBuilder builder =
resource.toBuilder().removeIf(attributeKey -> disabledKeys.contains(attributeKey.getKey()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,28 @@
class ResourceConfigurationTest {

@Test
void customConfigResource() {
void customConfigResourceWithDisabledKeys() {
Map<String, String> 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<String, String> props = new HashMap<>();
props.put("otel.service.name", "test-service");
props.put(
Expand Down
Loading