Skip to content

Conversation

jackshirazi
Copy link
Contributor

Description:

I'd like to dynamically enable/disable inferred spans, but it looks like a lot of work to get to dynamically initializing and loading/unloading. So instead I've gone for this option, which is to let the interval be dynamically updated. You would need to have inferred spans enabled to use it, but after that you could change the interval, including to a very large value that effectively stops inferred spans doing anything (though the objects would all still be there and loaded)

Existing Issue(s):

None, though part of the overall "making the agent more dynamic" task set eg open-telemetry/opentelemetry-java-instrumentation#12251

Testing:

Test class added, but end-to-end testing still needs adding (it's not straightforward but I'll do that when I test these changes in our distribution). The changes shouldn't affect the existing functionality

Documentation:

It needs additional documentation on an example of how to use this feature, that's to come after teh above testing

Outstanding items:

Currently the changes are completely API based. I'm not proposing to add any config based support, but that could be added easily. End-to-end testing and example documentation of using the API are needed

@jackshirazi jackshirazi requested a review from a team as a code owner August 21, 2025 14:51
@jackshirazi jackshirazi changed the title Add dynamically changing the interval Add dynamically changing the inferred span interval Aug 21, 2025
@otelbot-java-contrib
Copy link
Contributor

🔧 The result from spotlessApply was committed to the PR branch.

public void reschedule() {
Future<?> future = this.profilingTask;
if (future != null) {
if (future.cancel(true)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (future.cancel(true)) {
if (future.isDone() || future.cancel(true)) {

So the javadoc for Future.cancel() says that it returns

"false if the task could not be cancelled, typically because it has already completed;

If the thing finishes right before/when this reschedule() is invoked, we still want to kick it off again, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the task has already completed, it has already scheduled the next task, so on isDone() we do NOT want to schedule a new task in this reschedule() method

Copy link
Contributor

@breedx-splk breedx-splk left a comment

Choose a reason for hiding this comment

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

Looks good to me, so approving. I did have one comment about a potential race condition, so I'll wait to merge until that's figured out. Thanks!

Comment on lines +62 to +63
config.setProfilerInterval(interval);
profiler.reschedule();
Copy link
Contributor

Choose a reason for hiding this comment

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

If I get this correctly, when we "disable at runtime", it means:

  • a very long profiler interval is configured
  • reschedule() is executed and schedules profiling execution very far in the future

When we then "enable it at runtime", it means:

  • a relatively short profiler interval is configured
  • reschedule() is executed and schedules profiling execution accordingly to the interval (so in the close future)

In the case where the value set to disable is not large enough, for example 1 day, then it means that we will get one extra scheduled execution, which is probably not what we expect here.

I think it would probably be better to define a specific value/threshold to indicate that the profiler should be considered as disabled (zero or a significant value), it could then allow to avoid re-scheduling when such value is configured.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is documentation rather than anything for the code. The code change is not disabling anything, it's purely making the interval dynamically changeable.

A separate note for the doc (I'll do that in another change as I need to think about also how to explain using this dynamic capability for an example) is that choosing a very long time (eg max long) effectively disables the inferred spans, while leaving it in a state where it could be re-enabled

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.

4 participants