MDC context no longer applied consistently in task/flow logs after upgrade to v1.0…
- User
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<?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:
json{"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"} - Assistant
Now let me find where MDC is currently set (for the task's own logs, which do carry context):
- Assistant
Now let me look at the existing test:
- Assistant
Now update the test to assert the MDC context is captured on the events and doesn't leak afterwards:
- Assistant
Now run the test:
- Assistant
The test is running in the background; I'll wait for it to complete.
- Assistant
The diff looks good. Waiting for the test run to finish.
- Assistant
Still compiling. I'll wait for the background monitors to report the result.
- Assistant
The build is still in progress. I'll report once the background watcher signals completion.
- Assistant
Gradle daemon is running and the test task output is buffered through
tail, so nothing appears until it finishes. Waiting for completion notification. - Assistant
All watchers are armed. I'll wait for the test result notification and then confirm the outcome.
- Assistant
The original Gradle test run (b97hwba40) is still compiling — its output stays empty until the
tailpipe flushes at completion. Still waiting on its completion notification and the monitor watching forBUILD SUCCESSFUL/FAILED. - Assistant
Waiting for the Gradle run to finish; I'll report the test result as soon as the process exits.
- Assistant
All 5 tests pass —
BUILD SUCCESSFUL(the wait-watchers have also all cleaned up).Done — fix verified
Root cause: In v0.19.x,
RunContextLoggerpopulated the global thread-local MDC (MDC.setContextMap(...)), and that context incidentally leaked into server-side task/flow/execution logs emitted on the same executor/worker threads. Commit151d4d9da("fix(core): use the MDC from the loggin context", shipped in v1.0) moved the MDC into an isolated per-run — correct in itself, but it silently removed the MDC fields from the server logs your JSON layout (Stackdriver) relies on.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.