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
I’ll trace
LogServiceand its callers to find where MDC propagation changed, then make the smallest scoped fix with regression tests. Assumption: lifecycle logs should carry the same structured execution/task fields as user flow logs, without leaking MDC across reused worker threads. Success means execution and task lifecycle logging emits the expected MDC fields, restores prior thread context afterward, and the relevant Gradle tests pass. I’ll compare fixing each caller versus centralizing context handling inLogService; centralization is preferable only if it safely covers all paths. - Assistant
The workspace does not have
rg, and the reported source path is not present at the current root. I’m locating the actual checkout/module layout first, then I’ll continue with equivalent read-only searches. - Assistant
The lifecycle helpers are centralized in
core/utils/Logsin this checkout (the earlierLogServicehas since been renamed/refactored). The inconsistency comes from these helpers formatting identifiers into the message but never placing them in MDC, whileRunContextLoggerdoes.I’m applying context at the shared logging boundary for flow, execution, trigger, and task-run logs. The context will be merged with any existing MDC and restored immediately after emission; this preserves tracing/custom keys and prevents metadata leaking to the next job on pooled threads. Tests will cover emitted fields, nullable tenant IDs, and restoration.
- Assistant
The focused test build is still compiling. The initial implementation now covers all four lifecycle helper variants and explicitly handles missing tenant IDs. While it runs, I’m tightening the regression test to follow the repository’s Given–When–Then convention and checking that no unrelated files are touched.
- Assistant
The Gradle run is blocked trying to resolve a dependency over the network, which is outside the allowed offline scope. I’m stopping that attempt and will rerun in Gradle offline mode so verification uses only the repository and cached dependencies.
- Assistant
Offline production compilation passes. The focused test task cannot be created because the exact Mockito agent artifact is absent from the local cache; this happens before tests execute and is unrelated to the change. I’m still compiling the test sources offline, then I’ll run the focused JUnit class directly from cached artifacts if the local JUnit launcher is available.
- Assistant
The standard
unitTestpath also realizes the normaltesttask indirectly through its coverage finalizer, so it hits the same missing agent before execution. I’m using a temporary, repository-external Gradle init task that runs onlyLogsTestwith the already compiled test runtime; this does not alter the build files or dependency cache. - Assistant
All five regression methods pass in the offline focused harness, including flow, execution, trigger, task-run, nullable tenant, MDC merging, and restoration. Production and test sources also compile successfully offline. I’m removing the temporary harness and doing the final diff/status check now.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.