Springboot 3.3.0 — распространение MDC на ложный потокJAVA

Программисты JAVA общаются здесь
Anonymous
Springboot 3.3.0 — распространение MDC на ложный поток

Сообщение Anonymous »

Мне нужно знать, как передать MDC (сопоставленный диагностический контекст), который я использую в основном потоке, в поток, который Feign использует для вызова другой службы.
Такая необходимость возникает. от требования отслеживать поток в серии логов. В настоящее время вызов клиента, который использует другой поток, теряется среди всех остальных журналов.

Код: Выделить всё

[
{"timestamp": "2024-07-02T10:00:00", "level": "INFO", "thread": "MainThread", "mdc": {"userID": "12345", "flowID": "abcde"}, "message": "Starting process for user 12345"},
{"timestamp": "2024-07-02T10:00:01", "level": "INFO", "thread": "MainThread", "mdc": {"userID": "12345", "flowID": "abcde"}, "message": "Processing data for user 12345"},
{"timestamp": "2024-07-02T10:00:02", "level": "INFO", "thread": "MainThread", "mdc": {"userID": "12345", "flowID": "abcde"}, "message": "Preparing to call external service for user 12345"},

**{"timestamp": "2024-07-02T10:00:03", "level": "INFO", "thread": "FeignThread", "message": "Calling external service"}**,

{"timestamp": "2024-07-02T10:00:04", "level": "INFO", "thread": "FeignThread", "mdc": {}, "message": "Received response from external service"},
{"timestamp": "2024-07-02T10:00:05", "level": "INFO", "thread": "MainThread", "mdc": {"userID": "12345", "flowID": "abcde"}, "message": "Completed processing for user 12345"},
{"timestamp": "2024-07-02T10:00:06", "level": "INFO", "thread": "MainThread", "mdc": {"userID": "67890", "flowID": "fghij"}, "message": "Starting process for user 67890"},
{"timestamp": "2024-07-02T10:00:07", "level": "INFO", "thread": "MainThread", "mdc": {"userID": "67890", "flowID": "fghij"}, "message": "Processing data for user 67890"},
{"timestamp": "2024-07-02T10:00:08", "level": "INFO", "thread": "MainThread", "mdc": {"userID": "67890", "flowID": "fghij"}, "message": "Preparing to call external service for user 67890"}
]
как вы можете видеть, объект mdc в притворном потоке не существует
спасибо за помощь

Подробнее здесь: https://stackoverflow.com/questions/786 ... ign-thread

Вернуться в «JAVA»