-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OpenTelemetry support on WorkQueueManager
Signed-off-by: Adriano Machado <60320+ammachado@users.noreply.github.com>
- Loading branch information
Showing
7 changed files
with
150 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...c/main/java/org/apache/cxf/tracing/opentelemetry/OpenTelemetryAutomaticWorkQueueImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.apache.cxf.tracing.opentelemetry; | ||
|
||
import org.apache.cxf.tracing.opentelemetry.internal.CurrentContextThreadPoolExecutor; | ||
import org.apache.cxf.workqueue.AutomaticWorkQueueImpl; | ||
|
||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.ThreadFactory; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class OpenTelemetryAutomaticWorkQueueImpl extends AutomaticWorkQueueImpl { | ||
|
||
@Override | ||
protected ThreadPoolExecutor createThreadPoolExecutor( | ||
int corePoolSize, | ||
int maximumPoolSize, | ||
long keepAliveTime, | ||
TimeUnit unit, | ||
BlockingQueue<Runnable> workQueue, | ||
ThreadFactory threadFactory, | ||
AutomaticWorkQueueImpl.WatchDog watchDog | ||
) { | ||
return new CurrentContextThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory) { | ||
|
||
@Override | ||
protected void terminated() { | ||
ThreadFactory f = this.getThreadFactory(); | ||
if (f instanceof AWQThreadFactory awqThreadFactory) { | ||
awqThreadFactory.shutdown(); | ||
} | ||
if (watchDog != null) { | ||
watchDog.shutdown(); | ||
} | ||
} | ||
}; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...src/main/java/org/apache/cxf/tracing/opentelemetry/OpenTelemetryWorkQueueManagerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.apache.cxf.tracing.opentelemetry; | ||
|
||
import org.apache.cxf.Bus; | ||
import org.apache.cxf.bus.managers.WorkQueueManagerImpl; | ||
import org.apache.cxf.workqueue.AutomaticWorkQueue; | ||
|
||
public class OpenTelemetryWorkQueueManagerImpl extends WorkQueueManagerImpl { | ||
|
||
public OpenTelemetryWorkQueueManagerImpl(Bus bus) { | ||
super(bus); | ||
} | ||
|
||
@Override | ||
public synchronized AutomaticWorkQueue getAutomaticWorkQueue() { | ||
return new OpenTelemetryAutomaticWorkQueueImpl(); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
.../java/org/apache/cxf/tracing/opentelemetry/internal/CurrentContextThreadPoolExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.apache.cxf.tracing.opentelemetry.internal; | ||
|
||
import io.opentelemetry.context.Context; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.Future; | ||
import java.util.concurrent.RunnableFuture; | ||
import java.util.concurrent.ThreadFactory; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
public class CurrentContextThreadPoolExecutor extends ThreadPoolExecutor { | ||
|
||
public CurrentContextThreadPoolExecutor( | ||
int corePoolSize, | ||
int maximumPoolSize, | ||
long keepAliveTime, | ||
TimeUnit unit, | ||
BlockingQueue<Runnable> workQueue, | ||
ThreadFactory threadFactory | ||
) { | ||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory); | ||
} | ||
|
||
@Override | ||
protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) { | ||
return super.newTaskFor(Context.current().wrap(runnable), value); | ||
} | ||
|
||
@Override | ||
protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) { | ||
return super.newTaskFor(Context.current().wrap(callable)); | ||
} | ||
|
||
@Override | ||
public Future<?> submit(Runnable task) { | ||
return super.submit(Context.current().wrap(task)); | ||
} | ||
|
||
@Override | ||
public <T> Future<T> submit(Runnable task, T result) { | ||
return super.submit(Context.current().wrap(task), result); | ||
} | ||
|
||
@Override | ||
public <T> Future<T> submit(Callable<T> task) { | ||
return super.submit(Context.current().wrap(task)); | ||
} | ||
|
||
@Override | ||
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException { | ||
return super.invokeAny(wrap(tasks)); | ||
} | ||
|
||
@Override | ||
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { | ||
return super.invokeAny(wrap(tasks), timeout, unit); | ||
} | ||
|
||
@Override | ||
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException { | ||
return super.invokeAll(wrap(tasks)); | ||
} | ||
|
||
@Override | ||
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException { | ||
return super.invokeAll(wrap(tasks), timeout, unit); | ||
} | ||
|
||
@Override | ||
public void execute(Runnable command) { | ||
super.execute(Context.current().wrap(command)); | ||
} | ||
|
||
protected static <T> Collection<? extends Callable<T>> wrap(Collection<? extends Callable<T>> tasks) { | ||
return tasks.stream().map(task -> Context.current().wrap(task)).toList(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
integration/tracing/tracing-opentelemetry/src/main/resources/META-INF/cxf/bus-extensions.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.apache.cxf.tracing.opentelemetry.OpenTelemetryWorkQueueManagerImpl:org.apache.cxf.workqueue.WorkQueueManager:true |