DSPy
DSPy is a framework for programming language model systems with signatures, modules, tools, agents, and evaluation loops. Respan’s DSPy integration registers a native DSPy callback and sends module, LLM, adapter, tool, and evaluation spans through respan-tracing.
Set up Respan
Create an account at platform.respan.ai and grab an API key. For gateway, also add credits or a provider key.
Run npx @respan/cli setup to set up with your coding agent.
Example projects
- Example repo root:
respan-example-projects/python/tracing/dspy
Tracing
Gateway
Setup
Set environment variables
RESPAN_API_KEY exports traces to Respan. OPENAI_API_KEY is used by DSPy’s underlying OpenAI-compatible model client in this tracing-only setup.
View your trace
Open the Traces page to see your DSPy program with module spans, adapter formatting/parsing spans, LLM calls, tool calls, and evaluation spans.
Configuration
Respan
DSPyInstrumentor
What gets traced
Attributes
In Respan()
Set defaults at initialization — these apply to all spans.
With propagate_attributes
Override per-request using a context scope.
Decorators (optional)
Decorators are not required. DSPy module calls, LLM calls, adapter work, tool calls, and evaluation calls are auto-traced by the instrumentor. Use Respan workflow spans when you want a recognizable root span around a full DSPy script or request.
Examples
Tool calls
Tool calls are captured as dspy.tool spans with JSON input shaped as {name, arguments} and the returned tool result as output.