Integrations / DSPy
To trace DSPy with Tracify, wrap the function that calls your DSPy program with trace_agent, and open a step around each module you want to see. Model calls made inside it stay in the same run.
Your code
DSPy
Tracify
One run.
Setup
DSPy and the Tracify SDK.
pip install tracify-sdk dspyCreate a project in Tracify, copy its API key and put it in the environment where your code runs. The SDK reads it from there, so nothing is hard-coded.
export TRACIFY_API_KEY="tracify_sk_live_..."trace_agent turns each call into one run. A step around the module shows its input and output inside that run.
import dspy
import tracify
program = dspy.ChainOfThought("question -> answer")
@tracify.trace_agent(name="dspy-qa")
def answer(question: str) -> str:
with tracify.span("chain-of-thought", type="agent", input=question) as step:
result = program(question=question)
step.set_output(result.answer)
return result.answerFor a program with several modules, open a step in each one's forward method. The run then shows which module was slow or wrong.
class RAG(dspy.Module):
def __init__(self):
self.retrieve = dspy.Retrieve(k=3)
self.generate = dspy.ChainOfThought("context, question -> answer")
def forward(self, question):
with tracify.span("retrieve", type="retrieval", input=question) as step:
context = self.retrieve(question).passages
step.set_output(context)
with tracify.span("generate", type="llm", input=question):
return self.generate(context=context, question=question)Run your code one time, then open the Tracing page of your project. Your DSPy program shows up as a run with its steps in order, plus the tokens, time and any error for each call.
Good to know
DSPy calls its language model through its own layer, so the SDK does not see each raw model request automatically. You see the modules you mark, with their inputs and outputs and timing.
Good to know
Optimizers can run your program hundreds of times. Use the sample rate option on the client so you only keep a share of those runs.
Full details in the documentation. All integrations are listed on the integrations page.
