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 @@ -5,7 +5,6 @@

package io.opentelemetry.api.incubator.config;

import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;

/**
Expand All @@ -23,15 +22,14 @@ public interface ConfigProvider {
/**
* Returns the {@link DeclarativeConfigProperties} corresponding to <a
* href="https://github.com/open-telemetry/opentelemetry-configuration/blob/main/schema/instrumentation.json">instrumentation
* config</a>, or {@code null} if unavailable.
* config</a>. Returns {@link DeclarativeConfigProperties#empty()} if unavailable.
*
* @return the instrumentation {@link DeclarativeConfigProperties}
*/
@Nullable
DeclarativeConfigProperties getInstrumentationConfig();

/** Returns a no-op {@link ConfigProvider}. */
static ConfigProvider noop() {
return () -> null;
return DeclarativeConfigProperties::empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ public static DeclarativeConfigProperties javaInstrumentationConfig(

/**
* Walk down the {@code segments} of {@link ConfigProvider#getInstrumentationConfig()} and call
* {@code accessor} on the terminal node. Returns null if {@link
* ConfigProvider#getInstrumentationConfig()} is null, or if null is encountered walking the
* {@code segments}, or if {@code accessor} returns null.
* {@code accessor} on the terminal node. Returns null if null is encountered walking the {@code
* segments}, or if {@code accessor} returns null.
*
* <p>See other methods in {@link InstrumentationConfigUtil} for usage examples.
*/
Expand All @@ -136,9 +135,6 @@ public static <T> T getOrNull(
Function<DeclarativeConfigProperties, T> accessor,
String... segments) {
DeclarativeConfigProperties config = configProvider.getInstrumentationConfig();
if (config == null) {
return null;
}
for (String segment : segments) {
config = config.getStructured(segment);
if (config == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void toMap_RoundTrip() throws JsonProcessingException {

@Test
void getInstrumentationConfigModel_UnsetConfig() {
ConfigProvider configProvider = () -> null;
ConfigProvider configProvider = DeclarativeConfigProperties::empty;

assertThat(
InstrumentationConfigUtil.getInstrumentationConfigModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.extension.incubator.fileconfig.SdkConfigProvider;
import java.io.Closeable;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;

/** A new interface for creating OpenTelemetrySdk that supports getting {@link ConfigProvider}. */
Expand Down Expand Up @@ -74,7 +73,6 @@ private ObfuscatedConfigProvider(SdkConfigProvider delegate) {
}

@Override
@Nullable
public DeclarativeConfigProperties getInstrumentationConfig() {
return delegate.getInstrumentationConfig();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.common.ComponentLoader;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel;
import javax.annotation.Nullable;

/** SDK implementation of {@link ConfigProvider}. */
public final class SdkConfigProvider implements ConfigProvider {

@Nullable private final DeclarativeConfigProperties instrumentationConfig;
private final DeclarativeConfigProperties instrumentationConfig;

private SdkConfigProvider(
OpenTelemetryConfigurationModel model, ComponentLoader componentLoader) {
DeclarativeConfigProperties configProperties =
DeclarativeConfiguration.toConfigProperties(model, componentLoader);
this.instrumentationConfig = configProperties.getStructured("instrumentation/development");
DeclarativeConfigProperties instrumentationConfigOrNull =
configProperties.getStructured("instrumentation/development");
this.instrumentationConfig =
instrumentationConfigOrNull == null
? DeclarativeConfigProperties.empty()
: instrumentationConfigOrNull;
}

/**
Expand All @@ -45,7 +49,6 @@ public static SdkConfigProvider create(
return new SdkConfigProvider(model, componentLoader);
}

@Nullable
@Override
public DeclarativeConfigProperties getInstrumentationConfig() {
return instrumentationConfig;
Expand Down