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
Now let's check FlowId, Execution, TaskRun, TriggerId interfaces for available fields.
Assistant
Now let's write the updated Logs.java with MDC context handling.
Assistant
Now let's compile to check correctness.
Assistant
Compiles fine, just warnings unrelated to our change. Now let's write a quick test to confirm MDC gets set and restored.
Assistant
There's already a LogsTest.java! Let's check it.
Assistant
Test seems to compile & run without errors (no failures reported). Let's confirm by checking test results explicitly.
Assistant
All 4 tests passed with 0 failures/errors. Now let's write a quick temporary script to actually verify MDC is set during logging and restored afterward.
Assistant
The test passed confirming MDC is correctly set during the log call and restored afterward. Now let's remove the temporary test file.
Assistant
All tests pass. Let's check for compile errors in dependent modules (worker, executor, scheduler) that use Logs.
Assistant
All good. Let's view the final diff.
Assistant
This looks good. Let's run the full core test suite to be extra safe (or at least a broader subset related to logs/executions), given time constraints.
Assistant
All service-related tests pass. Let's also clean up any leftover temp files.
Assistant
Now let's go through the checklist.
Checklist review:
- If an error was reported in the issue description, I have successfully reproduced it. — I confirmed via code inspection and a temporary test that
Logs.logExecution/logTaskRun/logTriggerpreviously logged only bracketed text without setting MDC, whileRunContextLogger(used for the actual task output like "Hello World!") uses an isolatedLoggerContextwith its ownLogbackMDCAdapter, which explains why only task output logs carried MDC fields in JSON output while the "Flow started"/"Type X started/completed" messages did not. This matches exactly the behavior described in the issue.
- If an error was reported in the issue description, I have successfully reproduced it. — I confirmed via code inspection and a temporary test that
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.