Skip to main content
DSPy is a framework for programming — not prompting — language models. It provides composable modules like ChainOfThought, ReAct, and custom Module classes that can be optimized and compiled. HoneyHive integrates with DSPy via the OpenInference DSPy instrumentor, which captures module calls, LM interactions, and tool executions as OpenTelemetry spans.

Quick Start

Add HoneyHive tracing in 4 lines of code. Initialize the tracer, create the instrumentors, and call .instrument() — all DSPy module calls, LLM requests, and tool executions are automatically traced.
Last tested with dspy 3.1.x (April 2026). Requires DSPy 3.x; the API changed significantly from 2.x.

What Gets Traced

The instrumentation automatically captures:
  • Module calls — Every forward() invocation with inputs and outputs (ReAct, ChainOfThought, Predict, custom Modules)
  • LLM calls — Model requests, responses, and token usage via the OpenAI instrumentor
  • Tool executions — Each tool call with arguments and results (in ReAct agents)
  • Pipeline composition — Parent-child nesting when Modules call sub-Modules
No manual instrumentation required.

Example: ReAct Agent with Tools

In HoneyHive, you’ll see the full trace: ReAct orchestration -> tool calls -> LLM reasoning steps.

Example: Multi-Module Pipeline

DSPy’s Module class lets you compose sub-modules into pipelines. Each module call is traced as a separate span with correct parent-child nesting:

Example: Custom Business Logic with @trace

Use the @trace decorator to wrap business logic that orchestrates multiple DSPy module calls. This creates a parent span encompassing the entire workflow, with DSPy module calls as child spans:
The @trace decorator and enrich_span() give you:
  • A parent span for the full business workflow
  • Custom metadata (order ID, priority, category) attached to the span
  • Custom metrics (steps completed) for monitoring
  • DSPy module calls automatically nested as child spans

Troubleshooting

Traces not appearing

  1. Call .instrument() before running any DSPy code — Instrumentation must be active before module execution:
  1. Check environment variables — Ensure HH_API_KEY is set
  2. Add the OpenAI instrumentor — DSPy uses LiteLLM/OpenAI under the hood. Adding the OpenAI instrumentor captures detailed LLM-level spans:
  1. Clean up instrumentors on exit — Call .uninstrument() to avoid duplicate spans in long-running processes:

Enrich Your Traces

Add user IDs and custom metadata to DSPy traces

Custom Spans

Create spans for business logic around module calls

Distributed Tracing

Trace pipelines across service boundaries

Query Trace Data

Export traces programmatically

Resources