Skip to content

Commit

Permalink
Deprecate Config (open-telemetry#6360)
Browse files Browse the repository at this point in the history
* Deprecate Config

* suppress deprecation on ConfigTest
  • Loading branch information
Mateusz Rzeszutek authored and LironKS committed Oct 23, 2022
1 parent 11cc018 commit c58ef0a
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.Map;
Expand All @@ -22,8 +21,6 @@
*/
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", emptyMap());

private final NetClientAttributesGetter<REQUEST, RESPONSE> attributesGetter;
private final Map<String, String> peerServiceMapping;
Expand All @@ -45,7 +42,10 @@ public final class PeerServiceAttributesExtractor<REQUEST, RESPONSE>
@Deprecated
public static <REQUEST, RESPONSE> PeerServiceAttributesExtractor<REQUEST, RESPONSE> create(
NetClientAttributesGetter<REQUEST, RESPONSE> attributesGetter) {
return create(attributesGetter, JAVAAGENT_PEER_SERVICE_MAPPING);
return create(
attributesGetter,
io.opentelemetry.instrumentation.api.config.Config.get()
.getMap("otel.instrumentation.common.peer-service-mapping", emptyMap()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
* repeatedly calling {@link Config}. The instrumentation configuration does not change during the
* runtime so retrieving the property once and storing its result in a static final field allows JIT
* to do its magic and remove some code branches.
*
* @deprecated This class is deprecated and will be removed from instrumentation-api in the next
* release. Please use programmatic configuration (e.g. builder methods) instead.
*/
// TODO: deprecate
@Deprecated
@AutoValue
@AutoValue.CopyAnnotations
public abstract class Config {
private static final Logger logger = Logger.getLogger(Config.class.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
import java.util.Properties;
import javax.annotation.Nullable;

/** A builder of a {@link Config}. */
/**
* A builder of a {@link Config}.
*
* @deprecated This class is deprecated and will be removed together with {@link Config}.
*/
@Deprecated
public final class ConfigBuilder {

private final Map<String, String> allProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.junit.jupiter.api.Test;

// suppress duration unit check, e.g. ofMillis(5000) -> ofSeconds(5)
@SuppressWarnings({"CanonicalDuration"})
@SuppressWarnings({"CanonicalDuration", "deprecation"})
class ConfigTest {
@Test
void shouldGetString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

package io.opentelemetry.javaagent.bootstrap;

import io.opentelemetry.instrumentation.api.config.Config;
import java.util.function.Predicate;
import java.util.logging.Logger;

public final class InstrumentedTaskClasses {

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

private static final String AGENT_CLASSLOADER_NAME =
"io.opentelemetry.javaagent.bootstrap.AgentClassLoader";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import static java.util.Objects.requireNonNull;

import io.opentelemetry.instrumentation.api.config.Config;
import java.time.Duration;
import java.util.List;
import java.util.Map;
Expand All @@ -21,9 +20,9 @@
*
* <p>In case any {@code get*()} method variant gets called for the same property more than once
* (e.g. each time an advice class executes) it is suggested to cache the result instead of
* repeatedly calling {@link Config}. Instrumentation configuration does not change during the
* runtime so retrieving the property once and storing its result in a static final field allows JIT
* to do its magic and remove some code branches.
* repeatedly calling {@link InstrumentationConfig}. Instrumentation configuration does not change
* during the runtime so retrieving the property once and storing its result in a static final field
* allows JIT to do its magic and remove some code branches.
*
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package io.opentelemetry.javaagent.extension;

import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import java.lang.instrument.Instrumentation;
import net.bytebuddy.agent.builder.AgentBuilder;
Expand All @@ -28,7 +27,8 @@ public interface AgentListener extends Ordered {
*/
@Deprecated
default void afterAgent(
Config config, AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk) {
io.opentelemetry.instrumentation.api.config.Config config,
AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk) {
throw new UnsupportedOperationException(
"This method is deprecated and will be removed in a future release;"
+ " implement AgentListener#afterAgent(AutoConfiguredOpenTelemetrySdk) instead");
Expand All @@ -38,7 +38,9 @@ default void afterAgent(
* Runs after instrumentations are added to {@link AgentBuilder} and after the agent is installed
* on an {@link Instrumentation}.
*/
@SuppressWarnings("deprecation") // Config usage, to be removed
default void afterAgent(AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk) {
afterAgent(Config.get(), autoConfiguredOpenTelemetrySdk);
afterAgent(
io.opentelemetry.instrumentation.api.config.Config.get(), autoConfiguredOpenTelemetrySdk);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package io.opentelemetry.javaagent.extension.config;

import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.javaagent.extension.Ordered;
import java.util.Collections;
import java.util.Map;
Expand Down Expand Up @@ -35,7 +34,8 @@ default Map<String, String> defaultProperties() {
}

/** Allows to change the javaagent configuration just before it is first used. */
default Config customize(Config config) {
default io.opentelemetry.instrumentation.api.config.Config customize(
io.opentelemetry.instrumentation.api.config.Config config) {
return config;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package io.opentelemetry.javaagent.extension.ignore;

import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.javaagent.extension.Ordered;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;

Expand All @@ -26,7 +25,8 @@ public interface IgnoredTypesConfigurer extends Ordered {
* @deprecated Use {@link #configure(IgnoredTypesBuilder, ConfigProperties)} instead.
*/
@Deprecated
default void configure(Config config, IgnoredTypesBuilder builder) {
default void configure(
io.opentelemetry.instrumentation.api.config.Config config, IgnoredTypesBuilder builder) {
throw new UnsupportedOperationException(
"This method is deprecated and will be removed in a future release;"
+ " implement IgnoredTypesConfigurer#configure(IgnoredTypesBuilder, ConfigProperties) instead");
Expand All @@ -36,7 +36,8 @@ default void configure(Config config, IgnoredTypesBuilder builder) {
* Configure the passed {@code builder} and define which classes should be ignored when
* instrumenting.
*/
@SuppressWarnings("deprecation") // Config usage, to be removed
default void configure(IgnoredTypesBuilder builder, ConfigProperties config) {
configure(Config.get(), builder);
configure(io.opentelemetry.instrumentation.api.config.Config.get(), builder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import static java.util.Collections.unmodifiableSet;
import static net.bytebuddy.matcher.ElementMatchers.any;

import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.javaagent.extension.Ordered;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import java.util.Collections;
Expand All @@ -31,8 +30,11 @@
* java.util.ServiceLoader} for more details.
*/
public abstract class InstrumentationModule implements Ordered {

@SuppressWarnings("deprecation") // Config usage, to be removed
private static final boolean DEFAULT_ENABLED =
Config.get().getBoolean("otel.instrumentation.common.default-enabled", true);
io.opentelemetry.instrumentation.api.config.Config.get()
.getBoolean("otel.instrumentation.common.default-enabled", true);

private final Set<String> instrumentationNames;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.context.ContextStorage;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.instrumentation.api.internal.EmbeddedInstrumentationProperties;
import io.opentelemetry.javaagent.bootstrap.AgentClassLoader;
import io.opentelemetry.javaagent.bootstrap.AgentInitializer;
Expand Down Expand Up @@ -78,7 +77,9 @@ public class AgentInstaller {

private static final Map<String, List<Runnable>> CLASS_LOAD_CALLBACKS = new HashMap<>();

public static void installBytebuddyAgent(Instrumentation inst, Config config) {
@SuppressWarnings("deprecation") // Config usage, to be removed
public static void installBytebuddyAgent(
Instrumentation inst, io.opentelemetry.instrumentation.api.config.Config config) {
addByteBuddyRawSetting();

Integer strictContextStressorMillis = Integer.getInteger(STRICT_CONTEXT_STRESSOR_MILLIS);
Expand All @@ -97,15 +98,17 @@ public static void installBytebuddyAgent(Instrumentation inst, Config config) {
}
}

@SuppressWarnings("deprecation") // Config usage, to be removed
private static void installBytebuddyAgent(
Instrumentation inst, Config config, Iterable<AgentListener> agentListeners) {
Instrumentation inst,
io.opentelemetry.instrumentation.api.config.Config config,
Iterable<AgentListener> agentListeners) {

WeakRefAsyncOperationEndStrategies.initialize();

EmbeddedInstrumentationProperties.setPropertiesLoader(
AgentInitializer.getExtensionsClassLoader());

setBootstrapPackages(config);
setDefineClassHandler();

// If noop OpenTelemetry is enabled, autoConfiguredSdk will be null and AgentListeners are not
Expand All @@ -116,6 +119,8 @@ private static void installBytebuddyAgent(
InstrumentationConfig.internalInitializeConfig(new ConfigPropertiesBridge(sdkConfig));
copyNecessaryConfigToSystemProperties(sdkConfig);

setBootstrapPackages(sdkConfig);

for (BeforeAgentListener agentListener : loadOrdered(BeforeAgentListener.class)) {
agentListener.beforeAgent(autoConfiguredSdk);
}
Expand Down Expand Up @@ -195,10 +200,10 @@ private static void setupUnsafe(Instrumentation inst) {
}
}

private static void setBootstrapPackages(Config config) {
private static void setBootstrapPackages(ConfigProperties config) {
BootstrapPackagesBuilderImpl builder = new BootstrapPackagesBuilderImpl();
for (BootstrapPackagesConfigurer configurer : load(BootstrapPackagesConfigurer.class)) {
configurer.configure(config, builder);
configurer.configure(builder, config);
}
BootstrapPackagePrefixesHolder.setBoostrapPackagePrefixes(builder.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package io.opentelemetry.javaagent.tooling;

import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.javaagent.bootstrap.AgentInitializer;
import io.opentelemetry.javaagent.bootstrap.AgentStarter;
import io.opentelemetry.javaagent.tooling.config.ConfigInitializer;
Expand Down Expand Up @@ -72,6 +71,7 @@ public void start() {
}
}

@SuppressWarnings("deprecation") // Config usage, to be removed
private void internalStart() {
Iterator<LoggingCustomizer> loggingCustomizers =
ServiceLoader.load(LoggingCustomizer.class).iterator();
Expand All @@ -86,7 +86,8 @@ private void internalStart() {
try {
loggingCustomizer.init();
ConfigInitializer.initialize();
AgentInstaller.installBytebuddyAgent(instrumentation, Config.get());
AgentInstaller.installBytebuddyAgent(
instrumentation, io.opentelemetry.instrumentation.api.config.Config.get());
} catch (Throwable t) {
// this is logged below and not rethrown to avoid logging it twice
startupError = t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package io.opentelemetry.javaagent.tooling;

import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;

// only one LoggingCustomizer is allowed, and its presence will suppress the
Expand All @@ -21,7 +20,7 @@ public interface LoggingCustomizer {
* Register a callback which will be called on synchronous startup success.
*
* <p>Synchronous startup may or may not include running {@link
* io.opentelemetry.javaagent.extension.AgentListener#afterAgent(Config,
* io.opentelemetry.javaagent.extension.AgentListener#afterAgent(
* AutoConfiguredOpenTelemetrySdk)}" listeners.
*/
void onStartupSuccess();
Expand All @@ -31,7 +30,7 @@ public interface LoggingCustomizer {
* #init()} fails).
*
* <p>Synchronous startup may or may not include running {@link
* io.opentelemetry.javaagent.extension.AgentListener#afterAgent(Config,
* io.opentelemetry.javaagent.extension.AgentListener#afterAgent(
* AutoConfiguredOpenTelemetrySdk)}" listeners.
*/
void onStartupFailure(Throwable throwable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import static io.opentelemetry.javaagent.tooling.HeliosConfiguration.getServiceName;

import io.opentelemetry.instrumentation.api.appender.internal.LogEmitterProvider;
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.instrumentation.sdk.appender.internal.DelegatingLogEmitterProvider;
import io.opentelemetry.javaagent.bootstrap.AgentInitializer;
import io.opentelemetry.javaagent.bootstrap.AgentLogEmitterProvider;
Expand All @@ -31,7 +30,9 @@ public class OpenTelemetryInstaller {
*
* @return the {@link AutoConfiguredOpenTelemetrySdk}
*/
static AutoConfiguredOpenTelemetrySdk installOpenTelemetrySdk(Config config) {
@SuppressWarnings("deprecation") // Config usage, to be removed
static AutoConfiguredOpenTelemetrySdk installOpenTelemetrySdk(
io.opentelemetry.instrumentation.api.config.Config config) {
AutoConfiguredOpenTelemetrySdkBuilder builder =
AutoConfiguredOpenTelemetrySdk.builder()
.setResultAsGlobal(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package io.opentelemetry.javaagent.tooling.bootstrap;

import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;

/**
* This SPI can be used to define which packages/classes belong to the bootstrap class loader: all
Expand All @@ -24,5 +24,5 @@ public interface BootstrapPackagesConfigurer {
* Configure the passed {@code builder} and define which classes should always be loaded by the
* bootstrap class loader.
*/
void configure(Config config, BootstrapPackagesBuilder builder);
void configure(BootstrapPackagesBuilder builder, ConfigProperties config);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import static io.opentelemetry.javaagent.tooling.SafeServiceLoader.loadOrdered;
import static java.util.logging.Level.SEVERE;

import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.javaagent.extension.config.ConfigPropertySource;
import java.io.File;
import java.io.FileInputStream;
Expand All @@ -20,27 +19,29 @@
import java.util.Properties;
import java.util.logging.Logger;

@SuppressWarnings("deprecation") // Config usage, to be removed
public final class ConfigInitializer {
private static final Logger logger = Logger.getLogger(ConfigInitializer.class.getName());

// visible for testing
static final String CONFIGURATION_FILE_PROPERTY = "otel.javaagent.configuration-file";
static final String CONFIGURATION_FILE_ENV_VAR = "OTEL_JAVAAGENT_CONFIGURATION_FILE";

@SuppressWarnings("deprecation") // loads the ConfigCustomizer SPI
public static void initialize() {
List<io.opentelemetry.javaagent.extension.config.ConfigCustomizer> customizers =
loadOrdered(io.opentelemetry.javaagent.extension.config.ConfigCustomizer.class);
Config config = create(loadSpiConfiguration(customizers), loadConfigurationFile());
io.opentelemetry.instrumentation.api.config.Config config =
create(loadSpiConfiguration(customizers), loadConfigurationFile());
for (io.opentelemetry.javaagent.extension.config.ConfigCustomizer customizer : customizers) {
config = customizer.customize(config);
}
Config.internalInitializeConfig(config);
io.opentelemetry.instrumentation.api.config.Config.internalInitializeConfig(config);
}

// visible for testing
static Config create(Properties spiConfiguration, Properties configurationFile) {
return Config.builder()
static io.opentelemetry.instrumentation.api.config.Config create(
Properties spiConfiguration, Properties configurationFile) {
return io.opentelemetry.instrumentation.api.config.Config.builder()
.addProperties(spiConfiguration)
.addProperties(configurationFile)
.addEnvironmentVariables()
Expand Down

0 comments on commit c58ef0a

Please sign in to comment.