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<?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
I'll start by exploring the repository structure and the LogService mentioned in the issue to understand how MDC context is currently handled.
- Assistant
Let me look at the LogService.java file mentioned in the issue.
- Assistant
Hmm, nothing found. Maybe the path is different or rg isn't available.
- Assistant
LogService might have been renamed. Searching for logging-related MDC and execution log code.
- Assistant
Checking ExecutionLogService and git history for LogService.
- Assistant
LogService was removed earlier — looking at its removal and how execution/task logging works now.
- Assistant
Examining the Logs utility class and how MDC is used in logging.
- Assistant
Next I'll inspect RunContextLogger and LogEntry to see how MDC context is applied for task logs.
- Assistant
Let me read the MDC-related parts of RunContextLogger and LogEntry.toMap()
- Assistant
Checking how logging worked before and whether any PR/issue already addresses MDC.
- Assistant
Checking related tests and how MDC appears in JSON layout:
- Assistant
So the fix is clear: When logging via
Logsutility methods, set MDC with the relevant context (tenantId, namespace, flowId, executionId, taskId, taskRunId, triggerId as appropriate) and clear it aft...I agree with your analysis—the core issue is that the logging utilities inLogService(and similar classes) no longer propagate the MDC context consistently after the v1.0 changes, unlike the older behavior in v0.19.5. - Assistant
I'll reuse
LogEntry.toMap()for consistent MDC keys and updateLogs.java. - Assistant
The edit may have targeted the wrong file — verifying both files.
- Assistant
Restoring the test file and applying the fix to the correct source file.
- Assistant
Now I'll edit Logs.java properly.
- Assistant
Checking import order conventions and compiling the tests.
- Assistant
Checking whether the tests passed:
- Assistant
Forcing a re-run of the tests and writing a small verification for MDC context.
- Assistant
Creating a temporary verification that MDC is set on log events and restored afterwards.
- Assistant
Let me get the classpath properly from gradle.
- Assistant
Execution/task/trigger MDC works. Investigating the flow path failure:
- Assistant
Digging into why the flow log isn't emitting:
- Assistant
Cleaning up temporary Gradle changes and verifying the final file.
- Assistant
Checking for other log paths that might need the same MDC treatment:
- Assistant
Checking whether Spotless is happy with the formatting:
- Assistant
There are many pre-existing spotless violations. Let me check just our file.
- Assistant
My changes were wiped accidentally — reapplying the fix.
- Assistant
Re-apply the fix carefully.
- Assistant
Re-verifying with compile, tests, and MDC checks—without wiping changes.
- Assistant
Confirming MDC works. Re-running unit tests cleanly:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.