Registry / observability / openinference-instrumentation-dspy

openinference-instrumentation-dspy

JSON →
library0.1.37pypypi✓ verified 83d ago

OpenTelemetry instrumentation for DSPy that automatically traces LLM calls, retrievers, and chain-of-thought reasoning. Current version 0.1.34, requires Python >=3.10, <3.15. Part of the Arize OpenInference ecosystem, actively maintained.

pip install openinference-instrumentation-dspy
INSTALL
IMPORT
SIG · OPENINFERENCE-INST
O
openinference-instrumentation-dspy
observabilitypythonv0.1.37
Install
2.7s avg
Import
531ms
Disk
23MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.37 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.552s · 24.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.7s · import 0.510s · 25MB
23MB installed
● package 23MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DSPyInstrumentor
from openinference.instrumentation.dspy import DSPyInstrumentor
Correct import path; no common mistakes reported.

Installs and configures the DSPy instrumentor, then runs a simple ChainOfThought example.

import os from opentelemetry import trace from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import SimpleSpanProcessor from openinference.instrumentation.dspy import DSPyInstrumentor from openinference.semconv.trace import SpanAttributes # Set up a tracer provider with a simple span processor (replace endpoint with your collector) from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter trace_provider = TracerProvider() trace_provider.add_span_processor( SimpleSpanProcessor(OTLPSpanExporter(endpoint=os.environ.get('OTEL_EXPORTER_OTLP_ENDPOINT', 'http://localhost:4318/v1/traces'))) ) trace.set_tracer_provider(trace_provider) # Instrument DSPy DSPyInstrumentor().instrument() # Now use DSPy normally - all traces will be captured. import dspy lm = dspy.LM('openai/gpt-4o-mini') dspy.configure(lm=lm) coT = dspy.ChainOfThought('question -> answer') print(coT(question="What is the capital of France?"))
Debug
Known issues
gotchaDSPyInstrumentor must be instrumented before any DSPy modules are imported or configured. If you instrument after importing dspy, some spans may be lost.
fix
Call DSPyInstrumentor().instrument() at the very start of your application, before importing dspy or any DSPy-related modules.
affects: all
gotchaRequires Python >=3.10 and <3.15. Using Python 3.9 or Python 3.15+ will result in installation failures or runtime errors.
fix
Use Python 3.10, 3.11, 3.12, or 3.13. Check your Python version before installing.
affects: 0.1.x
deprecatedThe older openinference-instrumentation-dspy package had different import paths (e.g., openinference_instrumentation_dspy). Migrate to the current OpenInference naming convention.
fix
Use `from openinference.instrumentation.dspy import DSPyInstrumentor`.
affects: <0.1.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'openinference.instrumentation.dspy'
The package is not installed or the import path is wrong.
fix
Install with `pip install openinference-instrumentation-dspy` and use the correct import: `from openinference.instrumentation.dspy import DSPyInstrumentor`.
RuntimeError: DSPyInstrumentor is not instrumented.
The instrument() method must be called exactly once before using DSPy.
fix
Call `DSPyInstrumentor().instrument()` at the start of your application. Do not call it multiple times.
AttributeError: module 'dspy' has no attribute 'LM'
DSPy version mismatch or import order issue. The instrumentor may have modified the module incorrectly if instrumented after import.
fix
Ensure DSPy is installed (pip install dspy) and instrument before any dspy usage: `DSPyInstrumentor().instrument(); import dspy`.
Upgrade
Version history
0.1.37latest on PyPI · released May 18, 2026
Audit
Dependencies
opentelemetry-apirequiredCore OpenTelemetry dependency for span creation and context propagation
openinference-instrumentationrequiredBase instrumentation package providing OpenInferenceSpanExporter and helpers
opentelemetry-sdkoptionalRequired to set up TracerProvider and export spans
Agent activity
26 hits · last 30 days
node
22
OpenAI (training)
3
Resources
openinference-instrumentation-dspy — pip install openinference-instrumentation-dspy · libregistry