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 current
LogServiceimplementation, then trace how MDC is established and cleared around execution/task logging. I’ll make the smallest general fix, run focused tests (and broader relevant tests if available), review the diff, and submit only after verification. - Assistant
The referenced class is named
Logsin this checkout rather thanLogService; I’ll inspect it and search all MDC-related code and tests to understand the intended context lifecycle before editing. - Assistant
The root cause is that
RunContextLoggerinstalls MDC only in its private LogbackLoggerContext; lifecycle logs emitted through the shared SLF4J context (Logs.logExecution,logTaskRun, andlogTrigger) never install those fields. I’ll add scoped MDC population to all structured logging helpers, including null-safe values and restoration of any prior MDC so pooled threads cannot leak one execution’s context into another. - Assistant
The first edit attempt could not run because this environment lacks Python, so no source change was made. I’ll apply the same targeted change using the available shell tooling, then compile the core module and run
LogsTest. - Assistant
The focused test suite passes. The implementation now scopes and restores MDC around each shared-context log event, so JSON appenders see the identifiers while unrelated logs on reused executor/worker threads remain clean. I’ll review the exact diff and run formatting/checks relevant to the module before submission.
- Assistant
The diff is clean, and the only source file changed is
Logs.java; the formatting-only changes to the existing logger construction were restored. The broader:core:checkinvocation exceeded the tool timeout after starting, but the focusedLogsTestcompleted successfully and compilation/test classes were built. I’ll do one final status/diff check and submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.