Deprecate Config (#6360)
* Deprecate Config * suppress deprecation on ConfigTest
This commit is contained in:
parent
82b39b1012
commit
976ab9411c
|
@ -9,7 +9,6 @@ import static java.util.Collections.emptyMap;
|
|||
|
||||
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;
|
||||
|
@ -22,8 +21,6 @@ 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", emptyMap());
|
||||
|
||||
private final NetClientAttributesGetter<REQUEST, RESPONSE> attributesGetter;
|
||||
private final Map<String, String> peerServiceMapping;
|
||||
|
@ -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()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,9 +25,13 @@ import javax.annotation.Nullable;
|
|||
* 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());
|
||||
|
||||
|
|
|
@ -11,7 +11,12 @@ import java.util.Map;
|
|||
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;
|
||||
|
|
|
@ -20,7 +20,7 @@ import java.time.Duration;
|
|||
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() {
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -7,7 +7,6 @@ package io.opentelemetry.javaagent.bootstrap.internal;
|
|||
|
||||
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;
|
||||
|
@ -21,9 +20,9 @@ import javax.annotation.Nullable;
|
|||
*
|
||||
* <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.
|
||||
|
|
|
@ -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;
|
||||
|
@ -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");
|
||||
|
@ -38,7 +38,9 @@ public interface AgentListener extends Ordered {
|
|||
* 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -35,7 +34,8 @@ public interface ConfigCustomizer extends Ordered {
|
|||
}
|
||||
|
||||
/** 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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");
|
||||
|
@ -36,7 +36,8 @@ public interface IgnoredTypesConfigurer extends Ordered {
|
|||
* 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import static java.util.Arrays.asList;
|
|||
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;
|
||||
|
@ -31,8 +30,11 @@ import net.bytebuddy.matcher.ElementMatcher;
|
|||
* 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;
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ import static net.bytebuddy.matcher.ElementMatchers.any;
|
|||
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;
|
||||
|
@ -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);
|
||||
|
@ -97,15 +98,17 @@ public class AgentInstaller {
|
|||
}
|
||||
}
|
||||
|
||||
@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
|
||||
|
@ -116,6 +119,8 @@ public class AgentInstaller {
|
|||
InstrumentationConfig.internalInitializeConfig(new ConfigPropertiesBridge(sdkConfig));
|
||||
copyNecessaryConfigToSystemProperties(sdkConfig);
|
||||
|
||||
setBootstrapPackages(sdkConfig);
|
||||
|
||||
for (BeforeAgentListener agentListener : loadOrdered(BeforeAgentListener.class)) {
|
||||
agentListener.beforeAgent(autoConfiguredSdk);
|
||||
}
|
||||
|
@ -195,10 +200,10 @@ public class AgentInstaller {
|
|||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -72,6 +71,7 @@ public class AgentStarterImpl implements AgentStarter {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // Config usage, to be removed
|
||||
private void internalStart() {
|
||||
Iterator<LoggingCustomizer> loggingCustomizers =
|
||||
ServiceLoader.load(LoggingCustomizer.class).iterator();
|
||||
|
@ -86,7 +86,8 @@ public class AgentStarterImpl implements AgentStarter {
|
|||
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;
|
||||
|
|
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
package io.opentelemetry.javaagent.tooling;
|
||||
|
||||
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;
|
||||
|
@ -26,7 +25,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)
|
||||
|
|
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ package io.opentelemetry.javaagent.tooling.config;
|
|||
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;
|
||||
|
@ -20,6 +19,7 @@ import java.util.List;
|
|||
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());
|
||||
|
||||
|
@ -27,20 +27,21 @@ public final class ConfigInitializer {
|
|||
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()
|
||||
|
|
Loading…
Reference in New Issue