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
It has been renamed to
Logs.java. Let's view it.Assistant
Good, these key names match what the user suggested. Now let's implement the fix in Logs.java using try/finally with MDC save/restore.
Assistant
Now let's run the existing test to make sure things still pass.
Assistant
Let's check the test report to confirm pass/fail.
Assistant
All 4 tests passed with 0 failures/errors. Now let's write a quick reproduce script to verify MDC is set correctly and cleared afterward.
Assistant
python3 not available, let's use sed/perl instead.
Assistant
My earlier perl attempt didn't run since python3 failed before that edit. The file is unmodified. Let's insert the temp test using the
edittool at line 94 (before the private static class).Assistant
Now let's run this test.
Assistant
Compiled fine, ran without errors reported. Let's check the XML results.
Assistant
All 5 tests passed, including my temporary
mdcIsSetAndClearedtest confirming MDC is set during logging and cleared afterward. Now let's revert the test file to its original state (since I shouldn't leave test modifications).Assistant
Test file is reverted, only
Logs.javais modified. Now let's run the full existing test suite for Logs (already confirmed) and also check other modules that useLogs.logExecutionetc. for compile correctness.Assistant
Now let's run the LogsTest again to be sure it still passes with the reverted test file (i.e. the original 4 tests) with our new Logs.java.
Assistant
All 4 original tests pass with the new implementation. Now let's review the final diff of Logs.java.
Assistant
No other tests depend on MDC directly. Let's also run related test suites (executor, worker) that use
Logsto ensure nothing broke.Assistant
Good, no failures. Let's check final diff status and confirm nothing else changed.
Assistant
Good, only the intended file is modified. Let's view final content once more for sanity check.
Assistant
This looks good. Now let's clean up the temp files created for testing.
Assistant
Now let's run a broader set of related tests to double check nothing else broke (executor, worker, scheduler modules that use Logs).
Assistant
All modules compile successfully with only pre-existing warnings. Let's do a final review of the complete diff.
Assistant
This is the complete, focused fix. Let's go through the checklist.
Assistant
All 4 tests pass with 0 failures.
Assistant
Everything looks good. Submitting the 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.