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
such as :
public void logExecution(Execution execution, Level level, String message, Object... args) { Logger logger = logger(execution); MDC.setContextMap(Map.of("tenantId", execution.getTenantId(), "namespace", execution.getNamespace(), "flowId", execution.getFlowId(), "executionId", execution.getId())); logExecution(execution, logger, level, message, args); }Environment
- Kestra Version: develop, v1.0
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /kestra, current file: none) bash-$
Assistant
Let me start by exploring the repository structure to understand the codebase.
Assistant
Let me look at the LogService.java file mentioned in the issue first.
Assistant
Hmm, the file name in the issue was LogService.java but it's actually ExecutionLogService.java now. Let me look at this file and also searchfor "logExecution".
Assistant
Let me search for the logExecution method in the codebase, since that's the method mentioned in the issue.
Assistant
Now let me look at theLogs.java file:
Assistant
Let me look at the LogEntry class to understand where the structured fields are added.
Assistant
Let me look at the test file for Logs.java:
Assistant
Let me find where the MDC context is set for the structured logger:
Assistant
Let me look at the RunContextLogger.java:
Assistant
Let me search for the old logger name
execution.{tenantId}to see where it's used:Assistant
Let me search specifically for the logger name pattern with "execution."
Assistant
Let me look at the git log to understand recent changes:
Assistant
Let me look at the previous LogService.java version:
Assistant
Let me look at the old v0.19.5 version. Let me see git tags:
Assistant
Now let me look at the current logback config to understand the structured logging:
Assistant
Let me see how MDC is handled in tests too:
Assistant
Let me also look at where these Logs.logExecution methods are called:
Assistant
Let me look at the LogService.java that existed before the change:
Assistant
Now let me see the existing tests and understand what I need to make work:
Assistant
Let me look at FlowId:
Assistant
Let me also look at the TriggerId interface:
Assistant
Now I have enough context to implement the fix. Let me first reproduce the issue with a test script:
Assistant
Now I have a clear understanding. Let me implement the fix:
Assistant
Now let me modify the Logs.java file to set the MDC context:
Assistant
Now let me verify the changes compile by running the tests:
Assistant
The compilation is successful. Now let me run the existing tests for the Logs.java file:
Assistant
There's a test failure because
Map.ofdoesn't allow null values. Let me update the implementation to handle null values:Assistant
Let me update the implementation to handle null values:
Assistant
Now let me run the tests again to confirm:
Assistant
All 4 tests pass. Now let me write a test script to verify the MDC context is set correctly:
Assistant
Let me create a temporary test to verify the MDC behavior:
Assistant
All 7 tests pass. Now let me delete the temporary test file since it's not part of the actual fix:
Assistant
Let me also run the LogsTest to make sure existing tests still pass:
Assistant
Let me look at the final implementation:
Assistant
Let me also check that there aren't other places in the codebase that may need updating:
Assistant
Let me run a broader test to make sure I haven't broken anything else:
Assistant
Let me find out which test is failing:
Assistant
Let me look at the failing test to verify it's unrelated to my changes:
Assistant
This test is clearly unrelated to my fix - it's testing files with non-ASCII characters. Let me confirm by checking out the original Logs.java and running this test:
Assistant
The test was already failing before my changes - it's unrelated. Let me restore my changes:
Assistant
Good. Now let me make sure my changes are still inplace:
Assistant
Let me run the LogsTest again to confirm:
Assistant
Let me check the diff of my changes:
Assistant
Let me check if there are any other places that reference the
Loggerfield of the LogService or Logs class:Assistant
Let me look at the WorkerTaskProcessor to ensure the fix works:
Assistant
Now let me run a broader set of tests related to the executor to make sure I haven't broken anything:
Assistant
Let me also run the webserver tests:
Assistant
Let me focus on tests that are most likely to be affected by my change:
Assistant
Let me also check the related tests to make sure things work:
Assistant
Let me look at the final implementation once more to make sure it's correct:
Assistant
Let me look at the diff of my changes:
Assistant
Let me check the build for the entire core module:
Assistant
Let me look at the diff once more and think about the issue again:
Assistant
Let me also check the executor tests pass:
Assistant
All 52 tests pass. Let me also verify the workertests:
Assistant
Let me make sure everything is in order. Let me look at the final Logs.java one more time:
Assistant
Let me also check the WorkerTriggerProcessor and other places where logs are called:
Assistant
All these places use one of the Logs methods I've already updated. So my fix should cover them all.
Let me also look at one more place toverify - the executor service:
Assistant
These calls are the ones that produce the log lines mentioned in the issue (like "Flow started" and "Flow completed with state SUCCESS"). My fix should handle these correctly.
Let me also verify the trigger andtask run logs:
Assistant
Good. These calls are also covered by my fix.
Now let me think about whether I should also check the
WorkerTriggerProcessorandWorkerTaskProcessorto see if they pass a logger:Assistant
Let me verify my understanding by reading the relevant parts:
Assistant
Let me run all the tests for the affected modules once more to confirm everything works:
Assistant
All 4 existing tests pass. Let me also run the executor tests:
Assistant
There are no ExecutorServiceTest in the executor module. Letme look for executor tests:
Assistant
Let me also check the diff once more:
Assistant
Let me do a final verification by checking how my fix interacts with the
StackdriverJsonLayout:Assistant
I'm satisfied with the fix. Let me do a final check to ensure everything compiles:
Assistant
Let me make sure all tests pass:
Assistant
Let me check the final diff one more time:
Assistant
Let me make a final check on the implementation and verify that everything is in order:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →