DSPy Tracing

Instrument and observe your DSPy application with OpenInference, DSPyInstrumentor, and view traces in Arize AX.

DSPy is a framework for automatically prompting and fine-tuning language models. It provides composable and declarative APIs that allow developers to describe the architecture of their LLM application in the form of a "module" (inspired by PyTorch's nn.Module). It then compiles these modules using "teleprompters" that optimize the module for a particular task.

OpenInference and Arize make your DSPy applications observable by visualizing the underlying structure of each call to your compiled DSPy module. This often involves instrumenting DSPy itself and LiteLLM, which DSPy frequently uses for model interactions.

Follow the tutorial notebook for an in-depth example. Note: you may need to adapt parts of the notebook's original OTel setup to the Arize OTel setup described below.

Launch Arize

To get started, sign up for a free Arize account and get your Space ID and API Key.

Install

Install dspy-ai, the OpenInference instrumentors for DSPy and LiteLLM (if used by DSPy for model calls), and Arize OTel packages.

DSPy frequently uses LiteLLM under the hood to make LLM calls. By adding the OpenInference instrumentor for LiteLLM, you'll get more detailed traces, including token counts.

API Key Setup

Configure the API key for the underlying LLM that DSPy (via LiteLLM or directly) will use. For example, if using OpenAI models:

Setup Tracing

Connect to Arize AX using arize.otel.register and apply the instrumentors.

Run DSPy Example

Now run your compiled DSPy module. The example below uses dspy.OpenAI which might make direct calls or go via a configured LiteLLM route depending on DSPy version and setup. The LiteLLMInstrumentor helps capture these calls.

Observe

Now that you have tracing setup, all instrumented calls within your DSPy application, including underlying LLM interactions captured by the LiteLLM (or other) instrumentor, will be streamed to your Arize account.

Resources

Last updated

Was this helpful?