Skip to content
TheChatArchiveThe Chat Archive
gpt-5.6-luna· openaiHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION MDC context no longer applied consistently in task/flow logs after…

  1. 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

    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 using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to 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-$

  2. Assistant

    I’ll inspect the repository and the current LogService implementation, trace how MDC is established and cleared, then identify existing tests around execution/task logging. I’ll implement the smallest lifecycle-safe fix (avoiding MDC leakage across pooled threads), run focused tests, and review the final diff.

  3. Assistant

    The referenced path is not present at that exact location in this checkout, so I’ll first locate the module and source file before making assumptions about package layout.

  4. Assistant

    This checkout uses ExecutionLogService rather than the issue’s older filename. I’ll inspect that service and all MDC-related utilities/usages to determine whether context is only set in task execution wrappers and omitted by the service’s direct logging overloads.

  5. Assistant

    RunContextLogger owns a separate Logback MDC adapter for task logs, while the missing service appears to have been removed/renamed. I’ll search the entire tree for its logging API and inspect the logger/context setup and recent history to find the intended insertion point.

  6. Assistant

    The current Logs utility is the replacement for LogService, and all server-side execution/task/trigger messages pass through it. Its logger calls add textual prefixes but never populate the process MDC, explaining why only the isolated RunContextLogger logs contain structured fields. I’ll inspect the existing historical MDC fix and LogEntry key conventions, then apply the equivalent to current APIs with safe restoration/clearing semantics.

  7. Assistant

    The historical code confirms LogEntry.toMap() uses the structured keys expected by the JSON layout (tenantId, namespace, flowId, executionId, etc.). I’ll update every Logs overload—not just executions—so flow, trigger, and task lifecycle records behave consistently. The MDC will be scoped to each log event and the previous map restored afterward, which prevents tenant/execution data leaking between reused executor threads while still allowing the appender to capture it.

  8. Assistant

    The environment lacks Python, so the first edit did not change the file. I’ll rewrite the small utility using a shell heredoc, preserving its existing APIs and adding the scoped MDC helper.

  9. Assistant

    The focused LogsTest suite passes. The implementation now captures MDC on the logging event and restores any caller context in finally, including when logging throws. I’ll run formatting/check the diff and inspect whether any existing conventions require a minor adjustment before submission.

  10. Assistant

    git diff --check is clean and the focused tests/build passed. The repository-wide Spotless check reports many pre-existing violations across unrelated files (195+), including files untouched by this change, so it is not actionable without modifying unrelated code; the changed file itself is syntactically compiled and tested. I’ll do a final status/diff review and submit.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.