Automatic tracing and integrations

One call — mlflow.<framework>.autolog() — enables tracing for any of 30+ supported frameworks and LLM providers. It patches the library at import time so every LLM invocation, tool call, and agent step is captured as a span with no additional instrumentation.

Enable automatic tracing

Note

On serverless compute clusters, autologging is not enabled by default. You must call mlflow.<library>.autolog() explicitly for each integration you want to trace.

Install

%pip install --upgrade "mlflow[databricks]>=3.1.0" "openai>=1.0.0"
# Also install the SDKs for any other frameworks you want to trace
dbutils.library.restartPython()

Set credentials

Databricks notebook

import os
os.environ["OPENAI_API_KEY"] = "your-api-key"
# Add other provider keys as needed:
# os.environ["ANTHROPIC_API_KEY"] = "your-api-key"

External environment

export DATABRICKS_HOST="https://your-workspace.cloud.databricks.com"
export DATABRICKS_TOKEN="your-databricks-token"
# Add provider keys for your chosen LLM

Quickstart examples

Choose your framework to see a minimal working example. Each tab links to the full per-framework guide.

OpenAI

import mlflow
import openai

mlflow.openai.autolog()
mlflow.set_tracking_uri("databricks")
mlflow.set_experiment("/Shared/openai-tracing-demo")

client = openai.OpenAI()
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "What is the capital of France?"}],
)
# Trace appears in the MLflow UI automatically

Full OpenAI guide

LangChain

import mlflow
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser

mlflow.langchain.autolog()
mlflow.set_tracking_uri("databricks")
mlflow.set_experiment("/Shared/langchain-tracing-demo")

chain = (
    ChatPromptTemplate.from_template("Tell me a joke about {topic}.")
    | ChatOpenAI(model="gpt-4o-mini", temperature=0.7)
    | StrOutputParser()
)
chain.invoke({"topic": "artificial intelligence"})

Full LangChain guide

LangGraph

import mlflow
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent

mlflow.langchain.autolog()  # LangGraph uses LangChain's autolog
mlflow.set_tracking_uri("databricks")
mlflow.set_experiment("/Shared/langgraph-tracing-demo")

@tool
def get_weather(city: str):
    """Get weather for a city."""
    return f"It might be cloudy in {city}"

graph = create_react_agent(ChatOpenAI(model="gpt-4o-mini"), [get_weather])
graph.invoke({"messages": [("user", "What is the weather in SF?")]})

Full LangGraph guide

Anthropic

import mlflow
import anthropic
import os

mlflow.anthropic.autolog()
mlflow.set_tracking_uri("databricks")
mlflow.set_experiment("/Shared/anthropic-tracing-demo")

client = anthropic.Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
message = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello, Claude"}],
)

Full Anthropic guide

Databricks FMAPI

import mlflow
import os
from openai import OpenAI

# Databricks Foundation Model APIs use the OpenAI client
mlflow.openai.autolog()
mlflow.set_tracking_uri("databricks")
mlflow.set_experiment("/Shared/databricks-fmapi-tracing")

client = OpenAI(
    api_key=os.environ.get("DATABRICKS_TOKEN"),
    base_url=f"{os.environ.get('DATABRICKS_HOST')}/serving-endpoints",
)
response = client.chat.completions.create(
    model="databricks-llama-4-maverick",
    messages=[{"role": "user", "content": "Key features of MLflow?"}],
)

Full Databricks guide

DSPy

import mlflow
import dspy

mlflow.dspy.autolog()
mlflow.set_tracking_uri("databricks")
mlflow.set_experiment("/Shared/dspy-tracing-demo")

dspy.configure(lm=dspy.LM("openai/gpt-4o-mini"))

class SimpleSignature(dspy.Signature):
    input_text: str = dspy.InputField()
    output_text: str = dspy.OutputField()

result = dspy.Predict(SimpleSignature)(input_text="Summarize MLflow Tracing.")

Full DSPy guide

Bedrock

import mlflow
import boto3

mlflow.bedrock.autolog()
mlflow.set_tracking_uri("databricks")
mlflow.set_experiment("/Shared/bedrock-tracing-demo")

bedrock = boto3.client(service_name="bedrock-runtime", region_name="us-east-1")
response = bedrock.converse(
    modelId="anthropic.claude-3-5-sonnet-20241022-v2:0",
    messages=[{"role": "user", "content": "Hello World."}],
)

Full Bedrock guide

AutoGen

import mlflow
from autogen import ConversableAgent
import os

mlflow.autogen.autolog()
mlflow.set_tracking_uri("databricks")
mlflow.set_experiment("/Shared/autogen-tracing-demo")

config_list = [{"model": "gpt-4o-mini", "api_key": os.environ.get("OPENAI_API_KEY")}]
assistant = ConversableAgent("assistant", llm_config={"config_list": config_list})
user_proxy = ConversableAgent("user_proxy", human_input_mode="NEVER", code_execution_config=False)
user_proxy.initiate_chat(assistant, message="What is 2+2?")

Full AutoGen guide

All integrations

Each page includes prerequisites, configuration options, and examples beyond the quickstart above.

LLM providers

Integration Name
Anthropic Anthropic
AWS Bedrock AWS Bedrock
Databricks Foundation Model APIs Databricks Foundation Model APIs
DeepSeek DeepSeek
Google Gemini Google Gemini
Groq Groq
Mistral Mistral
Ollama Ollama
OpenAI OpenAI

Agent frameworks and orchestrators

Integration Name
AG2 AG2
Agno Agno
AutoGen AutoGen
CrewAI CrewAI
DSPy DSPy
Haystack Haystack
LangChain LangChain
LangGraph LangGraph
LlamaIndex LlamaIndex
OpenAI Agents SDK OpenAI Agents SDK
PydanticAI PydanticAI
Semantic Kernel Semantic Kernel
Smolagents Smolagents
Strands Strands
Swarm Swarm
TxtAI TxtAI

Utilities and other

Integration Name
Claude Code Claude Code
Instructor Instructor
LiteLLM LiteLLM
OpenTelemetry OpenTelemetry

Disable automatic tracing

import mlflow

# Disable for a specific library
mlflow.openai.autolog(disable=True)

# Disable all autologging at once
mlflow.autolog(disable=True)

Additional resources

Next step: Manual and custom tracing