Class TracingExecutor
- All Implemented Interfaces:
Executor
Executor so that
- the trace context (and any other
ThreadLocalAccessor-backed state) active when a task is submitted is restored when the task runs; and - each task gets its own
vaadin.ui.accessspan when anObservationRegistryis supplied. The span is parented to the propagated trace, so work handed to the executor from a request thread ends up with a continuous trace tree across the thread hop.
The service executor is what Vaadin uses to dispatch signal effects and
result notifications, and what applications are expected to use for their own
background tasks (typically ones that end with UI.access(...)); it is
not used by UI.access itself, which runs pending commands on the
thread that unlocks the session.
Use wrap(Executor, ObservationRegistry) rather than the constructors
so that an ExecutorService delegate keeps its lifecycle methods:
Vaadin shuts its default executor down on service destroy, and only does so
when the executor still is an ExecutorService.
-
Constructor Summary
ConstructorsConstructorDescriptionTracingExecutor(Executor delegate) TracingExecutor(Executor delegate, io.micrometer.observation.ObservationRegistry observationRegistry) -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected final Runnableinstrument(Runnable command) Captures the current context and returns a task that restores it and opens avaadin.ui.accessspan before runningcommand.protected final <T> Callable<T> instrument(Callable<T> task) static ExecutorWraps the given executor for tracing, preserving theExecutorServicecontract when the delegate implements it.
-
Constructor Details
-
TracingExecutor
-
TracingExecutor
public TracingExecutor(Executor delegate, io.micrometer.observation.ObservationRegistry observationRegistry)
-
-
Method Details
-
wrap
public static Executor wrap(Executor delegate, io.micrometer.observation.ObservationRegistry observationRegistry) Wraps the given executor for tracing, preserving theExecutorServicecontract when the delegate implements it.Wrapping is idempotent: an executor that already traces is returned as-is.
- Parameters:
delegate- the executor to wrap, notnullobservationRegistry- the registry used to create the per-task span, may benullto only propagate the context- Returns:
- the tracing executor
-
execute
-
instrument
Captures the current context and returns a task that restores it and opens avaadin.ui.accessspan before runningcommand.Must be called on the submitting thread, since that is where the context to propagate lives.
- Parameters:
command- the task to instrument, notnull- Returns:
- the instrumented task
-
instrument
- Type Parameters:
T- the task result type- Parameters:
task- the task to instrument, notnull- Returns:
- the instrumented task
-