-
Notifications
You must be signed in to change notification settings - Fork 986
Vendor specific instrumentation config options handling #14016
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
trask
merged 11 commits into
open-telemetry:main
from
robsunday:declarative-config-improvements
Jul 10, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
16da1b0
Vendor specific instrumentation config options handling
robsunday c707f0e
spotless
robsunday 73b1797
Custom properties are no longer under "vendor" node.
robsunday 506425b
UT update
robsunday 8e03ae6
Code review changes.
robsunday 6940b8c
Merge branch 'main' into declarative-config-improvements
robsunday c01877c
Removed assertion in UT that was used to demonstrate name collision
robsunday f7be9c8
Merge branch 'main' into declarative-config-improvements
robsunday 7375716
Additional changes for mockito
robsunday 6d0f85a
Merge branch 'main' into declarative-config-improvements
robsunday f413172
Merge branch 'main' into declarative-config-improvements
robsunday 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
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
40 changes: 40 additions & 0 deletions
40
...xtension-api/src/main/java/io/opentelemetry/javaagent/extension/ConfigPropertiesUtil.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,40 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.extension; | ||
|
||
import io.opentelemetry.api.incubator.config.ConfigProvider; | ||
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; | ||
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; | ||
import io.opentelemetry.sdk.autoconfigure.internal.AutoConfigureUtil; | ||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
|
||
public class ConfigPropertiesUtil { | ||
private ConfigPropertiesUtil() {} | ||
|
||
/** Resolve {@link ConfigProperties} from the {@code autoConfiguredOpenTelemetrySdk}. */ | ||
public static ConfigProperties resolveConfigProperties( | ||
AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk) { | ||
ConfigProperties sdkConfigProperties = | ||
AutoConfigureUtil.getConfig(autoConfiguredOpenTelemetrySdk); | ||
if (sdkConfigProperties != null) { | ||
return sdkConfigProperties; | ||
} | ||
ConfigProvider configProvider = | ||
AutoConfigureUtil.getConfigProvider(autoConfiguredOpenTelemetrySdk); | ||
if (configProvider != null) { | ||
DeclarativeConfigProperties instrumentationConfig = configProvider.getInstrumentationConfig(); | ||
|
||
if (instrumentationConfig == null) { | ||
instrumentationConfig = DeclarativeConfigProperties.empty(); | ||
} | ||
robsunday marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return new DeclarativeConfigPropertiesBridge(instrumentationConfig); | ||
} | ||
// Should never happen | ||
throw new IllegalStateException( | ||
"AutoConfiguredOpenTelemetrySdk does not have ConfigProperties or DeclarativeConfigProperties. This is likely a programming error in opentelemetry-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
87 changes: 87 additions & 0 deletions
87
...sion-api/src/test/java/io/opentelemetry/javaagent/extension/ConfigPropertiesUtilTest.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,87 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.extension; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import io.opentelemetry.api.incubator.config.ConfigProvider; | ||
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; | ||
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; | ||
import io.opentelemetry.sdk.autoconfigure.internal.AutoConfigureUtil; | ||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
|
||
@SuppressWarnings("DoNotMockAutoValue") | ||
class ConfigPropertiesUtilTest { | ||
@Test | ||
void shouldUseConfigPropertiesForAutoConfiguration() { | ||
ConfigProperties configPropertiesMock = mock(ConfigProperties.class); | ||
AutoConfiguredOpenTelemetrySdk sdkMock = mock(AutoConfiguredOpenTelemetrySdk.class); | ||
try (MockedStatic<AutoConfigureUtil> autoConfigureUtilMock = | ||
Mockito.mockStatic(AutoConfigureUtil.class)) { | ||
autoConfigureUtilMock | ||
.when(() -> AutoConfigureUtil.getConfig(sdkMock)) | ||
.thenReturn(configPropertiesMock); | ||
|
||
ConfigProperties configProperties = ConfigPropertiesUtil.resolveConfigProperties(sdkMock); | ||
|
||
assertThat(configProperties).isSameAs(configPropertiesMock); | ||
} | ||
} | ||
|
||
@Test | ||
void shouldUseConfigProviderForDeclarativeConfiguration() { | ||
String propertyName = "testProperty"; | ||
String expectedValue = "the value"; | ||
DeclarativeConfigProperties javaNodeMock = mock(DeclarativeConfigProperties.class); | ||
when(javaNodeMock.getString(propertyName)).thenReturn(expectedValue); | ||
|
||
DeclarativeConfigProperties instrumentationConfigMock = mock(DeclarativeConfigProperties.class); | ||
when(instrumentationConfigMock.getStructured(eq("java"), any())).thenReturn(javaNodeMock); | ||
|
||
ConfigProvider configProviderMock = mock(ConfigProvider.class); | ||
when(configProviderMock.getInstrumentationConfig()).thenReturn(instrumentationConfigMock); | ||
|
||
AutoConfiguredOpenTelemetrySdk sdkMock = mock(AutoConfiguredOpenTelemetrySdk.class); | ||
|
||
try (MockedStatic<AutoConfigureUtil> autoConfigureUtilMock = | ||
Mockito.mockStatic(AutoConfigureUtil.class)) { | ||
autoConfigureUtilMock.when(() -> AutoConfigureUtil.getConfig(sdkMock)).thenReturn(null); | ||
autoConfigureUtilMock | ||
.when(() -> AutoConfigureUtil.getConfigProvider(sdkMock)) | ||
.thenReturn(configProviderMock); | ||
|
||
ConfigProperties configProperties = ConfigPropertiesUtil.resolveConfigProperties(sdkMock); | ||
|
||
assertThat(configProperties.getString(propertyName)).isEqualTo(expectedValue); | ||
} | ||
} | ||
|
||
@Test | ||
void shouldUseConfigProviderForDeclarativeConfiguration_noInstrumentationConfig() { | ||
AutoConfiguredOpenTelemetrySdk sdkMock = mock(AutoConfiguredOpenTelemetrySdk.class); | ||
ConfigProvider configProviderMock = mock(ConfigProvider.class); | ||
when(configProviderMock.getInstrumentationConfig()).thenReturn(null); | ||
|
||
try (MockedStatic<AutoConfigureUtil> autoConfigureUtilMock = | ||
Mockito.mockStatic(AutoConfigureUtil.class)) { | ||
autoConfigureUtilMock.when(() -> AutoConfigureUtil.getConfig(sdkMock)).thenReturn(null); | ||
autoConfigureUtilMock | ||
.when(() -> AutoConfigureUtil.getConfigProvider(sdkMock)) | ||
.thenReturn(configProviderMock); | ||
|
||
ConfigProperties configProperties = ConfigPropertiesUtil.resolveConfigProperties(sdkMock); | ||
|
||
assertThat(configProperties.getString("testProperty")).isEqualTo(null); | ||
} | ||
} | ||
} |
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
[for reviewer] This was extracted to separate public class (see ConfigPropertiesUtil) so can be used also for BeforeAgentListener's