Remove ConfigPropertiesAdatpter as it's no longer needed
MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/config/Config.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/config/Config.java
@@ -13,7 +13,6 @@ import com.google.auto.value.AutoValue;
import java.time.Duration;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -96,7 +95,10 @@ public abstract class Config {
/**
* Returns a boolean-valued configuration property or {@code null} if a property with name {@code
* name} has not been configured.
+ *
+ * @deprecated Use the {@link #getBoolean(String, boolean)} variant instead.
*/
+ @Deprecated
@Nullable
public Boolean getBoolean(String name) {
return getTypedProperty(name, ConfigValueParsers::parseBoolean);
@@ -115,7 +117,9 @@ public abstract class Config {
* name} has not been configured.
*
* @throws ConfigParsingException if the property is not a valid integer.
+ * @deprecated Use the {@link #getInt(String, int)} variant instead.
*/
+ @Deprecated
@Nullable
public Integer getInt(String name) {
return getTypedProperty(name, ConfigValueParsers::parseInt);
@@ -135,7 +139,9 @@ public abstract class Config {
* name} has not been configured.
*
* @throws ConfigParsingException if the property is not a valid long.
+ * @deprecated Use the {@link #getLong(String, long)} variant instead.
*/
+ @Deprecated
@Nullable
public Long getLong(String name) {
return getTypedProperty(name, ConfigValueParsers::parseLong);
@@ -155,7 +161,9 @@ public abstract class Config {
* name} has not been configured.
*
* @throws ConfigParsingException if the property is not a valid long.
+ * @deprecated Use the {@link #getDouble(String, double)} variant instead.
*/
+ @Deprecated
@Nullable
public Double getDouble(String name) {
return getTypedProperty(name, ConfigValueParsers::parseDouble);
@@ -187,7 +195,9 @@ public abstract class Config {
* <p>If no unit is specified, milliseconds is the assumed duration unit.
*
* @throws ConfigParsingException if the property is not a valid long.
+ * @deprecated Use the {@link #getDuration(String, Duration)} variant instead.
*/
+ @Deprecated
@Nullable
public Duration getDuration(String name) {
return getTypedProperty(name, ConfigValueParsers::parseDuration);
@@ -218,7 +228,10 @@ public abstract class Config {
* Returns a list-valued configuration property or an empty list if a property with name {@code
* name} has not been configured. The format of the original value must be comma-separated, e.g.
* {@code one,two,three}.
+ *
+ * @deprecated Use the {@link #getList(String, List)} variant instead.
*/
+ @Deprecated
public List<String> getList(String name) {
List<String> list = getTypedProperty(name, ConfigValueParsers::parseList);
return list == null ? emptyList() : list;
@@ -240,7 +253,9 @@ public abstract class Config {
* key=value,anotherKey=anotherValue}.
*
* @throws ConfigParsingException if the property is not a valid long.
+ * @deprecated Use the {@link #getMap(String, Map)} variant instead.
*/
+ @Deprecated
public Map<String, String> getMap(String name) {
Map<String, String> map = getTypedProperty(name, ConfigValueParsers::parseMap);
return map == null ? emptyMap() : map;
@@ -305,16 +320,4 @@ public abstract class Config {
public boolean isAgentDebugEnabled() {
return getBoolean("otel.javaagent.debug", false);
}
-
- /**
- * Converts this config instance to Java {@link Properties}.
- *
- * @deprecated Use {@link #getAllProperties()} instead.
- */
- @Deprecated
- public Properties asJavaProperties() {
- Properties properties = new Properties();
- properties.putAll(getAllProperties());
- return properties;
- }
}

MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/PeerServiceAttributesExtractor.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/PeerServiceAttributesExtractor.java
package io.opentelemetry.instrumentation.api.instrumenter;
+import static java.util.Collections.emptyMap;
+
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
@@ -24,7 +26,7 @@ import javax.annotation.Nullable;
public final class PeerServiceAttributesExtractor<REQUEST, RESPONSE>
implements AttributesExtractor<REQUEST, RESPONSE> {
private static final Map<String, String> JAVAAGENT_PEER_SERVICE_MAPPING =
- Config.get().getMap("otel.instrumentation.common.peer-service-mapping");
+ Config.get().getMap("otel.instrumentation.common.peer-service-mapping", emptyMap());
private final Map<String, String> peerServiceMapping;
private final NetClientAttributesExtractor<REQUEST, RESPONSE> netClientAttributesExtractor;

MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/CapturedHttpHeaders.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/CapturedHttpHeaders.java
@@ -53,9 +53,11 @@ public abstract class CapturedHttpHeaders {
// fall back to the experimental properties if the stable one isn't supplied
return CapturedHttpHeaders.create(
config.getList(
- CLIENT_REQUEST_PROPERTY, config.getList(EXPERIMENTAL_CLIENT_REQUEST_PROPERTY)),
+ CLIENT_REQUEST_PROPERTY,
+ config.getList(EXPERIMENTAL_CLIENT_REQUEST_PROPERTY, emptyList())),
config.getList(
- CLIENT_RESPONSE_PROPERTY, config.getList(EXPERIMENTAL_CLIENT_RESPONSE_PROPERTY)));
+ CLIENT_RESPONSE_PROPERTY,
+ config.getList(EXPERIMENTAL_CLIENT_RESPONSE_PROPERTY, emptyList())));
}
private static final String SERVER_REQUEST_PROPERTY =
@@ -77,9 +79,11 @@ public abstract class CapturedHttpHeaders {
// fall back to the experimental properties if the stable one isn't supplied
return CapturedHttpHeaders.create(
config.getList(
- SERVER_REQUEST_PROPERTY, config.getList(EXPERIMENTAL_SERVER_REQUEST_PROPERTY)),
+ SERVER_REQUEST_PROPERTY,
+ config.getList(EXPERIMENTAL_SERVER_REQUEST_PROPERTY, emptyList())),
config.getList(
- SERVER_RESPONSE_PROPERTY, config.getList(EXPERIMENTAL_SERVER_RESPONSE_PROPERTY)));
+ SERVER_RESPONSE_PROPERTY,
+ config.getList(EXPERIMENTAL_SERVER_RESPONSE_PROPERTY, emptyList())));
}
/**

MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/net/NetPeerAttributes.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/net/NetPeerAttributes.java
package io.opentelemetry.instrumentation.api.tracer.net;
+import static java.util.Collections.emptyMap;
+
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.instrumentation.api.config.Config;
@@ -12,7 +14,6 @@ import io.opentelemetry.instrumentation.api.tracer.AttributeSetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.InetAddress;
import java.net.InetSocketAddress;
-import java.util.Collections;
import java.util.Map;
import javax.annotation.Nullable;
@@ -28,12 +29,12 @@ public final class NetPeerAttributes {
public static final NetPeerAttributes INSTANCE =
new NetPeerAttributes(
- Config.get().getMap("otel.instrumentation.common.peer-service-mapping"));
+ Config.get().getMap("otel.instrumentation.common.peer-service-mapping", emptyMap()));
private final Map<String, String> peerServiceMapping;
public NetPeerAttributes() {
- this(Collections.emptyMap());
+ this(emptyMap());
}
public NetPeerAttributes(Map<String, String> peerServiceMapping) {

MODIFY
instrumentation/executors/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/javaconcurrent/AbstractExecutorInstrumentation.java
instrumentation/executors/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/javaconcurrent/AbstractExecutorInstrumentation.java
package io.opentelemetry.javaagent.instrumentation.javaconcurrent;
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface;
+import static java.util.Collections.emptyList;
import static net.bytebuddy.matcher.ElementMatchers.any;
import static net.bytebuddy.matcher.ElementMatchers.named;
@@ -99,7 +100,7 @@ public abstract class AbstractExecutorInstrumentation implements TypeInstrumenta
"scala.concurrent.impl.ExecutionContextImpl",
};
Set<String> combined = new HashSet<>(Arrays.asList(includeExecutors));
- combined.addAll(Config.get().getList(EXECUTORS_INCLUDE_PROPERTY_NAME));
+ combined.addAll(Config.get().getList(EXECUTORS_INCLUDE_PROPERTY_NAME, emptyList()));
this.includeExecutors = Collections.unmodifiableSet(combined);
String[] includePrefixes = {"slick.util.AsyncExecutor$"};

MODIFY
instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletRequestParametersExtractor.java
instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletRequestParametersExtractor.java
package io.opentelemetry.javaagent.instrumentation.servlet;
+import static java.util.Collections.emptyList;
+
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.instrumentation.api.config.Config;
@@ -20,7 +22,9 @@ public class ServletRequestParametersExtractor<REQUEST, RESPONSE>
implements AttributesExtractor<
ServletRequestContext<REQUEST>, ServletResponseContext<RESPONSE>> {
private static final List<String> CAPTURE_REQUEST_PARAMETERS =
- Config.get().getList("otel.instrumentation.servlet.experimental.capture-request-parameters");
+ Config.get()
+ .getList(
+ "otel.instrumentation.servlet.experimental.capture-request-parameters", emptyList());
private static final ConcurrentMap<String, AttributeKey<List<String>>> parameterKeysCache =
new ConcurrentHashMap<>();

DELETE
javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/config/ConfigPropertiesAdapter.java
-/*
- * Copyright The OpenTelemetry Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package io.opentelemetry.javaagent.tooling.config;
-
-import io.opentelemetry.instrumentation.api.config.Config;
-import io.opentelemetry.instrumentation.api.config.ConfigParsingException;
-import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
-import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
-import java.time.Duration;
-import java.util.List;
-import java.util.Map;
-import javax.annotation.Nullable;
-
-public final class ConfigPropertiesAdapter implements ConfigProperties {
- private final Config config;
-
- public ConfigPropertiesAdapter(Config config) {
- this.config = config;
- }
-
- @Nullable
- @Override
- public String getString(String name) {
- return config.getString(name);
- }
-
- @Nullable
- @Override
- public Boolean getBoolean(String name) {
- return config.getBoolean(name);
- }
-
- @Nullable
- @Override
- public Integer getInt(String name) {
- try {
- return config.getInt(name);
- } catch (ConfigParsingException e) {
- throw new ConfigurationException(e.getMessage(), e);
- }
- }
-
- @Nullable
- @Override
- public Long getLong(String name) {
- try {
- return config.getLong(name);
- } catch (ConfigParsingException e) {
- throw new ConfigurationException(e.getMessage(), e);
- }
- }
-
- @Nullable
- @Override
- public Double getDouble(String name) {
- try {
- return config.getDouble(name);
- } catch (ConfigParsingException e) {
- throw new ConfigurationException(e.getMessage(), e);
- }
- }
-
- @Nullable
- @Override
- public Duration getDuration(String name) {
- try {
- return config.getDuration(name);
- } catch (ConfigParsingException e) {
- throw new ConfigurationException(e.getMessage(), e);
- }
- }
-
- @Override
- public List<String> getList(String name) {
- return config.getList(name);
- }
-
- @Override
- public Map<String, String> getMap(String name) {
- try {
- return config.getMap(name);
- } catch (ConfigParsingException e) {
- throw new ConfigurationException(e.getMessage(), e);
- }
- }
-}

MODIFY
javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/ignore/UserExcludedClassesConfigurer.java
javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/ignore/UserExcludedClassesConfigurer.java
package io.opentelemetry.javaagent.tooling.ignore;
+import static java.util.Collections.emptyList;
+
import com.google.auto.service.AutoService;
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.javaagent.extension.ignore.IgnoredTypesBuilder;
@@ -19,7 +21,7 @@ public class UserExcludedClassesConfigurer implements IgnoredTypesConfigurer {
@Override
public void configure(Config config, IgnoredTypesBuilder builder) {
- List<String> excludedClasses = config.getList(EXCLUDED_CLASSES_CONFIG);
+ List<String> excludedClasses = config.getList(EXCLUDED_CLASSES_CONFIG, emptyList());
for (String excludedClass : excludedClasses) {
excludedClass = excludedClass.trim();
// remove the trailing *

DELETE
javaagent-tooling/src/test/java/io/opentelemetry/javaagent/tooling/config/ConfigPropertiesAdapterTest.java
-/*
- * Copyright The OpenTelemetry Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package io.opentelemetry.javaagent.tooling.config;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.assertj.core.api.Assertions.entry;
-
-import io.opentelemetry.instrumentation.api.config.Config;
-import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
-import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
-import java.time.Duration;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import org.junit.jupiter.api.Test;
-
-// Copied from
-// https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/ConfigPropertiesTest.java
-class ConfigPropertiesAdapterTest {
-
- @Test
- void allValid() {
- Map<String, String> properties = new HashMap<>();
- properties.put("string", "str");
- properties.put("int", "10");
- properties.put("long", "20");
- properties.put("double", "5.4");
- properties.put("list", "cat,dog,bear");
- properties.put("map", "cat=meow,dog=bark,bear=growl");
- properties.put("mapWithEmptyValue", "cat=meow,dog=,bear=growl");
- properties.put("duration", "1s");
-
- ConfigProperties config = createConfig(properties);
- assertThat(config.getString("string")).isEqualTo("str");
- assertThat(config.getInt("int")).isEqualTo(10);
- assertThat(config.getLong("long")).isEqualTo(20);
- assertThat(config.getDouble("double")).isEqualTo(5.4);
- assertThat(config.getList("list")).containsExactly("cat", "dog", "bear");
- assertThat(config.getMap("map"))
- .containsExactly(entry("cat", "meow"), entry("dog", "bark"), entry("bear", "growl"));
- assertThat(config.getMap("mapWithEmptyValue"))
- .containsExactly(entry("cat", "meow"), entry("dog", ""), entry("bear", "growl"));
- assertThat(config.getDuration("duration")).isEqualTo(Duration.ofSeconds(1));
- }
-
- @Test
- void allMissing() {
- ConfigProperties config = createConfig(Collections.emptyMap());
- assertThat(config.getString("string")).isNull();
- assertThat(config.getInt("int")).isNull();
- assertThat(config.getLong("long")).isNull();
- assertThat(config.getDouble("double")).isNull();
- assertThat(config.getList("list")).isEmpty();
- assertThat(config.getMap("map")).isEmpty();
- assertThat(config.getDuration("duration")).isNull();
- }
-
- @Test
- void allEmpty() {
- Map<String, String> properties = new HashMap<>();
- properties.put("string", "");
- properties.put("int", "");
- properties.put("long", "");
- properties.put("double", "");
- properties.put("list", "");
- properties.put("map", "");
- properties.put("duration", "");
-
- ConfigProperties config = createConfig(properties);
- assertThat(config.getString("string")).isEmpty();
- assertThat(config.getInt("int")).isNull();
- assertThat(config.getLong("long")).isNull();
- assertThat(config.getDouble("double")).isNull();
- assertThat(config.getList("list")).isEmpty();
- assertThat(config.getMap("map")).isEmpty();
- assertThat(config.getDuration("duration")).isNull();
- }
-
- @Test
- void invalidInt() {
- assertThatThrownBy(() -> createConfig(Collections.singletonMap("int", "bar")).getInt("int"))
- .isInstanceOf(ConfigurationException.class)
- .hasMessage("Invalid value for property int=bar. Must be a integer.");
- assertThatThrownBy(
- () -> createConfig(Collections.singletonMap("int", "999999999999999")).getInt("int"))
- .isInstanceOf(ConfigurationException.class)
- .hasMessage("Invalid value for property int=999999999999999. Must be a integer.");
- }
-
- @Test
- void invalidLong() {
- assertThatThrownBy(() -> createConfig(Collections.singletonMap("long", "bar")).getLong("long"))
- .isInstanceOf(ConfigurationException.class)
- .hasMessage("Invalid value for property long=bar. Must be a long.");
- assertThatThrownBy(
- () ->
- createConfig(Collections.singletonMap("long", "99223372036854775807"))
- .getLong("long"))
- .isInstanceOf(ConfigurationException.class)
- .hasMessage("Invalid value for property long=99223372036854775807. Must be a long.");
- }
-
- @Test
- void invalidDouble() {
- assertThatThrownBy(
- () -> createConfig(Collections.singletonMap("double", "bar")).getDouble("double"))
- .isInstanceOf(ConfigurationException.class)
- .hasMessage("Invalid value for property double=bar. Must be a double.");
- assertThatThrownBy(
- () -> createConfig(Collections.singletonMap("double", "1.0.1")).getDouble("double"))
- .isInstanceOf(ConfigurationException.class)
- .hasMessage("Invalid value for property double=1.0.1. Must be a double.");
- }
-
- @Test
- void uncleanList() {
- assertThat(
- createConfig(Collections.singletonMap("list", " a ,b,c , d,, ,")).getList("list"))
- .containsExactly("a", "b", "c", "d");
- }
-
- @Test
- void uncleanMap() {
- assertThat(
- createConfig(Collections.singletonMap("map", " a=1 ,b=2,c = 3 , d= 4,, ,"))
- .getMap("map"))
- .containsExactly(entry("a", "1"), entry("b", "2"), entry("c", "3"), entry("d", "4"));
- }
-
- @Test
- void invalidMap() {
- assertThatThrownBy(() -> createConfig(Collections.singletonMap("map", "a=1,b")).getMap("map"))
- .isInstanceOf(ConfigurationException.class)
- .hasMessage("Invalid map property: map=a=1,b");
- assertThatThrownBy(() -> createConfig(Collections.singletonMap("map", "a=1,=b")).getMap("map"))
- .isInstanceOf(ConfigurationException.class)
- .hasMessage("Invalid map property: map=a=1,=b");
- }
-
- @Test
- void invalidDuration() {
- assertThatThrownBy(
- () ->
- createConfig(Collections.singletonMap("duration", "1a1ms")).getDuration("duration"))
- .isInstanceOf(ConfigurationException.class)
- .hasMessage("Invalid duration property duration=1a1ms. Expected number, found: 1a1");
- assertThatThrownBy(
- () -> createConfig(Collections.singletonMap("duration", "9mm")).getDuration("duration"))
- .isInstanceOf(ConfigurationException.class)
- .hasMessage("Invalid duration property duration=9mm. Invalid duration string, found: mm");
- }
-
- @Test
- void durationUnitParsing() {
- assertThat(createConfig(Collections.singletonMap("duration", "1")).getDuration("duration"))
- .isEqualTo(Duration.ofMillis(1));
- assertThat(createConfig(Collections.singletonMap("duration", "2ms")).getDuration("duration"))
- .isEqualTo(Duration.ofMillis(2));
- assertThat(createConfig(Collections.singletonMap("duration", "3s")).getDuration("duration"))
- .isEqualTo(Duration.ofSeconds(3));
- assertThat(createConfig(Collections.singletonMap("duration", "4m")).getDuration("duration"))
- .isEqualTo(Duration.ofMinutes(4));
- assertThat(createConfig(Collections.singletonMap("duration", "5h")).getDuration("duration"))
- .isEqualTo(Duration.ofHours(5));
- assertThat(createConfig(Collections.singletonMap("duration", "6d")).getDuration("duration"))
- .isEqualTo(Duration.ofDays(6));
- // Check Space handling
- assertThat(createConfig(Collections.singletonMap("duration", "7 ms")).getDuration("duration"))
- .isEqualTo(Duration.ofMillis(7));
- assertThat(createConfig(Collections.singletonMap("duration", "8 ms")).getDuration("duration"))
- .isEqualTo(Duration.ofMillis(8));
- }
-
- private static ConfigProperties createConfig(Map<String, String> properties) {
- return new ConfigPropertiesAdapter(Config.builder().readProperties(properties).build());
- }
-}

Remove ConfigPropertiesAdatpter as it's no longer needed (#4888)