Support distributed tracing#19920
Conversation
There was a problem hiding this comment.
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, andset_tracing_context_from_http_request_headers()to extract and restore trace context from headers - Modified
InMemoryTraceManagerto 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.
|
Documentation preview for 0104391 is available at: More info
|
B-Step62
left a comment
There was a problem hiding this comment.
Overall mechanism of propagating traceparent and the handling in trace manager makes sense. Added a few comments to make things a bit more simple.
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>
🛠 DevTools 🛠
Install mlflow from this PR
For Databricks, use the following command:
Related Issues/PRs
#xxxWhat 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:
How is this PR tested?
Does this PR require documentation update?
Release Notes
Is this a user-facing change?
Support distributed tracing
What component(s), interfaces, languages, and integrations does this PR affect?
Components
area/tracking: Tracking Service, tracking client APIs, autologgingarea/models: MLmodel format, model serialization/deserialization, flavorsarea/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registryarea/scoring: MLflow Model server, model deployment tools, Spark UDFsarea/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflowsarea/gateway: MLflow AI Gateway client APIs, server, and third-party integrationsarea/prompts: MLflow prompt engineering features, prompt templates, and prompt managementarea/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionalityarea/projects: MLproject format, project running backendsarea/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev serverarea/build: Build and test infrastructure for MLflowarea/docs: MLflow documentation pagesHow 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" sectionrn/breaking-change- The PR will be mentioned in the "Breaking Changes" sectionrn/feature- A new user-facing feature worth mentioning in the release notesrn/bug-fix- A user-facing bug fix worth mentioning in the release notesrn/documentation- A user-facing documentation change worth mentioning in the release notesShould this PR be included in the next patch release?
Yesshould be selected for bug fixes, documentation updates, and other small changes.Noshould 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?
Bug fixes, doc updates and new features usually go into minor releases.
Bug fixes and doc updates usually go into patch releases.