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<?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 start by exploring the repository structure and the LogService mentioned in the issue to understand how MDC context is currently handled.
- Assistant
Let me look at the LogService and how MDC is used.
- Assistant
Hmm, find didn't find LogService.java. Let me search more carefully.
- Assistant
Interesting - LogService might have been renamed. Searching for MDC and logExecution usage next.
- Assistant
There's a log directory. Let me explore that.
- Assistant
Interesting - rg isn't finding MDC. Maybe it's using a different approach. Let me check the git history for LogService and also look at logging-related code.
- Assistant
LogService was removed. Checking that commit and the new logging path, plus MDC / context handling.
- Assistant
The Hello World log has MDC fields while system logs don't — inspecting RunContextLogger and the logback config next.
- Assistant
Let me read more of RunContextLogger, especially where MDC is set, and also look at gcp.xml.
- Assistant
Let me look at more of RunContextLogger, particularly ContextAppender or how it sets MDC.
- Assistant
The ForwardAppender may drop MDC when forwarding — I'll inspect it and the StackdriverJsonLayout next.
- Assistant
Let me see the rest of ForwardAppender and LogEntry.toMap(), and StackdriverJsonLayout.
- Assistant
Checking historical LogService and any past MDC usage for execution logs.
- Assistant
Checking 0.19 behavior and whether something previously populated MDC for system logs.
- Assistant
Checking LogEntry.toMap keys and existing tests next.
- Assistant
Checking other layouts and whether tenantId can be null:
- Assistant
I'll set MDC in
Logs.javafor execution, task, and trigger logs, using save/restore so the context doesn't leak, matchingLogEntry.toMap()keys. - Assistant
Verifying the fix with a temporary script and running existing Logs tests.
- Assistant
Checking whether the tests actually passed:
- Assistant
Forcing a clean recompile and re-run of the tests:
- Assistant
Adding temporary MDC assertions and running them without changing permanent tests:
- Assistant
Main cases passed. Checking whether MDC is snapshotted on the event when cleared, then removing the temp test.
- Assistant
All MDC tests passed. Cleaning up temporary files and reviewing the final change.
- Assistant
Adding the missing trailing newline.
- Assistant
Verifying the end of the file is correct:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.