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 update the tests to assert the MDC context is present on the events and doesn't leak:
- Assistant
I'll wait for the background test run to complete — it will notify when done.
- Assistant
The Gradle daemon is still spinning up (first build in this environment can take a while). I'll wait for the background task and monitor notifications rather than polling.
- Assistant
The implementation looks correct. Now waiting for the test run to complete — the monitor will notify when the build finishes.
- Assistant
Gradle daemon is compiling. I'll stop polling and let the background task notification arrive.
- Assistant
The build is still resolving dependencies/compiling (first Gradle invocation in this environment). Both monitors are armed — I'll continue when they fire.
- Assistant
The build is executing in the daemon. I'll wait for the monitors to notify on completion.
- Assistant
Both the Gradle client and daemon are alive; the daemon is network-bound resolving dependencies. This is expected for a first build. Let me check what it's actually waiting on:
- Assistant
The killed run never completed the build (exit 0 was from the kill, no test results). Restarting with IPv6 preference disabled:
- Assistant
The background run will notify on completion. Let me verify after a short while that downloads are now progressing:
- Assistant
Done. The fix is implemented and verified.
Root cause
In v0.19.5, server lifecycle messages ("Flow started", "Type Log started", …) were logged through loggers whose context carried the execution MDC, so JSON layouts (like the Stackdriver layout, which does
map.putAll(event.getMDCPropertyMap())) emittedtenantId/namespace// as structured fields. After the v1.0 refactoring that replaced with the static utility (commit ), these messages go through plain SLF4J loggers (, , ) with no MDC — only task logs emitted via still set it, which matches exactly what you observed. - Assistant
That's just the stale monitor from the first (killed) build run timing out — no action needed. The task was already completed and verified with the second run:
LogsTestpassed with 5 tests, 0 failures, and the MDC fix incore/src/main/java/io/kestra/core/utils/Logs.javais in place.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.