Skip to content

Add a ConfigProvider callback for runtime instrumentation option changes#8076

Open
jackshirazi wants to merge 4 commits intoopen-telemetry:mainfrom
jackshirazi:config-provider-callback
Open

Add a ConfigProvider callback for runtime instrumentation option changes#8076
jackshirazi wants to merge 4 commits intoopen-telemetry:mainfrom
jackshirazi:config-provider-callback

Conversation

@jackshirazi
Copy link
Contributor

First step in adding support for runtime changes to options, focusing only on API additions.

The assumption is that if an instrumentation is able to handle changes at runtime, it will register a callback against the ConfigProvider instance that the otel SDK is using.

Further steps (to be discussed):

  • Add spec change for runtime config updates and listener semantics
  • Expose getConfigProvider() in the SDK API
  • Provide a "change mechanism" for example, mutable provider or equivalent update source
  • Add implementations

@codecov
Copy link

codecov bot commented Feb 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.21%. Comparing base (0a1a2ce) to head (39b9c63).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8076      +/-   ##
============================================
+ Coverage     90.20%   90.21%   +0.01%     
- Complexity     7594     7608      +14     
============================================
  Files           841      841              
  Lines         22915    22924       +9     
  Branches       2290     2291       +1     
============================================
+ Hits          20670    20682      +12     
+ Misses         1529     1526       -3     
  Partials        716      716              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jackshirazi jackshirazi marked this pull request as ready for review February 12, 2026 15:43
@jackshirazi jackshirazi requested a review from a team as a code owner February 12, 2026 15:43
Comment on lines 77 to 80
default AutoCloseable addInstrumentationConfigChangeListener(
InstrumentationConfigChangeListener listener) {
return () -> {};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdyt about

addConfigChangeListener(".instrumentation.xyz", listener)

to cover also .general nodes, e.g. .general.http.server.request_captured_headers

interface ConfigChangeListener {
   void onChange();
}

and listeners can use ConfigProvider to get the latest value (imagining shared code path with initial setup, but not sure)

not sure if previous config is needed? if it's just a rare case, instrumentation could be responsible for maintaining their own previous config

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I'll add the path and remove previous

*/
default AutoCloseable addInstrumentationConfigChangeListener(
InstrumentationConfigChangeListener listener) {
return () -> {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a default implementation. This is still experimental so we can add new methods without worrying about compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. But this default is a safe fallback, I added it for that reason rather than for compatibility. I'm not against removing and implementing it in the implementations, but it's a good default

* @param listener the listener to notify when instrumentation configuration changes
* @return an {@link AutoCloseable} handle that can be closed to unregister the listener
*/
default AutoCloseable addInstrumentationConfigChangeListener(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have mixed feelings about using AutoCloseable here. IDE's will warn " used without 'try'-with-resources statement", where this isn't a traditional resource that must be to avoid a memory leak or other problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with switching to a new ListenerRegistration interface that extends AutoCloseable, wdyt?

* @param previousConfig the previous effective configuration, or {@code null} if unavailable
* @param newConfig the updated effective configuration for {@code instrumentationName}
*/
void onChange(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So with this pattern the listener is responsible for filtering through these change events and only reacting to ones of interest?

What if an instrumentation is interested in both .instrumentation/development.general.http and .instrumentation/development.java.<library_name>? Presumably, a change to instrumentation config which touched both would result in two separate invocations to the listener?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the assumption is listeners only get notified on events they register for. For updates that affect multiple top-level nodes, the expectation is one callback per changed node. I’ll make that explicit in javadocs

* <p>{@code newConfig} is never null. If the node is unset or cleared, {@code newConfig} is
* {@link DeclarativeConfigProperties#empty()}.
*
* @param instrumentationName the top-level instrumentation name that changed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to be able to watch .instrumentation/development.general.* nodes in addition to .instrumentation/development.java.* nodes. What does instrumentationName look like for these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll clarify in javadoc along with Trask's suggested change which also changes scope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants