[x] Bug fix (non-breaking change which fixes an issue)
[ ] New feature (non-breaking change which adds functionality)
Description
This change addresses an issue where tasks run in worker threads would be unable to properly resolve the original plugin calling context since the original call stack is lost. This resulted in bad telemetry in these scenarios when running the Amazon Q plugin.
To address this, this change refactors the PluginResolver class to allow each thread to have its own PluginResolver instance, while also supporting the ability for child threads to use the instance created by the parent thread. By using ThreadLocal, each thread has its own context for storing and retrieving the PluginResolver instance. A new threading utility function, pluginAwareExecuteOnPooledThread, wraps the original pooled thread execution logic and injects a resolved PluginResolver instance from the parent thread on the worker thread. This results in the worker inheriting the parent's correctly resolved plugin identifier.
Checklist
[x] My code follows the code style of this project
[x] I have added tests to cover my changes
[ ] A short description of the change has been added to the CHANGELOG if the change is customer-facing in the IDE.
[ ] I have added metrics for my changes (if required)
License
I confirm that my contribution is made under the terms of the Apache 2.0 license.
Types of changes
Description
This change addresses an issue where tasks run in worker threads would be unable to properly resolve the original plugin calling context since the original call stack is lost. This resulted in bad telemetry in these scenarios when running the Amazon Q plugin.
To address this, this change refactors the PluginResolver class to allow each thread to have its own
PluginResolver
instance, while also supporting the ability for child threads to use the instance created by the parent thread. By using ThreadLocal, each thread has its own context for storing and retrieving the PluginResolver instance. A new threading utility function,pluginAwareExecuteOnPooledThread
, wraps the original pooled thread execution logic and injects a resolvedPluginResolver
instance from the parent thread on the worker thread. This results in the worker inheriting the parent's correctly resolved plugin identifier.Checklist
License
I confirm that my contribution is made under the terms of the Apache 2.0 license.