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
Now let's check TaskRun and FlowId classes for available fields (executionKind, etc).
Assistant
Now let's check TaskRun fields for value.
Assistant
Now I'll implement the fix using MDC with try/finally to preserve previous MDC context.
Assistant
Now let's try to compile core module to verify no syntax errors.
Assistant
Compiled successfully (only pre-existing warnings). Now let's check whether other modules that use Logs.java compile fine too.
Assistant
All compiled fine. Now let's write a quick test to verify MDC works via a simple script.
Assistant
Let's run this existing test to check compatibility.
Assistant
All 4 tests passed (0 failures/errors). Now let's write a quick manual reproduce script to confirm MDC is actually set during the logging call (test the actual fix).
Assistant
No python3, edit manually via replace command.
Assistant
Test passed (no failure output this time, no "BUILD FAILED"). Let's verify explicitly.
Assistant
The MDC context is now properly set during logging (verified via captured MDCPropertyMap containing tenantId, namespace, flowId, executionId) and properly cleared/restored afterward. Now let's remove the temporary test file.
Assistant
Now let's re-run the full existing LogsTest suite to make sure everything still passes cleanly, and also run broader tests that might depend on Logs (e.g., in executor/worker modules) to be safe.
Assistant
All 4 tests pass. Now let's look for other places in the codebase that might also need similar fix — e.g., DefaultExecutor.java line 794, or any other place setting up loggers directly with prefixes but not MDC (e.g., worker processors).
Assistant
Good, no other place duplicates this pattern outside Logs.java. Let's also check
PluginDefaultService.javausage to ensure it usesLogs.logExecution(flow, log, ...)which is covered.Assistant
This is fine, covered by the fixed
Logs.logExecution(FlowId, ...)method. Now let's view the full diff for review.Assistant
Only the intended file is modified. Now let's also run a broader relevant test suite (e.g., ExecutorService tests, WorkerTaskProcessor tests) to double-check nothing broke due to MDC leakage across shared thread-pool executions.
Assistant
Good — all covered by the centralized fix in
Logs.java. Now let's do a final sanity compile of the whole project to be safe.Assistant
Full project compiles successfully with only pre-existing warnings. Let's do a final review of the diff and clean up temp folder.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.