libs/tracing/README.md
MLflow Tracing (mlflow-tracing) is an open-source, lightweight Python package that only includes the minimum set of dependencies and functionality
to instrument your code/models/agents with MLflow Tracing Feature. It is designed to be a perfect fit for production environments where you want:
@trace decorator.mlflow.set_trace_tag, mlflow.search_traces, etc.The MLflow Trace package is designed to work with a remote hosted MLflow server as a backend. This allows you to log your traces to a central location, making it easier to manage and analyze your traces. There are several different options for hosting your MLflow server, including:
To install the MLflow Python package, run the following command:
pip install mlflow-tracing
To install from the source code, run the following command:
pip install git+https://github.com/mlflow/mlflow.git#subdirectory=libs/tracing
NOTE: It is not recommended to co-install this package with the full MLflow package together, as it may cause version mismatches issues.
To connect to your MLflow server to log your traces, set the MLFLOW_TRACKING_URI environment variable or use the mlflow.set_tracking_uri function:
import mlflow
mlflow.set_tracking_uri("databricks")
# Specify the experiment to log the traces to
mlflow.set_experiment("/Path/To/Experiment")
import openai
client = openai.OpenAI(api_key="<your-api-key>")
# Enable auto-tracing for OpenAI
mlflow.openai.autolog()
# Call the OpenAI API as usual
response = client.chat.completions.create(
model="gpt-4.1-mini",
messages=[{"role": "user", "content": "Hello, how are you?"}],
)
Official documentation for MLflow Tracing can be found at here.
The following MLflow features are not included in this package.
To leverage the full feature set of MLflow, install the full package by running pip install mlflow.