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 how
LogServicebuilds structured context and how MDC is scoped across execution/task logging. Success means all Kestra-generated task/flow lifecycle logs carry the expected MDC fields, without leaking context between pooled threads, with focused regression tests and the relevant Gradle tests passing.Assumption: the intended behavior is per-log-event MDC scoping, not a persistent thread context. I’ll prefer a small save/set/restore boundary over an unbalanced
MDC.setContextMap, because executor threads are reused and stale execution data would be unsafe. - Assistant
The reported source path has moved in the current tree, so I’m locating the current implementation and its tests before changing anything.
- Assistant
The current branch has replaced
LogServicewith theLogsutility, and none of its lifecycle methods populate MDC. The structured JSON layout simply serializes the event’s MDC map, confirming the regression is at log emission. I’m checking every lifecycle overload now so the fix is consistent for flow, execution, trigger, and task-run events—not just the single execution overload from the report. - Assistant
I’m choosing a merged, scoped MDC map: existing caller fields (for example, tracing IDs) remain on the event, Kestra’s identifiers override any stale same-named keys, and the original thread context is restored immediately afterward. This avoids both context loss and cross-execution leakage on reused executor threads. The regression tests will snapshot events as an async appender would and verify both emitted fields and restoration.
- Assistant
The implementation and regression coverage are in place. The focused core test is running now; after it passes I’ll inspect the diff for formatting/scope and run the module’s required build-level verification.
- Assistant
The test runner is blocked trying to resolve an uncached Gradle dependency over the network. Since this task must remain fully local, I’m stopping that attempt and will rerun in offline mode; if the cache is incomplete, I’ll report that constraint explicitly after completing local compile/static checks available from the repository.
- Assistant
The production source compiles successfully offline. The focused test task itself cannot be configured because this checkout lacks the pinned Mockito agent in its local cache; I’m still compiling the test sources separately, which does not require launching that agent, to catch test/API errors.
- Assistant
Both production and test sources now compile offline. Test execution remains blocked at Gradle configuration by the missing Mockito 5.23.0 agent (even the agent-free unit-test task finalizes through the default test task), so I’m finishing with the repository’s formatting check and a final diff review.
- Assistant
To execute the regression test without network access, I’m substituting the unavailable Mockito agent with the locally cached 5.20.0 agent for this one test run. The test does not use Mockito; the agent is only an unconditional launcher requirement in the shared Gradle configuration. This does not modify the repository or production dependencies.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.