Skip to content

Support distributed tracing#19920

Merged
WeichenXu123 merged 22 commits intomlflow:masterfrom
WeichenXu123:distributed-tracing
Jan 15, 2026
Merged

Support distributed tracing#19920
WeichenXu123 merged 22 commits intomlflow:masterfrom
WeichenXu123:distributed-tracing

Conversation

@WeichenXu123
Copy link
Collaborator

@WeichenXu123 WeichenXu123 commented Jan 12, 2026

🛠 DevTools 🛠

Open in GitHub Codespaces

Install mlflow from this PR

# mlflow
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/19920/merge
# mlflow-skinny
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/19920/merge#subdirectory=libs/skinny

For Databricks, use the following command:

%sh curl -LsSf https://raw.githubusercontent.com/mlflow/mlflow/HEAD/dev/install-skinny.sh | sh -s pull/19920/merge

Related Issues/PRs

#xxx

What changes are proposed in this pull request?

Support distributed tracing.

Motivation:
Currently, MLflow can only create a trace from single process/service. However, multi-agent system is becoming more popular, and users can deploy multiple agents as separate services and use them within a single product. For example, they can have "SupervisorAgent", "SQLAgent", "PythonAgent", "WebSearchAgent", deployed into different model serving endpoints, and route requests from chatbot frontend based on user's question. In this case, it is ideal for customers that they can see all those agent actions for a single user request in a single trace. However, since MLflow can only create trace within a scope of process, they can only create separate trace per agent. Debugging issue is painful because they need to find and stitch those traces.

In this PR,
it supports building a trace that spans over multiple services. Note that OpenTelemetry already have a mechanism for that, which is called "context propagation" and use a protocol called W3C TraceContext by default. So that this PR is built on top of it.

APIs:

def get_tracing_context_headers_for_http_request():
    """
    Get the http request headers that hold information of the tracing context.
    The trace context is serialized as the traceparent header which is defined
    in the W3C TraceContext specification.
    For details, you can refer to
    https://opentelemetry.io/docs/concepts/context-propagation/
    and
    https://www.w3.org/TR/trace-context/#traceparent-header

    Returns:
        The http request headers that hold information of the tracing context.
    """

def set_tracing_context_from_http_request_headers(headers):
    """
    Extract the trace context from the http request headers,
    and return the context manager to set the extracted trace context as the
    current trace context.
    The trace context must be serialized as the traceparent header which is defined
    in the W3C TraceContext specification, please see
    :py:func:`mlflow.tracing.distributed.get_tracing_context_headers_for_http_request`
    for how to get the http request headers.

    Args:
        headers: The http request headers to extract the trace context from.
    """

How is this PR tested?

  • Existing unit/integration tests
  • New unit/integration tests
  • Manual tests

Does this PR require documentation update?

  • No. You can skip the rest of this section.
  • Yes. I've updated:
    • Examples
    • API references
    • Instructions

Release Notes

Is this a user-facing change?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release notes for MLflow users.

Support distributed tracing

What component(s), interfaces, languages, and integrations does this PR affect?

Components

  • area/tracking: Tracking Service, tracking client APIs, autologging
  • area/models: MLmodel format, model serialization/deserialization, flavors
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/scoring: MLflow Model server, model deployment tools, Spark UDFs
  • area/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflows
  • area/gateway: MLflow AI Gateway client APIs, server, and third-party integrations
  • area/prompts: MLflow prompt engineering features, prompt templates, and prompt management
  • area/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionality
  • area/projects: MLproject format, project running backends
  • area/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev server
  • area/build: Build and test infrastructure for MLflow
  • area/docs: MLflow documentation pages

How should the PR be classified in the release notes? Choose one:

  • rn/none - No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" section
  • rn/breaking-change - The PR will be mentioned in the "Breaking Changes" section
  • rn/feature - A new user-facing feature worth mentioning in the release notes
  • rn/bug-fix - A user-facing bug fix worth mentioning in the release notes
  • rn/documentation - A user-facing documentation change worth mentioning in the release notes

Should this PR be included in the next patch release?

Yes should be selected for bug fixes, documentation updates, and other small changes. No should be selected for new features and larger changes. If you're unsure about the release classification of this PR, leave this unchecked to let the maintainers decide.

What is a minor/patch release?
  • Minor release: a release that increments the second part of the version number (e.g., 1.2.0 -> 1.3.0).
    Bug fixes, doc updates and new features usually go into minor releases.
  • Patch release: a release that increments the third part of the version number (e.g., 1.2.0 -> 1.2.1).
    Bug fixes and doc updates usually go into patch releases.
  • Yes (this PR will be cherry-picked and included in the next patch release)
  • No (this PR will be included in the next minor release)

Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
@github-actions github-actions bot added area/tracing MLflow Tracing and its integrations rn/feature Mention under Features in Changelogs. labels Jan 12, 2026
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for distributed tracing in MLflow, enabling traces to span multiple services/processes. It implements W3C TraceContext-based context propagation via OpenTelemetry, allowing child spans created in remote processes to be linked to their parent spans. This addresses the use case of multi-agent systems where agents are deployed as separate services.

Changes:

  • Added two new APIs: get_tracing_context_headers_for_http_request() to serialize trace context into HTTP headers, and set_tracing_context_from_http_request_headers() to extract and restore trace context from headers
  • Modified InMemoryTraceManager to track whether traces are distributed
  • Added logic in the span exporter to handle distributed traces differently

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.

File Description
mlflow/tracing/distributed/init.py New module implementing distributed tracing APIs for context propagation via HTTP headers
mlflow/tracing/trace_manager.py Added is_distributed_trace parameter and tracking dictionary to distinguish distributed traces
mlflow/tracing/export/mlflow_v3.py Added validation to prevent incremental export of distributed trace spans
tests/tracing/test_distributed.py Comprehensive test suite including unit tests and end-to-end Flask server test
Comments suppressed due to low confidence (1)

mlflow/tracing/export/mlflow_v3.py:78

  • The code raises a RuntimeError but then logs a warning immediately after on unreachable lines 74-78. After raising an exception, execution stops, so the logger.warning call will never be executed. Either remove the raise statement and keep only the warning, or remove the unreachable warning code. Based on the error message mentioning "not supported", it appears the intention is to prevent this operation, so the warning should be removed.
                _logger.warning(
                    "The MLflow tracing store backend does not support exporting spans "
                    "incrementally. In the case, exporting the distributed tracing span "
                    f"{span.name} that is created in a remote process is not supported."
                )

        self._export_traces(spans)

    def _export_spans_incrementally(self, spans: Sequence[ReadableSpan]) -> None:
        """

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 12, 2026

Documentation preview for 0104391 is available at:

More info
  • Ignore this comment if this PR does not change the documentation.
  • The preview is updated when a new commit is pushed to this PR.
  • This comment was created by this workflow run.
  • The documentation was built by this workflow run.

Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Copy link
Collaborator

@B-Step62 B-Step62 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall mechanism of propagating traceparent and the handling in trace manager makes sense. Added a few comments to make things a bit more simple.

@B-Step62 B-Step62 linked an issue Jan 14, 2026 that may be closed by this pull request
14 tasks
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
@WeichenXu123 WeichenXu123 requested a review from B-Step62 January 14, 2026 06:37
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
@WeichenXu123 WeichenXu123 requested a review from B-Step62 January 14, 2026 13:53
Copy link
Collaborator

@B-Step62 B-Step62 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@WeichenXu123 WeichenXu123 added this pull request to the merge queue Jan 15, 2026
Merged via the queue into mlflow:master with commit 0a34924 Jan 15, 2026
56 of 58 checks passed
@WeichenXu123 WeichenXu123 deleted the distributed-tracing branch January 15, 2026 02:05
ridgupta26 pushed a commit to ridgupta26/mlflow-ridz that referenced this pull request Jan 29, 2026
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/tracing MLflow Tracing and its integrations rn/feature Mention under Features in Changelogs. v3.9.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR] Support distributed tracing in MLflow Tracing

3 participants