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 exploring the repository structure and the LogService mentioned in the issue to understand how MDC context is currently handled.
- Assistant
LogService isn't in the services list — I'll search the repo for MDC usage and related logging code.
- Assistant
Interesting -
rgdidn't find MDC. Let me try grep instead. - Assistant
I'll inspect the key logging and MDC-related classes next.
- Assistant
I'll examine how RunContextLogger sets MDC and check git history for the old logging behavior.
- Assistant
I'll inspect the old LogService and how Stackdriver/GCP JSON layout consumes MDC.
- Assistant
The LogService was deleted in that commit. Let me check the commit before removal.
- Assistant
I'll search git history for when MDC might have been set around execution logging.
- Assistant
Next I'll check
LogEntry.toMap()and any existing tests or related fixes. - Assistant
I'll inspect ForwardAppender and how MDC flows when logs are forwarded to the main logger.
- Assistant
I'll check older LogService versions and whether callers used to set MDC themselves.
- Assistant
I'll check model types so we can build MDC maps cleanly via
LogEntry. - Assistant
Checking how workers used to handle logging and MDC in older versions.
- Assistant
I'll check TriggerId and implement MDC setting in
Logs.java. - Assistant
Checking for an existing fix on another branch or open PR.
- Assistant
Implementing MDC context in
Logs.javaso execution/task/trigger lifecycle logs include the same fields as task logs. - Assistant
I'll also check logger names in the user's log sample white - the user iso on v1.0.3 and logs show execution.* and task.* while latest code has executor.* and worker.*. That's a separate change. Focus...I need to address the MDC context issue in Kestra v1.0 where additional info from tasks/flows/executions isn't consistently logged after the upgrade. The user provided a LogService fix that manually sets MDC context, but I should implement a more robust solution using LogEntry.
Let me start by examining the current logging structure and identifying where MDC context should be properly applied. The key is to ensure that context is set consistently across all log calls, especially for execution, task, and flow logs.
First, I should check the current LogService implementation to see how logging is handled.
- Assistant
Verifying the fix with a small temporary script that checks MDC on logged events:
- Assistant
Checking the full test result:
- Assistant
Forcing a clean recompile and re-run of the tests:
- Assistant
Running a targeted verification that MDC fields appear on logged events:
- Assistant
I'll pull the full test runtime classpath with Gradle and run the verify class.
- Assistant
The flow path wasn't captured — checking log levels and refining the temp test.
- Assistant
Flow logger was filtered by root WARN — fixing the temp test assertions.
- Assistant
I'll rewrite the temporary test file completely.
- Assistant
I'll cn replace lines 74 and 80.
- Assistant
Also need to verify MDC is restored when previous values existed, and handle null values in tenantId. Let me run the test.
- Assistant
All tests passed. Removing the temporary test file and cleaning up.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.