Trace AI agents with MLflow
MLflow Tracing records the steps an AI agent takes, including model requests and responses, chain and tool calls, retrieval steps, latency, token usage, and errors. On Alauda AI, traces are stored in the selected MLflow experiment and protected by the same workspace authentication and Kubernetes RBAC as runs and models.
This guide shows the recommended tracing path for:
- Python agents built with LangChain.
- Applications that call Llama Stack, now OGX, through its OpenAI-compatible API.
- OGX servers or other applications that already emit OpenTelemetry traces.
TOC
PrerequisitesTrace a LangChain agentTrace an OGX applicationExport OGX OpenTelemetry tracesView the tracesTroubleshootingPrerequisites
- An MLflow tracking server and a workspace you can access. See Workspaces and access control.
- A Dex id token in
MLFLOW_TRACKING_TOKEN. Follow Using the MLflow Python SDK with Authentication and RBAC to obtain and renew one. - An experiment for the traces. Creating or writing traces requires
createandupdatepermission on the workspace'sexperimentsresource. - Network access from the agent to the MLflow tracking server and its model endpoint.
Set the common MLflow connection variables before starting the agent:
The URI above is the in-cluster Service, fronted by the OAuth proxy. For a client outside the cluster, use https://<platform>/clusters/<cluster>/mlflow instead.
Traces can contain prompts, responses, retrieved content, and tool arguments or results. Do not send secrets or sensitive personal data unless your organization permits storing that data in MLflow.
Trace a LangChain agent
MLflow's LangChain integration automatically creates spans for the agent, nested chains, model requests, retrieval, and tool calls. It supports synchronous, asynchronous, batch, and streaming LangChain invocations.
Install the agent dependencies:
The following example uses a tool-calling agent and an OpenAI-compatible model endpoint. Set MODEL_BASE_URL, MODEL_API_KEY, and MODEL_ID for the model service available in your environment.
Call mlflow.langchain.autolog() once during application startup, before invoking the agent. Existing LangChain application code does not otherwise need to change.
Trace an OGX application
OGX provides an OpenAI-compatible Chat Completions and Responses API. For a Python application that calls OGX, MLflow's OpenAI integration is the simplest option and fully traces Responses API calls.
Install the client dependencies:
Point the OpenAI client at the OGX API. The @mlflow.trace wrapper groups all model and tool activity performed by run_agent under one parent span; mlflow.openai.autolog() creates the nested spans for each OGX request.
Every call made inside a multi-step agent loop is nested under the ogx-agent trace. When the request uses function tools, MLflow also records the tool definitions and the model's tool-call response.
Export OGX OpenTelemetry traces
Use OpenTelemetry when you want to trace the OGX server itself, instrument a non-Python application, or route telemetry through a collector. MLflow accepts traces over OTLP/HTTP at /v1/traces; it does not accept OTLP/gRPC ingestion.
First, get the numeric experiment ID:
Configure an OpenTelemetry Collector to receive traces from OGX and forward them to Alauda MLflow:
Start the collector with MLFLOW_TRACKING_TOKEN, MLFLOW_EXPERIMENT_ID, and MLFLOW_WORKSPACE in its environment. Then configure OGX to send OTLP/HTTP traces to the collector:
OGX uses OpenTelemetry auto-instrumentation for server and supported SDK activity. MLflow's OTLP endpoint ingests traces only; route metrics to a metrics backend separately.
Do not enable MLflow autologging and a separate OpenTelemetry exporter for the same calls unless you deliberately configure them to share one tracer provider. Independent exporters can create duplicate traces. For OGX Responses API client calls, prefer mlflow.openai.autolog() because OpenTelemetry auto-instrumentation may not capture all Responses API operations.
View the traces
- Open Alauda AI → Tools → MLFlow.
- Select the same workspace and experiment configured by the application or collector.
- Open the experiment's Traces tab.
- Select a trace to inspect its span hierarchy, inputs and outputs, latency, token usage, tool calls, and errors.