- Notifications
You must be signed in to change notification settings - Fork 917
Add helper class to capture context using ScheduledExecutorService #6712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add helper class to capture context using ScheduledExecutorService #6712
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@ ## main #6712 +/- ## ============================================ - Coverage 90.09% 90.01% -0.08% - Complexity 6390 6482 +92 ============================================ Files 711 719 +8 Lines 19333 19585 +252 Branches 1891 1931 +40 ============================================ + Hits 17418 17630 +212 - Misses 1335 1355 +20 - Partials 580 600 +20 ☔ View full report in Codecov by Sentry. |
jkwatson left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good idea. This PR needs some more testing, as there are bunch of uncovered methods in the implementation.
Signed-off-by: Adriano Machado <60320+ammachado@users.noreply.github.com>
b6c022c to e5d7cc4 Compare context/src/main/java/io/opentelemetry/context/CurrentContextScheduledExecutorService.java Outdated Show resolved Hide resolved
context/src/main/java/io/opentelemetry/context/ForwardingScheduledExecutorService.java Outdated Show resolved Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private field in CurrentContextScheduledExecutorService.java can be removed
| private final ScheduledExecutorService delegate; | ||
| | ||
| CurrentContextScheduledExecutorService(ScheduledExecutorService delegate) { | ||
| super(delegate); | ||
| this.delegate = delegate; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private final ScheduledExecutorService delegate; | |
| CurrentContextScheduledExecutorService(ScheduledExecutorService delegate) { | |
| super(delegate); | |
| this.delegate = delegate; | |
| } | |
| CurrentContextScheduledExecutorService(ScheduledExecutorService delegate) { | |
| super(delegate); | |
| } |
| | ||
| @Override | ||
| public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { | ||
| return delegate.schedule(Context.current().wrap(command), delay, unit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return delegate.schedule(Context.current().wrap(command), delay, unit); | |
| return ((ScheduledExecutorService) delegate()) | |
| .schedule(Context.current().wrap(command), delay, unit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I prefer just keeping a local copy of the delegate rather than having to make this cast everywhere.
| | ||
| @Override | ||
| public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) { | ||
| return delegate.schedule(Context.current().wrap(callable), delay, unit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return delegate.schedule(Context.current().wrap(callable), delay, unit); | |
| return ((ScheduledExecutorService) delegate()) | |
| .schedule(Context.current().wrap(callable), delay, unit); |
| @Override | ||
| public ScheduledFuture<?> scheduleAtFixedRate( | ||
| Runnable command, long initialDelay, long period, TimeUnit unit) { | ||
| return delegate.scheduleAtFixedRate(command, initialDelay, period, unit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return delegate.scheduleAtFixedRate(command, initialDelay, period, unit); | |
| return ((ScheduledExecutorService) delegate()) | |
| .scheduleAtFixedRate(command, initialDelay, period, unit); |
| @Override | ||
| public ScheduledFuture<?> scheduleWithFixedDelay( | ||
| Runnable command, long initialDelay, long delay, TimeUnit unit) { | ||
| return delegate.scheduleWithFixedDelay(command, initialDelay, delay, unit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return delegate.scheduleWithFixedDelay(command, initialDelay, delay, unit); | |
| return ((ScheduledExecutorService) delegate()) | |
| .scheduleWithFixedDelay(command, initialDelay, delay, unit); |
No description provided.