Skip to content

Commit

Permalink
wip: stabilizing disabled keys from experimental.
Browse files Browse the repository at this point in the history
  • Loading branch information
vasantteja committed Oct 21, 2024
1 parent 680c940 commit 0ff2da7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
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";

/**
* 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. 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 @@ -112,7 +112,8 @@ void createEnvironmentResource_EmptyResourceAttributes() {
@Test
void filterAttributes() {
ConfigProperties configProperties =
DefaultConfigProperties.createFromMap(ImmutableMap.of(DISABLED_ATTRIBUTE_KEYS, "foo,bar"));
DefaultConfigProperties.createFromMap(
ImmutableMap.of(DISABLED_ATTRIBUTE_KEYS, "foo,bar"));

Resource resourceNoSchema =
Resource.builder().put("foo", "val").put("bar", "val").put("baz", "val").build();
Expand Down

0 comments on commit 0ff2da7

Please sign in to comment.