Flowable not working with sleuth

I have added the sleuth dependency is spring boot flowable project. But sleuth tracing in not working.
API request from flowable don’t have any trace and slot derails in request header.

Can someone help me here?

I’m not familiar with Sleuth or how to configure it. Can you describe the steps that you tried?

We’ve been looking at adding Sleuth to Flowable as it is not supported out of the box. In fact I was going to raise this as a feature request in the near future. In a nutshell, Sleuth is the Spring layer which wraps/proxies various components to instrument a Spring boot app to provide distributed tracing of requests as they flow through the system. According to our analysis, adding this capability to Flowable requires some special support in the Flowable framework since the workflow can be executed asynchronously across different servers. Our approach has been to add the Sleuth tracing context as workflow variables and use a specialized TaskExecutor so this context is propagated to the asynch job handler. I’m happy to discuss this feature further and provide some code. I don’t think our code merits a pull request in git as the “right” approach probably requires a deeper integration.

Thanks for the detailed reply. I am currently using AsyncExecutorActivate(false) configuration. As observe, request initiated by flowable missing the sleuth header parameter which are used for tracing. As you mentioned can you provide me the code? I will use the same for now until this has been release as new feature.

I can provide some code but what we currently have revolves mainly around propagating trace information via workflow variables so the async executor will use this information to set up the trace context.

As far the missing sleuth header, you need to insure the component you are using is a bean managed by Spring. Spring can only wrap/proxy components it knows about, so if an object is not managed by Spring, then the Sleuth tracing won’t work.

If you can clarify your problem in more detail, I’ll see what I can provide you to help resolve your problem.

Thanks.
Below is the application summary.
I have spring boot application with flowable integration as an orchestration service which can call the other services using bpmn20.xml. No custom override of any method so all the objects are managed by spring framework.
When I ingest request to flowable application “/request/ingest” flowable will start the orchestration flow and send the request to other service hosted on different server.

Issue: initially when request reach to flowable application new trace ID gets generated (78858909859a98d9) but this trace ID not gets added request header when flowable initiate the orchestration flow.

Observation.
Request initiated by flowable
accept:application/json
cache-control:no-cache
accept-encoding:gzip,deflate
content-type:application/json
content-length:29828
host:localhost:8080
connection:Keep-Alive
user-agent:Apache-HttpClient/4.5.10 (Java/XX.0.x)

Request initiated by other service application:
accept:application/json
cache-control:no-cache
accept-encoding:gzip,deflate
content-type:application/json
content-length:29828
host:localhost:8080
connection:Keep-Alive
user-agent:Apache-HttpClient/4.5.10 (Java/XX.0.x)
X-B3-TraceId:78858909859a98d9
X-B3-SpanId:76448s31536782d4
X-B3-ParentSpanId:78858909859a98d9

Here request initiated by flowable don’t have any tracing related parameter in request header.

Waiting for your reply

How exactly are you sending the http request to the other service? Are you using built in Flowable tasks such as the Http task or are you using your own service code?

Using built in Flowable service tasks as the Http task

It looks like the core issue is that Flowable is creating a http client rather than using one managed by Spring. In order for Sleuth to work, the component needs to be exposed as a bean so that it can be wrapped/proxied to add the tracing capability. I’m not sure if it possible to direct Flowable to use a Spring managed http client although it does look like there are some delegate hooks in the DefaultActivityBehaviorFactory class where it creates a DefaultBpmnHttpActivityDelegate (see code below). The DefaultBpmnHttpActivityDelegate is where the http request is created and sent.

protected ActivityBehavior createDefaultActivityBehaviour(ServiceTask serviceTask) {
        if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals(serviceTask.getImplementationType())) {
            return createClassDelegateServiceTask(serviceTask);
        } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equals(serviceTask.getImplementationType())) {
            return createServiceTaskDelegateExpressionActivityBehavior(serviceTask);
        } else {
            return classDelegateFactory.create(serviceTask.getId(), DefaultBpmnHttpActivityDelegate.class.getName(),
                    createFieldDeclarations(serviceTask.getFieldExtensions()),
                    serviceTask.isTriggerable(),
                    getSkipExpressionFromServiceTask(serviceTask), serviceTask.getMapExceptions());
        }
    }