Skip to content

fix: extend mlflow.sourceRun metrics filter to cover post-hoc linked OTLP traces#23591

Merged
WeichenXu123 merged 2 commits into
mlflow:masterfrom
RudraDudhat2509:fix/otlp-traces-source-run-metrics-filter
May 27, 2026
Merged

fix: extend mlflow.sourceRun metrics filter to cover post-hoc linked OTLP traces#23591
WeichenXu123 merged 2 commits into
mlflow:masterfrom
RudraDudhat2509:fix/otlp-traces-source-run-metrics-filter

Conversation

@RudraDudhat2509

@RudraDudhat2509 RudraDudhat2509 commented May 26, 2026

Copy link
Copy Markdown
Contributor

Related Issues/PRs

Closes #23530

What changes are proposed in this pull request?

When traces arrive via the OTLP endpoint and are linked to a run post-hoc via link_traces_to_run(), the Traces tab fires three queries but Q2 (trace count badge)and Q3 (assessment score distribution) filter by trace.metadata.mlflow.sourceRun. OTLP traces never write this metadata key; their run association lives in
SqlEntityAssociation. The result is count=0 and score=NaN.

Fix: in _apply_filters (sql_trace_metrics_utils.py), when the filter key is TraceMetadataKey.SOURCE_RUN, OR-combine the existing SqlTraceMetadata EXISTS check with a SqlEntityAssociation EXISTS check. This covers both native MLflow traces (metadata path) and post-hoc linked OTLP traces (entity-association path).
No API changes, no schema migrations.

How is this PR tested?

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

New test: test_query_trace_metrics_source_run_filter_includes_linked_otlp_traces
in tests/store/tracking/sqlalchemy_store/test_sqlalchemy_store_query_trace_metrics.py.
Creates 1 native trace (with mlflow.sourceRun metadata) + 2 OTLP-style traces
(no metadata, linked via link_traces_to_run()) + 1 unrelated trace, and asserts
that the mlflow.sourceRun filter returns COUNT=3.

Does this PR require documentation update?

  • No.
  • Yes. I've updated:
    • Examples
    • API references
    • Instructions

Does this PR require updating the MLflow Skills repository?

  • No.
  • Yes. Please link the corresponding PR or explain how you plan to update it.

Release Notes

Is this a user-facing change?

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

The trace count badge and assessment score distribution on the Traces tab of an
Evaluation Run now correctly include traces linked post-hoc via
client.link_traces_to_run() (e.g. OTLP-ingested traces). Previously these showed 0 / NaN.

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

  • area/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionality

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

Is this PR a critical bugfix or security fix that should go into the next patch release?

  • This PR is critical and needs to be in the next patch release
  • This PR can wait for the next minor release

@github-actions github-actions Bot added the community Community/external contribution label May 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor
Install mlflow from this PR

Install mlflow from this PR

# mlflow
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/23591/merge
# mlflow-skinny
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/23591/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/23591/merge

PR author's recent activity

In the last 14 days, @RudraDudhat2509 opened 10 PRs across 8 repos:

Repository Open Closed Merged Total
BerriAI/litellm 1 1 0 2
NVIDIA/garak 2 0 0 2
mlflow/mlflow 1 0 0 1
vibrantlabsai/ragas 1 0 0 1
AaravWayneBanner/3GPP_Channel_Model 0 0 1 1
confident-ai/deepeval 1 0 0 1
invariantlabs-ai/mcp-injection-experiments 1 0 0 1
Puliczek/awesome-mcp-security 1 0 0 1

@github-actions github-actions Bot added size/L Large PR (200-499 LoC) area/tracing MLflow Tracing and its integrations rn/bug-fix Mention under Bug Fixes in Changelogs. labels May 26, 2026
Comment thread mlflow/store/tracking/utils/sql_trace_metrics_utils.py Outdated
@WeichenXu123

Copy link
Copy Markdown
Contributor

overall good, but please remove many lines format changes which are not related to the fix.

@github-actions

github-actions Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

Documentation preview for b3fe5b6 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.

@RudraDudhat2509
RudraDudhat2509 force-pushed the fix/otlp-traces-source-run-metrics-filter branch 2 times, most recently from 22a66f3 to 77d9111 Compare May 26, 2026 09:03
@RudraDudhat2509

Copy link
Copy Markdown
Contributor Author

Done! Pushed a cleaned commit the formatting changes from ruff format have been removed. The diff now only contains the two new imports and the _apply_filters logic change. The test file is back to original style with just the one new test function added.

@WeichenXu123
WeichenXu123 requested a review from Copilot May 26, 2026 09:59
@github-actions github-actions Bot added size/M and removed size/L Large PR (200-499 LoC) labels May 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes trace-metrics filtering for evaluation runs by making the trace.metadata.mlflow.sourceRun filter also match OTLP-ingested traces that were linked to a run post-hoc via link_traces_to_run() (stored in SqlEntityAssociation, not trace metadata). This aligns the trace count badge and assessment score distribution queries with the trace list behavior for linked traces.

Changes:

  • Extend _apply_filters() to OR-combine the existing SqlTraceMetadata filter with an SqlEntityAssociation EXISTS check when filtering on TraceMetadataKey.SOURCE_RUN.
  • Add a new SQLAlchemy store test ensuring the source-run filter includes linked OTLP-style traces in trace count metrics.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
mlflow/store/tracking/utils/sql_trace_metrics_utils.py Expands SOURCE_RUN filtering to include traces associated to a run via SqlEntityAssociation (post-hoc OTLP linking).
tests/store/tracking/sqlalchemy_store/test_sqlalchemy_store_query_trace_metrics.py Adds regression test data setup for native + linked OTLP traces and asserts the trace-count metric includes both.

Comment on lines +821 to +823
"""OTLP traces have no mlflow.sourceRun metadata; they are linked post-hoc via
link_traces_to_run(). Q2/Q3 on the Traces tab filter by mlflow.sourceRun — this test
verifies that the filter also matches entity-association-linked traces (issue #23530)."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@RudraDudhat2509 would you address this comment for test code ? :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a second assertion for the ASSESSMENTS view (Q3) with a feedback logged against one of the linked OTLP traces. Also fixing the lint failure, pushing now

…inked OTLP traces

Q2/Q3 on the Traces tab (trace count badge, assessment score distribution) filter by
trace.metadata.mlflow.sourceRun, which OTLP traces never populate. Traces linked
post-hoc via link_traces_to_run() are stored in SqlEntityAssociation, not metadata.

OR-combine the metadata EXISTS with an EntityAssociation EXISTS in _apply_filters so
the filter returns correct results for both native and OTLP-ingested traces.

Fixes mlflow#23530

Signed-off-by: Rudra Dudhat <[email protected]>
@RudraDudhat2509
RudraDudhat2509 force-pushed the fix/otlp-traces-source-run-metrics-filter branch from 77d9111 to 9459903 Compare May 26, 2026 10:56
@WeichenXu123
WeichenXu123 added this pull request to the merge queue May 27, 2026
Merged via the queue into mlflow:master with commit 60864d5 May 27, 2026
53 checks passed
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 community Community/external contribution rn/bug-fix Mention under Bug Fixes in Changelogs. size/M

Projects

None yet

3 participants