Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.context.propagation.TextMapGetter;
import io.opentelemetry.context.propagation.TextMapSetter;
import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil;
import io.opentelemetry.instrumentation.api.internal.DeprecatedLibraryConfigPropertiesUtil;
import io.opentelemetry.instrumentation.api.internal.EmbeddedInstrumentationProperties;
import io.opentelemetry.instrumentation.api.internal.Experimental;
import io.opentelemetry.instrumentation.api.internal.InstrumenterBuilderAccess;
Expand Down Expand Up @@ -386,10 +386,12 @@ private String getSpanSuppressionStrategy() {
.getConfigProvider()
.getInstrumentationConfig("common");
}

@SuppressWarnings("deprecation") // using deprecated config property
String result =
commonConfig.getString(
"span_suppression_strategy/development",
ConfigPropertiesUtil.getString(
DeprecatedLibraryConfigPropertiesUtil.getString(
"otel.instrumentation.experimental.span-suppression-strategy", ""));
return result.isEmpty() ? null : result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@

package io.opentelemetry.instrumentation.api.internal;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import javax.annotation.Nullable;

/**
Expand All @@ -25,40 +22,8 @@ public final class ConfigPropertiesUtil {
* to support Declarative Config.
*/
public static boolean getBoolean(String propertyName, boolean defaultValue) {
Boolean value = getBoolean(propertyName);
return value == null ? defaultValue : value;
}

/**
* Returns the boolean value of the given property name from system properties and environment
* variables.
*
* <p>It's recommended to use {@link io.opentelemetry.api.incubator.config.ConfigProvider} instead
* to support Declarative Config.
*/
@Nullable
public static Boolean getBoolean(String propertyName) {
String strValue = getString(propertyName);
return strValue == null ? null : Boolean.parseBoolean(strValue);
}

/**
* Returns the int value of the given property name from system properties and environment
* variables.
*
* <p>It's recommended to use {@link io.opentelemetry.api.incubator.config.ConfigProvider} instead
* to support Declarative Config.
*/
public static int getInt(String propertyName, int defaultValue) {
String strValue = getString(propertyName);
if (strValue == null) {
return defaultValue;
}
try {
return Integer.parseInt(strValue);
} catch (NumberFormatException ignored) {
return defaultValue;
}
String value = getString(propertyName);
return value == null ? defaultValue : Boolean.parseBoolean(value);
}

/**
Expand All @@ -77,41 +42,6 @@ public static String getString(String propertyName) {
return System.getenv(toEnvVarName(propertyName));
}

/**
* Returns the string value of the given property name from system properties and environment
* variables, or the default value if not found.
*
* <p>It's recommended to use {@link io.opentelemetry.api.incubator.config.ConfigProvider} instead
* to support Declarative Config.
*/
public static String getString(String propertyName, String defaultValue) {
String strValue = getString(propertyName);
return strValue == null ? defaultValue : strValue;
}

/**
* Returns the list of strings value of the given property name from system properties and
* environment variables, or the default value if not found. The property value is expected to be
* a comma-separated list.
*
* <p>It's recommended to use {@link io.opentelemetry.api.incubator.config.ConfigProvider} instead
* to support Declarative Config.
*/
public static List<String> getList(String propertyName, List<String> defaultValue) {
String value = getString(propertyName);
if (value == null) {
return defaultValue;
}
return filterBlanksAndNulls(value.split(","));
}

private static List<String> filterBlanksAndNulls(String[] values) {
return Arrays.stream(values)
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.toList());
}

private static String toEnvVarName(String propertyName) {
return propertyName.toUpperCase(Locale.ROOT).replace('-', '_').replace('.', '_');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ public final class ContextPropagationDebug {
private static final boolean FAIL_ON_CONTEXT_LEAK;

static {
boolean agentDebugEnabled = ConfigPropertiesUtil.getBoolean("otel.javaagent.debug", false);
THREAD_PROPAGATION_DEBUGGER = isDebuggerEnabled();
FAIL_ON_CONTEXT_LEAK = Boolean.getBoolean("otel.javaagent.testing.fail-on-context-leak");
}

THREAD_PROPAGATION_DEBUGGER =
ConfigPropertiesUtil.getBoolean(
"otel.javaagent.experimental.thread-propagation-debugger.enabled", agentDebugEnabled);
FAIL_ON_CONTEXT_LEAK =
ConfigPropertiesUtil.getBoolean("otel.javaagent.testing.fail-on-context-leak", false);
private static boolean isDebuggerEnabled() {
String enabled =
System.getProperty("otel.javaagent.testing.thread-propagation-debugger.enabled");
if (enabled != null) {
return Boolean.parseBoolean(enabled);
}
return ConfigPropertiesUtil.getBoolean("otel.javaagent.debug", false);
}

// context to which debug locations were added
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.api.internal;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import javax.annotation.Nullable;

/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class DeprecatedLibraryConfigPropertiesUtil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see what we gain from this change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it allows the methods to be deprecated - this has caused some confusion in a previous PR

@trask fyi

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think things are getting clearer now and we could avoid the rename and instead deprecate it saying will be removed in 3.0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a rename - the class is split to distinguish the cases that are deprecated from the ones we still need in the future (which are few, but it's still confusing to understand right now)


/**
* Returns the boolean value of the given property name from system properties and environment
* variables.
*
* @deprecated allows library configuration via system properties and environment variables, which
* will be removed in 3.0.
*/
@Deprecated
public static boolean getBoolean(String propertyName, boolean defaultValue) {
Boolean value = getBoolean(propertyName);
return value == null ? defaultValue : value;
}

/**
* Returns the boolean value of the given property name from system properties and environment
* variables.
*
* @deprecated allows library configuration via system properties and environment variables, which
* will be removed in 3.0.
*/
@Nullable
@Deprecated
public static Boolean getBoolean(String propertyName) {
String strValue = getString(propertyName);
return strValue == null ? null : Boolean.parseBoolean(strValue);
}

/**
* Returns the string value of the given property name from system properties and environment
* variables.
*
* @deprecated allows library configuration via system properties and environment variables, which
* will be removed in 3.0.
*/
@Nullable
@Deprecated
private static String getString(String propertyName) {
String value = System.getProperty(propertyName);
if (value != null) {
return value;
}
return System.getenv(toEnvVarName(propertyName));
}

/**
* Returns the string value of the given property name from system properties and environment
* variables, or the default value if not found.
*
* @deprecated allows library configuration via system properties and environment variables, which
* will be removed in 3.0.
*/
@Deprecated
public static String getString(String propertyName, String defaultValue) {
String strValue = getString(propertyName);
return strValue == null ? defaultValue : strValue;
}

/**
* Returns the list of strings value of the given property name from system properties and
* environment variables, or the default value if not found. The property value is expected to be
* a comma-separated list.
*
* @deprecated allows library configuration via system properties and environment variables, which
* will be removed in 3.0.
*/
@Deprecated
public static List<String> getList(String propertyName, List<String> defaultValue) {
String value = getString(propertyName);
if (value == null) {
return defaultValue;
}
return filterBlanksAndNulls(value.split(","));
}

private static List<String> filterBlanksAndNulls(String[] values) {
return Arrays.stream(values)
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.toList());
}

private static String toEnvVarName(String propertyName) {
return propertyName.toUpperCase(Locale.ROOT).replace('-', '_').replace('.', '_');
}

private DeprecatedLibraryConfigPropertiesUtil() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,6 @@ void getString_none() {
assertThat(ConfigPropertiesUtil.getString("test.property.string")).isNull();
}

@SetEnvironmentVariable(key = "TEST_PROPERTY_INT", value = "12")
@SetSystemProperty(key = "test.property.int", value = "42")
@Test
void getInt_systemProperty() {
assertThat(ConfigPropertiesUtil.getInt("test.property.int", -1)).isEqualTo(42);
}

@SetEnvironmentVariable(key = "TEST_PROPERTY_INT", value = "12")
@Test
void getInt_environmentVariable() {
assertThat(ConfigPropertiesUtil.getInt("test.property.int", -1)).isEqualTo(12);
}

@Test
void getInt_none() {
assertThat(ConfigPropertiesUtil.getInt("test.property.int", -1)).isEqualTo(-1);
}

@SetSystemProperty(key = "test.property.int", value = "not a number")
@Test
void getInt_invalidNumber() {
assertThat(ConfigPropertiesUtil.getInt("test.property.int", -1)).isEqualTo(-1);
}

@SetEnvironmentVariable(key = "TEST_PROPERTY_BOOLEAN", value = "false")
@SetSystemProperty(key = "test.property.boolean", value = "true")
@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.api.internal;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.SetEnvironmentVariable;
import org.junitpioneer.jupiter.SetSystemProperty;

@SuppressWarnings("deprecation") // using deprecated config property
class DeprecatedLibraryConfigPropertiesUtilTest {

@SetEnvironmentVariable(key = "TEST_PROPERTY_BOOLEAN", value = "false")
@SetSystemProperty(key = "test.property.boolean", value = "true")
@Test
void getBoolean_systemProperty() {
assertThat(DeprecatedLibraryConfigPropertiesUtil.getBoolean("test.property.boolean", false))
.isTrue();
}

@SetEnvironmentVariable(key = "TEST_PROPERTY_BOOLEAN", value = "true")
@Test
void getBoolean_environmentVariable() {
assertThat(DeprecatedLibraryConfigPropertiesUtil.getBoolean("test.property.boolean", false))
.isTrue();
}

@Test
void getBoolean_none() {
assertThat(DeprecatedLibraryConfigPropertiesUtil.getBoolean("test.property.boolean", false))
.isFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.instrumentation.api.incubator.config.internal.DeclarativeConfigUtil;
import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil;
import io.opentelemetry.instrumentation.api.internal.DeprecatedLibraryConfigPropertiesUtil;
import io.opentelemetry.instrumentation.awssdk.v1_11.AwsSdkTelemetry;

/**
Expand All @@ -25,6 +25,7 @@ public class TracingRequestHandler extends RequestHandler2 {

private static final RequestHandler2 DELEGATE = buildDelegate(GlobalOpenTelemetry.get());

@SuppressWarnings("deprecation") // using deprecated config property
private static RequestHandler2 buildDelegate(OpenTelemetry openTelemetry) {
DeclarativeConfigProperties messaging =
DeclarativeConfigUtil.getInstrumentationConfig(openTelemetry, "common").get("messaging");
Expand All @@ -33,21 +34,21 @@ private static RequestHandler2 buildDelegate(OpenTelemetry openTelemetry) {
DeclarativeConfigUtil.getInstrumentationConfig(openTelemetry, "aws_sdk")
.getBoolean(
"experimental_span_attributes/development",
ConfigPropertiesUtil.getBoolean(
DeprecatedLibraryConfigPropertiesUtil.getBoolean(
"otel.instrumentation.aws-sdk.experimental-span-attributes", false)))
.setMessagingReceiveTelemetryEnabled(
messaging
.get("receive_telemetry/development")
.getBoolean(
"enabled",
ConfigPropertiesUtil.getBoolean(
DeprecatedLibraryConfigPropertiesUtil.getBoolean(
"otel.instrumentation.messaging.experimental.receive-telemetry.enabled",
false)))
.setCapturedHeaders(
messaging.getScalarList(
"capture_headers/development",
String.class,
ConfigPropertiesUtil.getList(
DeprecatedLibraryConfigPropertiesUtil.getList(
"otel.instrumentation.messaging.experimental.capture-headers", emptyList())))
.build()
.createRequestHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.instrumentation.api.incubator.config.internal.DeclarativeConfigUtil;
import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil;
import io.opentelemetry.instrumentation.api.internal.DeprecatedLibraryConfigPropertiesUtil;
import io.opentelemetry.instrumentation.awssdk.v2_2.AwsSdkTelemetry;
import java.util.List;

Expand Down Expand Up @@ -81,12 +81,16 @@ private static AwsSdkTelemetry telemetry(boolean useLegacyLibraryConfig) {
.build();
}

@SuppressWarnings("deprecation") // using deprecated config property
private List<String> legacyListValue(String key) {
return useLegacyLibraryConfig ? ConfigPropertiesUtil.getList(key, emptyList()) : emptyList();
return useLegacyLibraryConfig
? DeprecatedLibraryConfigPropertiesUtil.getList(key, emptyList())
: emptyList();
}

@SuppressWarnings("deprecation") // using deprecated config property
private boolean legacyBooleanValue(String key) {
return useLegacyLibraryConfig && ConfigPropertiesUtil.getBoolean(key, false);
return useLegacyLibraryConfig && DeprecatedLibraryConfigPropertiesUtil.getBoolean(key, false);
}

private AwsSdkTelemetryFactory(boolean useLegacyLibraryConfig) {
Expand Down
Loading
Loading