Move autoconfigure getConfig to internal, remove getResource (#5467)
This commit is contained in:
parent
ddb47e14c8
commit
73597b1332
|
|
@ -51,10 +51,10 @@ public abstract class AutoConfiguredOpenTelemetrySdk {
|
|||
public abstract OpenTelemetrySdk getOpenTelemetrySdk();
|
||||
|
||||
/** Returns the {@link Resource} that was auto-configured. */
|
||||
public abstract Resource getResource();
|
||||
abstract Resource getResource();
|
||||
|
||||
/** Returns the {@link ConfigProperties} used for auto-configuration. */
|
||||
public abstract ConfigProperties getConfig();
|
||||
abstract ConfigProperties getConfig();
|
||||
|
||||
AutoConfiguredOpenTelemetrySdk() {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.autoconfigure.internal;
|
||||
|
||||
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
|
||||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
||||
* any time.
|
||||
*/
|
||||
public final class AutoConfigureUtil {
|
||||
|
||||
private AutoConfigureUtil() {}
|
||||
|
||||
/** Returns the {@link ConfigProperties} used for auto-configuration. */
|
||||
public static ConfigProperties getConfig(
|
||||
AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk) {
|
||||
try {
|
||||
Method method = AutoConfiguredOpenTelemetrySdk.class.getDeclaredMethod("getConfig");
|
||||
method.setAccessible(true);
|
||||
return (ConfigProperties) method.invoke(autoConfiguredOpenTelemetrySdk);
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
throw new IllegalStateException(
|
||||
"Error calling getConfig on AutoConfiguredOpenTelemetrySdk", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.autoconfigure;
|
||||
|
||||
import static java.util.Collections.singletonMap;
|
||||
|
||||
import io.opentelemetry.sdk.autoconfigure.internal.AutoConfigureUtil;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class AutoConfigureUtilTest {
|
||||
|
||||
AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk;
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
autoConfiguredOpenTelemetrySdk =
|
||||
AutoConfiguredOpenTelemetrySdk.builder()
|
||||
.addPropertiesSupplier(() -> singletonMap("otel.metrics.exporter", "none"))
|
||||
.addPropertiesSupplier(() -> singletonMap("otel.traces.exporter", "none"))
|
||||
.addPropertiesSupplier(() -> singletonMap("otel.logs.exporter", "none"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getConfig() {
|
||||
Assertions.assertThat(AutoConfigureUtil.getConfig(autoConfiguredOpenTelemetrySdk))
|
||||
.isSameAs(autoConfiguredOpenTelemetrySdk.getConfig());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue