You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
Currently, the io.opentelemetry.context.CurrentContextExecutorService class, used to wrap ExecutorService with tracing context propagation, is non-public. As a result, there is no public API to determine if an ExecutorService is already wrapped. This limitation makes it challenging to avoid excessive wrapping or recursive wrapping in scenarios where multiple components may apply OpenTelemetry wrapping independently.
Use Case
In our application, we use OpenTelemetry to enable tracing across multiple services. During the setup of our custom Aspect for MQTT consumers, we encountered a scenario where multiple layers could potentially wrap an ExecutorService. Since CurrentContextExecutorService is non-public, there is no way to check if an executor is already wrapped.
The absence of such a mechanism leads to potential issues:
1. Performance Overhead: Re-wrapping executors multiple times unnecessarily adds extra layers and CPU/memory usage. 2. Circular Dependencies: Repeated wrapping can result in unintended behaviors, including stack overflow exceptions in some cases.
A public method to check if an executor is already wrapped would allow developers to handle this elegantly and avoid redundant wrapping.
Proposed Solution
Expose a utility method or make CurrentContextExecutorService public, enabling developers to check if an 'ExecutorService' is already wrapped. For example:
public static boolean isTaskWrapping(Executor executor) {
// Internal check for wrapping
}
This approach would make it straightforward for developers to ensure their wrapping logic is idempotent.
Potential Impact 1. Improved Developer Experience: Simplifies scenarios where multiple layers apply OpenTelemetry wrapping, improving usability. 2. Avoid Performance Overhead: Ensures that executors are wrapped only once, reducing unnecessary overhead. 3. Enhances Debugging: Provides better insight for developers when debugging issues related to executor wrapping.
Steps to Reproduce the Issue
Create an ExecutorService.
Wrap the executor using Context.taskWrapping(executor).
Attempt to check if the executor is already wrapped without relying on non-public classes.
Request for Feedback
I would appreciate feedback on this proposal and happy to contribute a pull request if maintainers are open to this enhancement.
Call to Action
Please consider this feature request for inclusion in a future release of OpenTelemetry. Let us know if there's an alternative approach we can take to solve this issue.
The text was updated successfully, but these errors were encountered:
Another options would be to adjust the behavior of the utility methods that provide the wrapped Executors to not duplicate the wrapping. I.e. something like:
default ExecutorService wrap(ExecutorService executor) {
if (executor instanceof ContextExecutorService) {
return executor;
}
return new ContextExecutorService(this, executor);
}
Description
Currently, the
io.opentelemetry.context.CurrentContextExecutorService
class, used to wrapExecutorService
with tracing context propagation, is non-public. As a result, there is no public API to determine if anExecutorService
is already wrapped. This limitation makes it challenging to avoid excessive wrapping or recursive wrapping in scenarios where multiple components may apply OpenTelemetry wrapping independently.Use Case
In our application, we use OpenTelemetry to enable tracing across multiple services. During the setup of our custom
Aspect
for MQTT consumers, we encountered a scenario where multiple layers could potentially wrap anExecutorService
. SinceCurrentContextExecutorService
is non-public, there is no way to check if an executor is already wrapped.The absence of such a mechanism leads to potential issues:
1. Performance Overhead: Re-wrapping executors multiple times unnecessarily adds extra layers and CPU/memory usage.
2. Circular Dependencies: Repeated wrapping can result in unintended behaviors, including stack overflow exceptions in some cases.
A public method to check if an executor is already wrapped would allow developers to handle this elegantly and avoid redundant wrapping.
Proposed Solution
Expose a utility method or make
CurrentContextExecutorService
public, enabling developers to check if an 'ExecutorService' is already wrapped. For example:Alternatively, add a public method in
Context
:This approach would make it straightforward for developers to ensure their wrapping logic is idempotent.
Potential Impact
1. Improved Developer Experience: Simplifies scenarios where multiple layers apply OpenTelemetry wrapping, improving usability.
2. Avoid Performance Overhead: Ensures that executors are wrapped only once, reducing unnecessary overhead.
3. Enhances Debugging: Provides better insight for developers when debugging issues related to executor wrapping.
Steps to Reproduce the Issue
ExecutorService
.Context.taskWrapping(executor)
.Request for Feedback
I would appreciate feedback on this proposal and happy to contribute a pull request if maintainers are open to this enhancement.
Call to Action
Please consider this feature request for inclusion in a future release of OpenTelemetry. Let us know if there's an alternative approach we can take to solve this issue.
The text was updated successfully, but these errors were encountered: