MLflow tracing tutorial with OpenAI and LangChain
Learn MLflow autologging, trace inspection and error debugging with OpenAI and LangChain, including a pipeline whose final parsing step fails.
Player not loading? Watch on YouTube
Jules Damji introduces MLflow Tracing in notebook 1.3 of his GenAI tutorial series. He explains how a trace records a request or workflow, while spans describe individual operations with inputs, outputs, timing and metadata. A RAG example separates query embedding, document retrieval and answer generation.
The notebook uses a localhost MLflow UI and configured OpenAI API keys. Prerequisites include the first two notebooks and familiarity with starting and navigating the UI. This is an observability tutorial; the demonstrated model calls use OpenAI rather than establishing an offline setup.
Damji first runs a request without autologging, then enables mlflow.openai.autolog() to capture request details, latency, token usage and cost information. Three sequential OpenAI calls produce separate traces in this example. The LangChain demonstration uses mlflow.langchain.autolog() and shows prompt construction and model calls as spans within one hierarchical trace. Grouping the separate OpenAI calls with a manual trace decorator is left for the next tutorial.
The debugging examples cover an invalid message role, a tool function name containing spaces and a pipeline that fails during integer parsing. Damji uses MLflow Assistant to inspect the traces and suggest fixes, and says the assistant was introduced in version 3.9. He recommends enabling tracing early, combining it with experiment tracking and sampling production traces according to request volume.