Skip to content

TraceRunnable does not let you to get delegate and extract context data. #2261

Closed
@sta-szek

Description

Hi,
when I use TaskExecutor and tracing autoinstrumentation from spring-cloud-sleuth then it is problematic to handle rejected tasks.
My task are custom implementations of Runnable, and they contain tenant info.

If the task fails, I want to get this tenant info and process.
But unfortunatelly, that is not possible, as TraceRunnable does not have methods that would allow me to get the delegate Runnable - in my case my custom Runnable implementation.

Example lines of code:

    private RejectedExecutionHandler createRejectedExecutionHandler(ServiceInitializer serviceInitializer) {
        return (task, executor) -> {
            if (task instanceof XXXRunnableClass) { // this will never be the case, as it always will be `TraceRunnable`, which is created in `org.springframework.cloud.sleuth.instrument.async.LazyTraceAsyncTaskExecutor#execute(java.lang.Runnable)`

Describe the solution you'd like
I would be happy if TraceRunnable provides method Runnable getDelegate()

Describe alternatives you've considered
Alternatively, i could use TaskExecutor which is not wrapped with LazyTraceAsyncTaskExecutor and do tracing on my own, but i dont like reimplementing and maintaining that solution.
The second approach could be to use reflection with casting but, ... that would be ugly as well...

Additional context
I am using spring boot 2.7.8

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions