I have an application based on Serverless workflows, these work with Kogito Workflow framework built on Quarkus.
I need to add an MDC property to all logs within the same context, I have incoming reactive channels for this. I think I might be able to use a Channel decorator to add the property when a message is received like:
@ApplicationScoped
public class ConsumedMessageDecorator implements SubscriberDecorator {
@Override
public int getPriority() {
return 10;
}
@Override
public Multi<? extends Message<?>> decorate(Multi<? extends Message<?>> toBeSubscribed, List<String> channelName,
boolean isConnector) {
return toBeSubscribed.onItem().invoke(message -> {
if (MDC.get("txid") == null) {
MDC.put("txid", UUID.randomUUID());
}
});
}
}
Not really sure if this is the best approach, and more importantly I don't have a clue where to place:
MDC.clear();
Because a workflow can run multiple steps and push messages to it self within the same request.
Any ideas?
Thanks in advance