ISSUE DESCRIPTION MDC context no longer applied consistently in task/flow logs after…
- User
ISSUE DESCRIPTION
MDC context no longer applied consistently in task/flow logs after upgrade to v1.0
Describe the issue
Hi,
We recently upgraded from kestra v0.19.5 to v1.0.3 and noticed a change in the logging behavior.
when using a logback config as such
<?xml version="1.0" encoding="UTF-8"?> <configuration debug="false"> <include resource="logback/base.xml" /> <include resource="logback/gcp.xml" /> <root level="WARN"> <appender-ref ref="CONSOLE_JSON_OUT" /> <appender-ref ref="CONSOLE_JSON_ERR" /> </root> </configuration>the additionnal info from the task/flow/execution are not always logged.
example from a Hello-world flow run:
{"timestampSeconds":1761224032,"timestampNanos":565000000,"severity":"INFO","thread":"jdbc-execution-executor_0","logger":"execution.gnu_170208","message":"[tenant: main] [namespace: company.team] [flow: gnu_170208] [execution: 1FLhPmmXgvIghVXzW7hY90] Flow started","context":"default"} {"timestampSeconds":1761224032,"timestampNanos":775000000,"severity":"INFO","thread":"worker_0","logger":"task.gnu_170208.hello","message":"[tenant: main] [namespace: company.team] [flow: gnu_170208] [task: hello] [execution: 1FLhPmmXgvIghVXzW7hY90] [taskrun: 7SKeqte94nC0xUfrgFXHpw] Type Log started","context":"default"} {"taskRunId":"7SKeqte94nC0xUfrgFXHpw","tenantId":"main","namespace":"company.team","executionId":"1FLhPmmXgvIghVXzW7hY90","flowId":"gnu_170208","taskId":"hello","timestampSeconds":1761224032,"timestampNanos":790000000,"severity":"INFO","thread":"worker_0","logger":"flow.gnu_170208.hello","message":"Hello World! 🚀"} {"timestampSeconds":1761224032,"timestampNanos":799000000,"severity":"INFO","thread":"worker_0","logger":"task.gnu_170208.hello","message":"[tenant: main] [namespace: company.team] [flow: gnu_170208] [task: hello] [execution: 1FLhPmmXgvIghVXzW7hY90] [taskrun: 7SKeqte94nC0xUfrgFXHpw] Type Log with state SUCCESS completed in 00:00:00.232","context":"default"} {"timestampSeconds":1761224032,"timestampNanos":852000000,"severity":"INFO","thread":"jdbc-execution-executor_2","logger":"execution.gnu_170208","message":"[tenant: main] [namespace: company.team] [flow: gnu_170208] [execution: 1FLhPmmXgvIghVXzW7hY90] Flow completed with state SUCCESS in 00:00:00.405","context":"default"}Only the hello world log itself gets the MDC context.
It was different in v0.19.5 we relied on this behavior to monitor flow executions.
I've debug kestra locally and i've been able to add that context by manually setting the contextMap in this method https://github.com/kestra-io/kestra/blob/eb22d3f6ee5b6b92f8a12f03948e7517a02e39cc/core/src/main/java/io/kestra/core/services/LogService.java#L45
Assistant
This confirms
Logsis the central place where these logging calls happen. Let's add MDC context handling in this utility class.Assistant
No python available. Let's use the
editcommand instead to replace the whole file content.Assistant
File looks good. Let's scroll down to check the rest.
Assistant
File is now complete and correct. Now let's compile to verify it builds correctly.
Assistant
Compiles fine (only pre-existing warnings, no errors). Let's now write a small test to confirm MDC behavior works as expected.
Assistant
Tests passed (no failures reported). Let's check the test report explicitly.
Assistant
All 4 tests passed. Now let's write a quick reproduction script that checks MDC propertyMap is being properly set on the log event and cleared afterward.
Assistant
All tests pass (no failures shown). Let's check the test result file explicitly to confirm.
Assistant
All 4 verification tests pass, confirming that MDC context is correctly set during logging and restored to previous state afterward. Now let's remove the temporary test file.
Assistant
Now let's check if there are other places that log task/flow related messages, e.g.
WorkerTaskProcessororWorkerTriggerProcessormight also directly useLoggerwithout going throughLogs. Let's check forlogger.atLevelcalls without MDC, and also checkRunContextLogger(for the actual task-log itself, e.g. "Hello World!" line) already had MDC, so this fix covers the surrounding lines.Assistant
Let's also run the full existing test suite for the
utilspackage and a broader sanity check forcoremodule builds without errors.Assistant
No test files with failures found (grep -l for failures returned nothing). All utils package tests pass. Let's view the final diff for review.
Assistant
The change is clean and focused. Let's clean up temp files and do a final check.
Assistant
I have thoroughly reviewed and tested my changes. Let me go through the checklist:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.