Integrations
DSPy
Trace DSPy programs and optimization runs in Muster via the OpenInference instrumentation.
DSPy is a framework that systematically optimizes language model prompts and weights, automating the tuning process. Muster captures DSPy runs through the OpenInference instrumentation, including Chain-of-Thought, RAG, and ReAct programs.
Setup
1. Install dependencies
%pip install langfuse dspy openinference-instrumentation-dspy -U2. Configure credentials
import os
os.environ["LANGFUSE_PUBLIC_KEY"] = "pk-lf-..."
os.environ["LANGFUSE_SECRET_KEY"] = "sk-lf-..."
os.environ["LANGFUSE_BASE_URL"] = "https://app.getmuster.io"
os.environ["OPENAI_API_KEY"] = "sk-..."3. Enable tracing
from openinference.instrumentation.dspy import DSPyInstrumentor
DSPyInstrumentor().instrument()4. Configure DSPy
import dspy
lm = dspy.LM("openai/gpt-4o-mini")
dspy.configure(lm=lm)Example use cases captured
The instrumentation captures spans for the standard DSPy idioms:
- Chain-of-Thought reasoning for mathematical problems.
- RAG pipelines combining search with question answering.
- ReAct modules using multiple tools for complex reasoning.
Each program execution becomes a trace in Muster with sub-spans for every LM call, retrieval, and tool invocation.
Add user/session attributes
from langfuse import propagate_attributes
with propagate_attributes(user_id="user_123", session_id="sess_abc", tags=["dspy"]):
# run your DSPy program
...Troubleshooting
- Enable debug logging:
export LANGFUSE_DEBUG="True". - In short-lived scripts, call
langfuse.flush()before exit. - Filter unrelated OTel spans from unrelated libraries.