0

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

josesuero
  • 3,260
  • 2
  • 13
  • 19

1 Answers1

0

Do you need a different property value for each message? When you say "context", what are you referring to? Usually MDC is used when you want to print some value which is shared across an operation (and that value is not accessible in the method where you are logging or you forgot to log it or you want to conditionally log it) , but in the case of every message, which are the operation boundaries? (in MDC terminology, when to call clear()).

  • I need the same value for all logs within the same operation, for a serverless operation it's the actions taken from when this message was received, to the steps taken in the workflow automatically until it stopped to get a new message. – josesuero Mar 13 '23 at 08:10
  • But what do you mean by operation? A message received is translated to three potential operations: message discarded, start a new flow or resume a paused flow. I think is worh for you to explore, rather than using MDC, to implement something like this https://github.com/kiegroup/kogito-runtimes/blob/main/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow/src/main/java/org/kie/kogito/serverless/workflow/devservices/DevModeServerlessWorkflowLogger.java, where you can control the logs that the flow execution is printing – Francisco Javier Tirado Sarti Mar 14 '23 at 10:35