From 56d1ab6af1f00caeba07adbc9b68915cefd79c45 Mon Sep 17 00:00:00 2001 From: Jack Berg Date: Mon, 16 Sep 2024 15:50:03 -0500 Subject: [PATCH 1/2] Use autoconfigured ClassLoader to load declarative config --- .../AutoConfiguredOpenTelemetrySdkBuilder.java | 11 +++++++---- .../incubator/fileconfig/FileConfiguration.java | 17 ++++++++++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java index 7fd5d515f4c..294b4f97636 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java @@ -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()); @@ -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( @@ -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 = diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfiguration.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfiguration.java index ec7fe6407ac..f620de20888 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfiguration.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfiguration.java @@ -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} + * @throws ConfigurationException if unable to interpret + */ + public static OpenTelemetrySdk create( + OpenTelemetryConfiguration configurationModel, SpiHelper spiHelper) { return createAndMaybeCleanup( - OpenTelemetryConfigurationFactory.getInstance(), - SpiHelper.create(FileConfiguration.class.getClassLoader()), - configurationModel); + OpenTelemetryConfigurationFactory.getInstance(), spiHelper, configurationModel); } /** From 16a4e67805ad4b1cc3c97c8e75c9e5ecdc5ad074 Mon Sep 17 00:00:00 2001 From: Jack Berg Date: Fri, 20 Sep 2024 13:48:17 -0500 Subject: [PATCH 2/2] spotless --- .../sdk/extension/incubator/fileconfig/FileConfiguration.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfiguration.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfiguration.java index bfea854be35..5b1b3dd32f0 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfiguration.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfiguration.java @@ -97,7 +97,8 @@ public static OpenTelemetrySdk create(OpenTelemetryConfigurationModel configurat * corresponding to the configuration. * * @param configurationModel the configuration model - * @param componentLoader the component loader used to load {@link ComponentProvider} implementations + * @param componentLoader the component loader used to load {@link ComponentProvider} + * implementations * @return the {@link OpenTelemetrySdk} * @throws ConfigurationException if unable to interpret */