-
Notifications
You must be signed in to change notification settings - Fork 956
don't call old plugin when declarative config is in use #7472
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
Merged
jkwatson
merged 9 commits into
open-telemetry:main
from
zeitlinger:declarative-config-order
Sep 4, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
46fc6b2
don't call old plugin when declarative config is in use
zeitlinger bef6aae
fix
zeitlinger c8ccdaa
fix
zeitlinger 6242d30
fix
zeitlinger 0a15c4a
fix rebase
zeitlinger d024873
fix test
zeitlinger 5b81ef8
add spi to load a declarative config model
zeitlinger 593162e
add spi to load a declarative config model
zeitlinger 07c61ef
test coverage
zeitlinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...iveConfigSpi/java/io/opentelemetry/sdk/autoconfigure/DeclarativeConfigurationSpiTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.autoconfigure; | ||
|
|
||
| import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.doReturn; | ||
| import static org.mockito.Mockito.spy; | ||
|
|
||
| import io.opentelemetry.exporter.logging.LoggingSpanExporter; | ||
| import io.opentelemetry.internal.testing.CleanupExtension; | ||
| import io.opentelemetry.sdk.OpenTelemetrySdk; | ||
| import io.opentelemetry.sdk.resources.Resource; | ||
| import io.opentelemetry.sdk.trace.SdkTracerProvider; | ||
| import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
||
| class DeclarativeConfigurationSpiTest { | ||
|
|
||
| @RegisterExtension private static final CleanupExtension cleanup = new CleanupExtension(); | ||
|
|
||
| @Test | ||
| void configFromSpi() { | ||
| OpenTelemetrySdk expectedSdk = | ||
| OpenTelemetrySdk.builder() | ||
| .setTracerProvider( | ||
| SdkTracerProvider.builder() | ||
| .setResource( | ||
| Resource.getDefault().toBuilder().put("service.name", "test").build()) | ||
| .addSpanProcessor(SimpleSpanProcessor.create(LoggingSpanExporter.create())) | ||
| .build()) | ||
| .build(); | ||
| cleanup.addCloseable(expectedSdk); | ||
| AutoConfiguredOpenTelemetrySdkBuilder builder = spy(AutoConfiguredOpenTelemetrySdk.builder()); | ||
| Thread thread = new Thread(); | ||
| doReturn(thread).when(builder).shutdownHook(any()); | ||
|
|
||
| AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk = builder.build(); | ||
| cleanup.addCloseable(autoConfiguredOpenTelemetrySdk.getOpenTelemetrySdk()); | ||
|
|
||
| assertThat(autoConfiguredOpenTelemetrySdk.getOpenTelemetrySdk().toString()) | ||
| .isEqualTo(expectedSdk.toString()); | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
.../testDeclarativeConfigSpi/java/io/opentelemetry/sdk/autoconfigure/IncubatingUtilTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.autoconfigure; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThatCode; | ||
|
|
||
| import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; | ||
| import java.lang.reflect.InvocationTargetException; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class IncubatingUtilTest { | ||
|
|
||
| @Test | ||
| void classNotFoundException() { | ||
| assertThatCode( | ||
| () -> | ||
| IncubatingUtil.createWithFactory( | ||
| "test", | ||
| () -> { | ||
| Class.forName("foo"); | ||
| return null; | ||
| })) | ||
| .isInstanceOf(ConfigurationException.class) | ||
| .hasMessage( | ||
| "Error configuring from test. Is opentelemetry-sdk-extension-incubator on the classpath?"); | ||
| } | ||
|
|
||
| @Test | ||
| void invocationTargetException() { | ||
| assertThatCode( | ||
| () -> | ||
| IncubatingUtil.createWithFactory( | ||
| "test", | ||
| () -> { | ||
| throw new InvocationTargetException(new RuntimeException("test exception")); | ||
| })) | ||
| .isInstanceOf(ConfigurationException.class) | ||
| .hasMessage("Unexpected error configuring from test") | ||
| .hasRootCauseMessage("test exception"); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
...nfigSpi/java/io/opentelemetry/sdk/autoconfigure/TestDeclarativeConfigurationProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.autoconfigure; | ||
|
|
||
| import io.opentelemetry.sdk.extension.incubator.fileconfig.DeclarativeConfiguration; | ||
| import io.opentelemetry.sdk.extension.incubator.fileconfig.DeclarativeConfigurationProvider; | ||
| import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel; | ||
| import java.io.ByteArrayInputStream; | ||
| import java.nio.charset.StandardCharsets; | ||
|
|
||
| public class TestDeclarativeConfigurationProvider implements DeclarativeConfigurationProvider { | ||
| @Override | ||
| public OpenTelemetryConfigurationModel getConfigurationModel() { | ||
| String yaml = | ||
| "file_format: \"1.0-rc.1\"\n" | ||
| + "resource:\n" | ||
| + " attributes:\n" | ||
| + " - name: service.name\n" | ||
| + " value: test\n" | ||
| + "tracer_provider:\n" | ||
| + " processors:\n" | ||
| + " - simple:\n" | ||
| + " exporter:\n" | ||
| + " console: {}\n"; | ||
|
|
||
| return DeclarativeConfiguration.parse( | ||
| new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8))); | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
...ices/io.opentelemetry.sdk.extension.incubator.fileconfig.DeclarativeConfigurationProvider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| io.opentelemetry.sdk.autoconfigure.TestDeclarativeConfigurationProvider |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.extension.incubator.fileconfig; | ||
|
|
||
| import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** A service provider interface (SPI) for providing a declarative configuration model. */ | ||
| public interface DeclarativeConfigurationProvider { | ||
| /** | ||
| * Returns an OpenTelemetry configuration model to be used when configuring the SDK, or {@code | ||
| * null} if no configuration is provided by this provider. | ||
| */ | ||
| @Nullable | ||
| OpenTelemetryConfigurationModel getConfigurationModel(); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
most (all?) of these are runtime exceptions, yeah? I don't think we usually declare them to be thrown, especially not on private methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
none of them are runtime exceptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ugh, really? Sometimes Java APIs are the worst. 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes...