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
Let me start by understanding the issue:
- After upgrading from Kestra v0.19.5 to v1.0.3, MDC (Mapped Diagnostic Context) context is no longer applied consistently in task/flow logs.
- The issue is that when logging, the MDC context (tenantId, namespace, flowId, executionId, taskId, taskrunId) is only applied to some log messages but not others.
- The user suggests that manually setting the context map in
LogService.java'slogExecutionmethod would fix it.
Let me explore the repository structure and the relevant file first.
The key file mentioned is:
core/src/main/java/io/kestra/core/services/LogService.javaLet me look at it and understand the logging flow.
Assistant
The find didn't return results. Let me try a broader search.
Assistant
Let me look at the directory structure first.
Assistant
This is the kestra monorepo. Let me find LogService.java.
Assistant
Let me look for LogService.java in the core module.
Assistant
Hmm, the file referenced in the issue doesn't seem to exist. Let me search more
Assistant
Let me search for log-related files
Assistant
Let me look at the key files. The issue references
LogService.javabut it may have been renamed. Let me check the loggingAssistant
Let me check the commit referenced in the issue and find the LogService.java
Assistant
Now I see the old
LogService.java. It's been removed/refactored. Let me see the current state of the codebase and understand the new logging flow.Assistant
So
LogServicewas removed. Let me see what replaced itAssistant
So LogService was refactored into
Logs.javautility class. Let me look at the current stateAssistant
Now I understand the issue. Let me find where MDC context is set for user logs
Assistant
Let me look at RunContextLogger.java and DefaultRunContext.java to understand how MDC is set.
Assistant
Let me look at the specific line referenced in the issue and understand the full picture
Assistant
Let me look at the logging configuration and JSON appenders to understand how MDC is
Assistant
Let me look at the logback config files
Assistant
Let me look at StackdriverJson
Assistant
Let me look at this file.
Assistant
Now I understand the architecture. Let me find where
Logs.*methods are called and also check ifAssistant
Let me look at what changed in the history to understand the regression
Assistant
Let me look at these key commits to understand what
Assistant
Let me look at the diff for
LogService.javain this keyAssistant
Let me look at how MDC is used in the codebase
Assistant
Now I have a clear understanding of the issue. The
Logs.javamethods log context information only in the message string but don't set MDC properties. Only theRunContextLogger(user flow logs) sets MDC. The fix is to set MDC context in theLogs.javamethods.Let me open the file and make the changes:
Assistant
Let me try again with the proper command.
Assistant
Let me check what keys
LogEntry.toMap()returns to ensure consistency:Assistant
Let me look at LogEntry.java directly
Assistant
Now I understand the full picture. Let me implement the fix. First, let me add the necessary imports:
Assistant
The edit duplicated imports. Let me restore the file and try again more carefully
Assistant
Now let me use
replaceto make smaller targeted changes. First, add the import for MDC and Map:Assistant
Now let me make changes step by step. First, let me add the imports:
Assistant
Good. Now let me modify each method to set MDC context before logging. Let me
Assistant
Let me now modify each method. I'll start with the
logExecution(FlowId flow, Logger logger, ...)methodAssistant
Now modify the
logExecution(Execution execution, Logger logger, ...)Assistant
Now modify the
logTrigger(TriggerId trigger, Logger logger, ...)methodAssistant
Now modify the
logTaskRunmethodAssistant
Let me verify the final file looks correct
Assistant
The file looks correct. Let me now verify it compiles and check for existing tests
Assistant
Let me check the existing test
Assistant
Let me try to compile the core module to verify the changes
Assistant
Build successful. Now let me run the existing test
Assistant
All tests pass. Let me also check if there are any other places where the old
LogServicemight still be referenced, or if there are additional logging points that need MDCAssistant
Let me check the Logback version and verify how
getMDCPropertyMap()Assistant
Let me check the logback version from gradle build files.
Assistant
Let me check the specific logback version.
Assistant
Let me check the logback version from the main build.g
Assistant
Now let me think about whether there are any additional places that need fixing. Let me also check if the
ForwardAppenderinRunContextLoggerhas issues with MDC propagation. Let me look at how the logbackLoggingEventhandles MDC in the version used.Assistant
Let me check the Logback 1.5.32 source for `LoggingEvent.getMDCPropertyMap()
Assistant
Now I understand the full MDC propagation mechanism. The
LoggingEvent.getMDCPropertyMap()in Logback 1.5.32 has a fallback to the event's logger context MDC adapter. This confirms my fix is correct.Let me now run the broader test suite for the core module to make sure nothing is
Assistant
All tests pass. Let me also run a quick compilation check on the modules that depend on
Logsto make sure they still compile.Assistant
All modules compile successfully. Let me do a final review of the changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.