Skip to content
Open
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 @@ -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 @@ -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 DebugUtil.isAgentDebugEnabled();
}

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

package io.opentelemetry.instrumentation.api.internal;

/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public class DebugUtil {

static boolean isAgentDebugEnabled() {
return Boolean.parseBoolean(SemconvStability.getString("otel.javaagent.debug"));
}

private DebugUtil() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class ConfigPropertiesUtil {
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)

Copy link
Member

Choose a reason for hiding this comment

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

the ones we still need in the future

which ones are these?

I looked and only found otel.semconv-stability.opt-in?

Copy link
Member Author

Choose a reason for hiding this comment

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

direct usages

Class
    ConfigPropertiesUtil
Usages in All Places  (15 usages found)
    Production  (9 usages found)
        Class static member access  (9 usages found)
            instrumentation-api  (3 usages found)
                src  (3 usages found)
                    main  (3 usages found)
                        java  (3 usages found)
                            io  (3 usages found)
                                opentelemetry  (3 usages found)
                                    instrumentation  (3 usages found)
                                        api  (3 usages found)
                                            internal  (3 usages found)
                                                ContextPropagationDebug  (1 usage found)
                                                    isDebuggerEnabled()  (1 usage found)
                                                        45 return ConfigPropertiesUtil.getBoolean("otel.javaagent.debug", false);
                                                SemconvStability  (1 usage found)
                                                    34 String value = ConfigPropertiesUtil.getString("otel.semconv-stability.opt-in");
                                                SupportabilityMetrics  (1 usage found)
                                                    33 ConfigPropertiesUtil.getBoolean("otel.javaagent.debug", false), logger::fine)
            javaagent-bootstrap  (2 usages found)
                src  (2 usages found)
                    main  (2 usages found)
                        java  (2 usages found)
                            io  (2 usages found)
                                opentelemetry  (2 usages found)
                                    javaagent  (2 usages found)
                                        bootstrap  (2 usages found)
                                            AgentClassLoader  (1 usage found)
                                                49 ConfigPropertiesUtil.getString("otel.javaagent.experimental.initializer.jar");
                                            AgentInitializer  (1 usage found)
                                                getBoolean(String, boolean)  (1 usage found)
                                                    97 return ConfigPropertiesUtil.getBoolean(property, defaultValue);
            javaagent-tooling  (4 usages found)
                src  (4 usages found)
                    main  (4 usages found)
                        java  (4 usages found)
                            io  (4 usages found)
                                opentelemetry  (4 usages found)
                                    javaagent  (4 usages found)
                                        tooling  (4 usages found)
                                            config  (4 usages found)
                                                ConfigurationFile  (1 usage found)
                                                    loadConfigFile()  (1 usage found)
                                                        50 String configurationFilePath = ConfigPropertiesUtil.getString(CONFIGURATION_FILE_PROPERTY);
                                                EarlyInitAgentConfig  (3 usages found)
                                                    getString(String)  (1 usage found)
                                                        59 String value = ConfigPropertiesUtil.getString(propertyName);
                                                    getBoolean(String, boolean)  (1 usage found)
                                                        70 return ConfigPropertiesUtil.getBoolean(propertyName, configFileValue);
                                                    getInt(String, int)  (1 usage found)
                                                        75 String value = ConfigPropertiesUtil.getString(propertyName);
  • "otel.javaagent.debug" can't use EarlyInitAgentConfig.isDebug, because it's not accessible
  • AgentInitializer is used for "otel.javaagent.experimental.security-manager-support.enabled"
  • All usages in EarlyInitAgentConfig
  @Nullable
  public String getLogging() {
    return getString("otel.javaagent.logging");
  }

  @Nullable
  public String getExtensions() {
    return getString("otel.javaagent.extensions");
  }

  public boolean isDebug() {
    return getBoolean("otel.javaagent.debug", false);
  }

  public boolean isEnabled() {
    return getBoolean("otel.javaagent.enabled", true);
  }

  public boolean isExperimentalFieldInjectionEnabled() {
    return getBoolean("otel.javaagent.experimental.field-injection.enabled", true);
  }

  public int getLoggingApplicationLogsBufferMaxRecords() {
    return getInt("otel.javaagent.logging.application.logs-buffer-max-records", 2048);
  }

Copy link
Member

Choose a reason for hiding this comment

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

If it's only needed in the future for javaagent properties then we could make a non-deprecated copy in the javaagent module (don't need it in instrumentation-api)

Copy link
Member Author

Choose a reason for hiding this comment

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

yes that would work if we find a solution for "otel.javaagent.debug" and "otel.semconv-stability.opt-in"

Copy link
Member

Choose a reason for hiding this comment

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

otel.javaagent.debug usages should be using EarlyInitAgentConfig instead of ConfigPropertiesUtil?

otel.semconv-stability.opt-in if this is the only usage in the one place, then let's just hardcode get system property and get env var there, no need for normalizing logic

Copy link
Member Author

Choose a reason for hiding this comment

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

we use otel.javaagent.debug in intrumentation-api - but we can make a dedicated copy for that as well - I'll try that out.


/**
* 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.
* @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;
Expand All @@ -33,43 +34,26 @@ public static boolean getBoolean(String propertyName, boolean defaultValue) {
* 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.
* @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 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;
}
}

/**
* Returns the string 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.
* @deprecated allows library configuration via system properties and environment variables, which
* will be removed in 3.0.
*/
@Nullable
public static String getString(String propertyName) {
@Deprecated
private static String getString(String propertyName) {
String value = System.getProperty(propertyName);
if (value != null) {
return value;
Expand All @@ -81,9 +65,10 @@ public static String getString(String 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.
* @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;
Expand All @@ -94,9 +79,10 @@ public static String getString(String propertyName, String defaultValue) {
* 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.
* @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) {
Expand All @@ -116,5 +102,5 @@ private static String toEnvVarName(String propertyName) {
return propertyName.toUpperCase(Locale.ROOT).replace('-', '_').replace('.', '_');
}

private ConfigPropertiesUtil() {}
private DeprecatedLibraryConfigPropertiesUtil() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

Expand All @@ -31,7 +32,7 @@ public final class SemconvStability {
boolean oldCode = true;
boolean stableCode = false;

String value = ConfigPropertiesUtil.getString("otel.semconv-stability.opt-in");
String value = getString("otel.semconv-stability.opt-in");
if (value != null) {
Set<String> values = new HashSet<>(asList(value.split(",")));

Expand Down Expand Up @@ -64,6 +65,18 @@ public final class SemconvStability {
emitStableCodeSemconv = stableCode;
}

static String getString(String propertyName) {
String value = System.getProperty(propertyName);
if (value != null) {
return value;
}
return System.getenv(toEnvVarName(propertyName));
}

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

public static boolean emitOldDatabaseSemconv() {
return emitOldDatabaseSemconv;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public final class SupportabilityMetrics {
private final ConcurrentMap<String, AtomicLong> counters = new ConcurrentHashMap<>();

private static final SupportabilityMetrics INSTANCE =
new SupportabilityMetrics(
ConfigPropertiesUtil.getBoolean("otel.javaagent.debug", false), logger::fine)
.start();
new SupportabilityMetrics(DebugUtil.isAgentDebugEnabled(), logger::fine).start();

public static SupportabilityMetrics instance() {
return INSTANCE;
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

import com.google.common.collect.ImmutableMap;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
Expand Down Expand Up @@ -99,9 +98,9 @@ public abstract class AbstractAws2ClientCoreTest {
protected abstract ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder();

protected static boolean isSqsAttributeInjectionEnabled() {
// See io.opentelemetry.instrumentation.awssdk.v2_2.autoconfigure.TracingExecutionInterceptor
return ConfigPropertiesUtil.getBoolean(
"otel.instrumentation.aws-sdk.experimental-use-propagator-for-messaging", false);
// See io.opentelemetry.instrumentation.awssdk.v2_2.internal.AwsSdkTelemetryFactory
return Boolean.getBoolean(
"otel.instrumentation.aws-sdk.experimental-use-propagator-for-messaging");
}

protected void configureSdkClient(SdkClientBuilder<?, ?> builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import static java.util.Collections.singletonList;

import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.testing.internal.armeria.common.HttpResponse;
import io.opentelemetry.testing.internal.armeria.common.HttpStatus;
Expand Down Expand Up @@ -124,9 +123,9 @@ private static void cleanResponses() {
}

public boolean isRecordIndividualHttpErrorEnabled() {
// See io.opentelemetry.instrumentation.awssdk.v2_2.autoconfigure.TracingExecutionInterceptor
return ConfigPropertiesUtil.getBoolean(
"otel.instrumentation.aws-sdk.experimental-record-individual-http-error", false);
// See io.opentelemetry.instrumentation.awssdk.v2_2.internal.AwsSdkTelemetryFactory
return Boolean.getBoolean(
"otel.instrumentation.aws-sdk.experimental-record-individual-http-error");
}

@SuppressWarnings("deprecation") // using deprecated semconv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
import io.opentelemetry.sdk.trace.data.SpanData;
Expand Down Expand Up @@ -130,9 +129,9 @@ protected void configureSdkClient(SqsAsyncClientBuilder builder) throws URISynta
}

protected boolean isSqsAttributeInjectionEnabled() {
// See io.opentelemetry.instrumentation.awssdk.v2_2.autoconfigure.TracingExecutionInterceptor
return ConfigPropertiesUtil.getBoolean(
"otel.instrumentation.aws-sdk.experimental-use-propagator-for-messaging", false);
// See io.opentelemetry.instrumentation.awssdk.v2_2.internal.AwsSdkTelemetryFactory
return Boolean.getBoolean(
"otel.instrumentation.aws-sdk.experimental-use-propagator-for-messaging");
}

@BeforeAll
Expand Down
Loading
Loading