[dynamic control] wire up first policy#2833
Open
jackshirazi wants to merge 4 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to make the first dynamic-control policy (TraceSamplingRatePolicy) selectable via policy-init configuration by registering the policy type string to its policy class/initializer, and ensuring the policy initializer produces the corresponding implementer.
Changes:
- Added registration hook so
TraceSamplingRatePolicycan be registered withPolicyInit.registerPolicyType(...). - Updated
TraceSamplingRatePolicy.initialize(...)to return aPolicyImplementer(created with the installedDelegatingSampler). - Added a
PolicyInitTestcovering the “no init-config properties present” (non-initialization) path.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| dynamic-control/src/test/java/io/opentelemetry/contrib/dynamic/policy/registry/PolicyInitTest.java | Adds tests around PolicyInit.init(...) behavior when init-config properties are absent. |
| dynamic-control/src/main/java/io/opentelemetry/contrib/dynamic/policy/tracesampling/TraceSamplingRatePolicy.java | Returns an implementer from initialization and adds a policy-type registration method. |
| dynamic-control/src/main/java/io/opentelemetry/contrib/dynamic/policy/registry/PolicyInit.java | Registers TraceSamplingRatePolicy in the static bootstrap. |
Comments suppressed due to low confidence (2)
dynamic-control/src/test/java/io/opentelemetry/contrib/dynamic/policy/registry/PolicyInitTest.java:57
- These two tests are currently identical (both only verify that YAML/JSON init config properties are missing) but the second test name refers to missing top-level declarative telemetry policy config. Consider removing the duplicate or rewriting one test to exercise
PolicyInit.initFromDeclarativeConfig(...)so the test intent matches what’s actually being validated.
@Test
void doesNotInitializePolicyWhenTopLevelTelemetryPolicyDeclarativeConfigMissing() {
AutoConfigurationCustomizer customizer = mock(AutoConfigurationCustomizer.class);
PolicyInit.init(customizer);
Function<ConfigProperties, Map<String, String>> propertiesCustomizer =
capturePropertiesCustomizer(customizer);
ConfigProperties config = mock(ConfigProperties.class);
when(config.getString(PolicyInitConfig.POLICY_INIT_CONFIG_PROPERTY_YAML)).thenReturn(null);
when(config.getString(PolicyInitConfig.POLICY_INIT_CONFIG_PROPERTY_JSON)).thenReturn(null);
Map<String, String> ignored = propertiesCustomizer.apply(config);
dynamic-control/src/test/java/io/opentelemetry/contrib/dynamic/policy/registry/PolicyInitTest.java:76
invokeStaticNoArg()uses reflective access (setAccessible(true)) to callTraceSamplingRatePolicy.resetForTest. This is brittle (can be restricted by JVM access rules) and makes the test harder to maintain. Prefer placing the test in the same package as the method, or exposing a test-only reset hook without reflection (e.g., package-private in the test package or an explicit@VisibleForTesting-stylemethod).
private static void invokeStaticNoArg(Class<?> targetClass, String methodName) throws Exception {
Method method = targetClass.getDeclaredMethod(methodName);
method.setAccessible(true);
method.invoke(null);
}
LikeTheSalad
approved these changes
May 13, 2026
jaydeluca
reviewed
May 21, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description:
Wire up TraceSamplingRatePolicy so it can be used in config.
Existing Issue(s):
#2546
Testing:
Added
Documentation:
Included
Outstanding items:
Wiring up the policy pipeline:
Steps needed for the wiring: