Retrieving Mlflow Traces

mlflow/skills/retrieving-mlflow-traces

作者 mlflowc55c66586a35f7e3f2a377bfc462ef9791fbc3f4无许可证收录于 2026年10月9日更新于 2026年10月9日

Retrieves MLflow traces using CLI or Python API. Use when the user asks to get a trace by ID, find traces, filter traces by status/tags/metadata/execution time, query traces, or debug failed traces. Triggers on "get trace", "search traces", "find failed traces", "filter traces by", "traces slower than", "query MLflow traces".

AI 生成的概览

指导通过 CLI 或 Python API 检索 MLflow 追踪,包括单条获取、筛选搜索和调试失败追踪。

功能
该技能提供使用 MLflow CLI 或 Python API 检索 MLflow 追踪的说明。涵盖按 ID 获取单条追踪,以及按运行 ID、会话、用户、状态、时间范围、执行时间、标签、元数据、评估和全文进行搜索,还包括分页和输出选项。文档还说明了筛选语法,并建议对 Unity Catalog 搜索按时间限定范围。
适用场景
当用户要求按 ID 获取追踪、查找或筛选追踪、按状态、标签、元数据或执行时间查询追踪,或调试失败追踪时使用。它也适用于验证新添加的追踪埋点。
运行要求
需要 MLflow CLI 或 Python API,并能访问 MLflow 跟踪服务器或 Unity Catalog。查阅文档时可能需要网络访问。不包含脚本,仅为说明文档。

Retrieving MLflow Traces

Bound Unity Catalog Searches by Time

When searching traces stored in Unity Catalog, include trace.timestamp_ms >= <start_time_ms> in the filter string, with an upper bound when known. This also applies when searching by experiment ID, run ID, session, or other filters: a small result limit does not prevent a scan across the full trace history. In Python, pass the time condition through filter_string; mlflow.search_traces() has no start_time argument.

Use the time window requested by the user or established by the run or incident. For setup verification, record the time immediately before the instrumented run. Do not silently restrict historical investigations to the last hour. If the relevant period cannot be determined, ask for it before starting a broad UC search. The examples below demonstrate individual filters; combine them with the relevant time bounds for UC.

Keep Setup Verification Brief

For verifying newly added instrumentation, follow the verification workflow in instrumenting-with-mlflow-tracing. Enforce a 60-second wall-clock deadline for readback, cancelling the verification command at the deadline even if a call is still retrying internally: make one fetch by a known trace ID, or one time-bounded search with --max-results 1 (Python: max_results=1). Retry at most once after a concrete, quick fix, within the same budget. Stop once one trace and its expected spans are confirmed.

If readback is slow or fails, report what was verified, what remains unverified, and the observed blocker and required user action (such as configuring a missing API key, logging in, obtaining permission, or resolving warehouse availability/capacity). Do not start parallel searches or fall back to direct SQL, raw REST, alternate authentication, or repeated agent runs just to complete setup verification. A dedicated retrieval or debugging request can require broader investigation; preserve the user's scope.

Single Fetch vs Search

Choose the right approach based on what you have:

You have...UseCommand
Trace IDSingle fetchmlflow traces get --trace-id <id>
Session/user/filtersSearchmlflow traces search --experiment-id <id> --filter-string "..."

Single fetch - Use when you have a specific trace ID (e.g., from UI, logs, or API response):

bash
mlflow traces get --trace-id tr-69f72a3772570019f2f91b75b8b5ded9

Search - Use when you need to find traces by criteria (session, user, status, time range, etc.):

bash
mlflow traces search --experiment-id 1 --filter-string "metadata.\`mlflow.trace.session\` = 'session_abc'"

Trace Data Structure

  • TraceInfo: trace_id, status (OK/ERROR), timestamp_ms, execution_time_ms, tags, metadata, assessments (human feedback, evaluation results)
  • Spans: Tree of operations with name, type, attributes, start_time, end_time

Workflow

  1. Check CLI usage (required): mlflow traces search --help
  2. Build filter query using syntax below
  3. Execute search with appropriate flags
  4. Retrieve details for specific traces if needed

Prerequisite: Check CLI Usage

bash
mlflow traces search --help

Always run this first to get accurate flags for the installed MLflow version.

Searching Traces

The mlflow traces search command is used to search for traces in an MLflow experiment.

By Run ID

Filter traces associated with a specific MLflow run:

bash
# All traces for a runmlflow traces search --run-id <run_id>
# Failed traces for a runmlflow traces search --run-id <run_id> --filter-string "trace.status = 'ERROR'"
# Can combine with experiment-idmlflow traces search --experiment-id 1 --run-id <run_id>

By Session or User (Common for Debugging)

When debugging an issue from the MLflow UI, filter by session or user ID to get all related traces:

bash
# All traces for a specific session (use backticks for special characters in key)mlflow traces search --experiment-id 1 --filter-string "metadata.\`mlflow.trace.session\` = 'session_abc123'"
# All traces for a specific usermlflow traces search --experiment-id 1 --filter-string "metadata.\`mlflow.trace.user\` = 'user_456'"
# Failed traces in a session (for root cause analysis)mlflow traces search --experiment-id 1 --filter-string "metadata.\`mlflow.trace.session\` = 'session_abc123' AND trace.status = 'ERROR'"
# Session traces ordered by time (to see sequence of events)mlflow traces search --experiment-id 1 --filter-string "metadata.\`mlflow.trace.session\` = 'session_abc123'" --order-by "timestamp_ms ASC"

By Status

bash
mlflow traces search --experiment-id 1 --filter-string "trace.status = 'ERROR'"mlflow traces search --experiment-id 1 --filter-string "trace.status = 'OK'"

By Time Range

bash
# Timestamps are in milliseconds since epoch# Get current time in ms: $(date +%s)000# Last hour: $(( $(date +%s)000 - 3600000 ))
mlflow traces search --experiment-id 1 --filter-string "trace.timestamp_ms > $(( $(date +%s)000 - 3600000 ))"

By Execution Time (Slow Traces)

bash
# Traces slower than 1 secondmlflow traces search --experiment-id 1 --filter-string "trace.execution_time_ms > 1000"

By Tags and Metadata

bash
# By tagmlflow traces search --experiment-id 1 --filter-string "tag.environment = 'production'"
# By metadatamlflow traces search --experiment-id 1 --filter-string "metadata.user_id = 'user_123'"
# Escape special characters in key names with backticksmlflow traces search --experiment-id 1 --filter-string "tag.\`model-name\` = 'gpt-4'"mlflow traces search --experiment-id 1 --filter-string "metadata.\`user.id\` = 'abc'"

By Assessment/Feedback

bash
mlflow traces search --experiment-id 1 --filter-string "feedback.rating = 'positive'"

Full Text Search

bash
mlflow traces search --experiment-id 1 --filter-string "trace.text LIKE '%error%'"

Pagination

Control result count and iterate through pages:

bash
# Limit results per pagemlflow traces search --experiment-id 1 --max-results 50
# Output includes "Next page token: <token>" if more results exist# Use --page-token to fetch next pagemlflow traces search --experiment-id 1 --max-results 50 --page-token "eyJvZmZzZXQiOiA1MH0="

Output Options

bash
# Output format (table or json)mlflow traces search --experiment-id 1 --output json
# Include span details in outputmlflow traces search --experiment-id 1 --include-spans
# Order resultsmlflow traces search --experiment-id 1 --order-by "timestamp_ms DESC"

Retrieving Single Trace

When you need to retrieve details about a specific trace, use the mlflow traces get command.

bash
mlflow traces get --trace-id <trace_id>

Filter Syntax

For detailed syntax, fetch from documentation:

WebFetch(  url: "https://mlflow.org/docs/latest/genai/tracing/search-traces.md",  prompt: "Extract the filter syntax table showing supported fields, operators, and examples.")

Common filters:

  • trace.status: OK, ERROR, IN_PROGRESS
  • trace.execution_time_ms, trace.timestamp_ms: numeric comparison
  • metadata.\mlflow.trace.session`, metadata.`mlflow.trace.user``: session/user filtering
  • tag.<key>, metadata.<key>: exact match or pattern
  • span.name, span.type: exact match or pattern
  • feedback.<name>, expectation.<name>: assessments

Pattern operators: LIKE, ILIKE (case-insensitive), RLIKE (regex)

Python API

For mlflow.search_traces(), see: https://mlflow.org/docs/latest/genai/tracing/search-traces.md

来源与署名

来源:mlflow/skills位于retrieving-mlflow-traces提交c55c665

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架