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
I'll start by examining the repository structure and the LogService mentioned in the issue to understand how MDC context is handled.
- Assistant
LogService isn't in the expected path—I'll search the codebase for MDC usage and logging related to executions.
- Assistant
Hmm, rg might not have worked, or perhaps the path is different. Let me try again.
- Assistant
The logging logic moved into
Logs.javaandRunContextLogger—I'll inspect those next. - Assistant
I'll check RunContextLogger next—it already configures MDC and may show the right pattern to follow.
- Assistant
Let me continue reading the MDC-related parts of RunContextLogger.
- Assistant
I'll inspect
LogEntry.toMap()and the git history for how MDC was previously handled. - Assistant
I'll inspect LogEntry.toMap() and the pre-refactor LogService to compare MDC handling.
- Assistant
I'll search the history for when MDC context might have been removed from execution logging.
- Assistant
Next I'll look at the log layout and existing tests to confirm which MDC keys are expected.
- Assistant
Checking project guidance and whether there's already related work or discussion on this MDC fix.
- Assistant
I'll check nullable fields and how similar code handles MDC for a safe pattern.
- Assistant
Implementing MDC setup in
Logs.javausing the same keys asLogEntry.toMap(). - Assistant
The edit may have targeted the wrong file—I'll verify what changed.
- Assistant
I overwrote the wrong file — restoring
LogsTest.javaand applying the fix toLogs.java. - Assistant
Now applying the MDC fix to the correct file.
- Assistant
Checking whether we should include
executionKindin the MDC for parity with LogEntry. - Assistant
I'll verify the fix with a temporary test that asserts MDC is present on logging events.
- Assistant
The output got truncated - I need to see if the test passed.
- Assistant
Gradle reported compile UP-TO-DATE despite our edit — forcing a fresh compile and re-run.
- Assistant
Existing tests passed. Next I’ll add a temporary verification that MDC fields are actually present on the log events.
- Assistant
I'll pull the full runtime classpath and run the MDC verification.
- Assistant
Classpath is ready—compiling and running the MDC verification next.
- Assistant
Verification passed for execution, task, and trigger MDC. I'll review the final file and check formatting conventions.
- Assistant
Cleaning up temp files, then submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.