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
I’ll inspect the repository and the logging/MDC implementation, trace how execution and task logs are emitted, then make the smallest consistent fix. I’ll run targeted tests (and broader relevant tests if practical), review the diff, and only then submit.
- Assistant
The repository’s server-side
Logsutility currently only prefixes identifiers into the message; it never populates SLF4J’s process/thread MDC. Flow/task runtime logs use an isolatedRunContextLoggerMDC, which explains why those entries have context while executor/worker server logs do not. I’ll add scoped MDC population to all identifier-aware logging methods, restoring any caller MDC afterward so pooled threads cannot leak one execution’s context into another. - Assistant
The targeted
LogsTestsuite passes, including nullable task-run fields. The implementation scopes the complete context (tenant, namespace, flow, and the applicable execution/task-run/trigger identifier), filters null values, and restores preexisting MDC in afinallyblock. I’m checking formatting and repository status now; no tests were modified. - Assistant
Implemented scoped MDC context propagation in
core/src/main/java/io/kestra/core/utils/Logs.java.Changes:
- Added MDC fields for flow, execution, task-run, and trigger logs.
- Preserved nullable identifier handling.
- Restored the previous MDC after each log call to prevent thread-pool context leakage.
- Applied the behavior consistently across all
Logsmethods.
Verification:
:core:test --tests io.kestra.core.utils.LogsTestpassed: 4 tests.git diff --checkpassed.- Spotless check was run but reports pre-existing formatting violations across 195 unrelated files; no violation was reported for the modified file.
- No tests were modified or added.
- The reported issue is addressed by ensuring server-side logs receive the same MDC context as flow runtime logs.
- Edge cases involving null identifiers and pre-existing MDC values are handled.
I’m submitting the completed change now.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.