How to propagate traceId to other threads in one transaction for Spring Boot 3.x along with Micrometer

71 Views Asked by At

I am learning to use Micrometer to tag traceId and spanId in my log. But I have a problem with one scenario: in one method, I wrote some multi-threading code. When I use Micrometer, it looks like only main thread has traceId and spanId, while traceId of other threads in that same method is null.

Some dummy code to show this:

public void doSomething() {
  log.info("here is main thread");
  executor.submit(() -> log.info("here is thread1"));
}

and the result would be: only the main thread log has traceId.

I know I could add some codes to start a new span and pass to threads. But ideally there could be implemented through by some configuration instead of inserting too much non-related code in my business method.

Is this supported, or just I need to manually create new span and pass it?

I am excepting to propagate same traceId to other threads in one transaction/method.

0

There are 0 best solutions below