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
Success means every execution-, task-, and flow-scoped log carries the expected MDC fields, without leaking context across reused worker threads, and focused tests prove both population and restoration. I’ll first trace the logging helpers and existing MDC lifecycle; my working assumption is that the regression belongs in the shared
LogServiceboundary, but I’ll prefer scoped restoration over a bareMDC.setContextMap, which could contaminate later logs. - Assistant
The current branch has moved this code from
LogServiceinto the staticLogsutility. There are four relevant entry points (flow, execution, trigger, task run), all of which currently format identifiers into the message but do not scope MDC. I’m checking the canonical MDC key names and how direct flow-task logs populate them so the fix remains backward-compatible. - Assistant
I found the established structured keys in
LogEntry.toMap:tenantId,namespace,flowId,executionId,taskId,taskRunId, andtriggerId. The simplest compatible design is to merge the applicable keys into the caller’s MDC only for the synchronous log call, then restore the exact prior map infinally; this preserves tracing/custom MDC fields and prevents thread-pool leakage. I’ll apply that uniformly to all four helpers and add a regression test covering emitted fields plus restoration. - Assistant
The implementation is in place and the focused core test is running. One compatibility detail surfaced during review: tenant IDs can be absent in some OSS objects, so the context builder deliberately omits null-valued keys (matching
LogEntry.toMap) instead of usingMap.of, which would throw. - Assistant
The focused Gradle invocation is still in configuration/compilation and has produced no additional output yet; it remains active. While it runs, I’m keeping the change limited to the core utility and its existing unit test—no logger configuration or caller changes are needed.
- Assistant
Gradle is unusually quiet but still running after roughly two minutes, likely due to this monorepo’s configuration phase. There is no failure output. I’ll continue through completion, then run diff/format checks and address any test or compilation issue rather than treating the silent build as success.
- Assistant
The build was waiting on an external dependency connection (confirmed from the Gradle thread state), so I’m stopping that attempt to honor the no-internet constraint and rerunning the focused test in Gradle offline mode against the local cache.
- Assistant
The offline test run reached project configuration but cannot resolve
mockito-core:5.23.0because that dependency is not cached locally. I’ll still run the production compile offline (which does not require the test agent), then perform static/diff checks; the test execution limitation is environmental and I’ll report it precisely if the cache also blocks compilation. - Assistant
Both production and test sources now compile successfully offline. The remaining obstacle is only launching Gradle’s
testtask: its configured Mockito Java agent requires version5.23.0, absent from the cache. I’m checking whether the repository’s local dependency cache offers a safe test-only workaround; I won’t alter project dependency versions just to make this environment pass. - Assistant
The regression test and all test sources compile. Actual JUnit launch remains impossible offline because several runtime-only artifacts (JUnit launcher, Allure filter, Objenesis, and others) are not cached; a temporary agent-free test task confirmed the broader runtime gap and was removed. I’m doing the final repository/diff validation now.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.