Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use autoconfigured ClassLoader to load declarative config #6725

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -428,7 +428,8 @@ public AutoConfiguredOpenTelemetrySdk build() {

ConfigProperties config = getConfig();

AutoConfiguredOpenTelemetrySdk fromFileConfiguration = maybeConfigureFromFile(config);
AutoConfiguredOpenTelemetrySdk fromFileConfiguration =
maybeConfigureFromFile(config, spiHelper);
if (fromFileConfiguration != null) {
maybeRegisterShutdownHook(fromFileConfiguration.getOpenTelemetrySdk());
maybeSetAsGlobal(fromFileConfiguration.getOpenTelemetrySdk());
Expand Down Expand Up @@ -527,7 +528,8 @@ public AutoConfiguredOpenTelemetrySdk build() {
}

@Nullable
private static AutoConfiguredOpenTelemetrySdk maybeConfigureFromFile(ConfigProperties config) {
private static AutoConfiguredOpenTelemetrySdk maybeConfigureFromFile(
ConfigProperties config, SpiHelper spiHelper) {
String otelConfigFile = config.getString("otel.config.file");
if (otelConfigFile != null && !otelConfigFile.isEmpty()) {
logger.warning(
Expand All @@ -552,8 +554,9 @@ private static AutoConfiguredOpenTelemetrySdk maybeConfigureFromFile(ConfigPrope
Class<?> openTelemetryConfiguration =
Class.forName(
"io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfiguration");
Method create = configurationFactory.getMethod("create", openTelemetryConfiguration);
OpenTelemetrySdk sdk = (OpenTelemetrySdk) create.invoke(null, model);
Method create =
configurationFactory.getMethod("create", openTelemetryConfiguration, SpiHelper.class);
OpenTelemetrySdk sdk = (OpenTelemetrySdk) create.invoke(null, model, spiHelper);
Method toConfigProperties =
configurationFactory.getMethod("toConfigProperties", openTelemetryConfiguration);
StructuredConfigProperties structuredConfigProperties =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,21 @@ public static OpenTelemetrySdk parseAndCreate(InputStream inputStream) {
* @throws ConfigurationException if unable to interpret
*/
public static OpenTelemetrySdk create(OpenTelemetryConfiguration configurationModel) {
return create(configurationModel, SpiHelper.create(FileConfiguration.class.getClassLoader()));
}

/**
* Interpret the {@code configurationModel} to create {@link OpenTelemetrySdk} instance
* corresponding to the configuration.
*
* @param configurationModel the configuration model
* @return the {@link OpenTelemetrySdk}
jack-berg marked this conversation as resolved.
Show resolved Hide resolved
* @throws ConfigurationException if unable to interpret
*/
public static OpenTelemetrySdk create(
OpenTelemetryConfiguration configurationModel, SpiHelper spiHelper) {
jack-berg marked this conversation as resolved.
Show resolved Hide resolved
return createAndMaybeCleanup(
OpenTelemetryConfigurationFactory.getInstance(),
SpiHelper.create(FileConfiguration.class.getClassLoader()),
configurationModel);
OpenTelemetryConfigurationFactory.getInstance(), spiHelper, configurationModel);
}

/**
Expand Down
Loading