{"id":24168,"library":"openinference-instrumentation-dspy","title":"OpenInference DSPy Instrumentation","description":"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.","status":"active","version":"0.1.34","language":"python","source_language":"en","source_url":"https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-dspy","tags":["dspy","openinference","opentelemetry","instrumentation","llm","tracing"],"install":[{"cmd":"pip install openinference-instrumentation-dspy","lang":"bash","label":"PyPI install"}],"dependencies":[{"reason":"Core OpenTelemetry dependency for span creation and context propagation","package":"opentelemetry-api","optional":false},{"reason":"Base instrumentation package providing OpenInferenceSpanExporter and helpers","package":"openinference-instrumentation","optional":false},{"reason":"Required to set up TracerProvider and export spans","package":"opentelemetry-sdk","optional":true}],"imports":[{"note":"Correct import path; no common mistakes reported.","wrong":"","symbol":"DSPyInstrumentor","correct":"from openinference.instrumentation.dspy import DSPyInstrumentor"}],"quickstart":{"code":"import os\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import SimpleSpanProcessor\nfrom openinference.instrumentation.dspy import DSPyInstrumentor\nfrom openinference.semconv.trace import SpanAttributes\n\n# Set up a tracer provider with a simple span processor (replace endpoint with your collector)\nfrom opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter\ntrace_provider = TracerProvider()\ntrace_provider.add_span_processor(\n    SimpleSpanProcessor(OTLPSpanExporter(endpoint=os.environ.get('OTEL_EXPORTER_OTLP_ENDPOINT', 'http://localhost:4318/v1/traces')))\n)\ntrace.set_tracer_provider(trace_provider)\n\n# Instrument DSPy\nDSPyInstrumentor().instrument()\n\n# Now use DSPy normally - all traces will be captured.\nimport dspy\nlm = dspy.LM('openai/gpt-4o-mini')\ndspy.configure(lm=lm)\ncoT = dspy.ChainOfThought('question -> answer')\nprint(coT(question=\"What is the capital of France?\"))","lang":"python","description":"Installs and configures the DSPy instrumentor, then runs a simple ChainOfThought example."},"warnings":[{"fix":"Call DSPyInstrumentor().instrument() at the very start of your application, before importing dspy or any DSPy-related modules.","message":"DSPyInstrumentor must be instrumented before any DSPy modules are imported or configured. If you instrument after importing dspy, some spans may be lost.","severity":"gotcha","affected_versions":"all"},{"fix":"Use Python 3.10, 3.11, 3.12, or 3.13. Check your Python version before installing.","message":"Requires Python >=3.10 and <3.15. Using Python 3.9 or Python 3.15+ will result in installation failures or runtime errors.","severity":"gotcha","affected_versions":"0.1.x"},{"fix":"Use `from openinference.instrumentation.dspy import DSPyInstrumentor`.","message":"The older openinference-instrumentation-dspy package had different import paths (e.g., openinference_instrumentation_dspy). Migrate to the current OpenInference naming convention.","severity":"deprecated","affected_versions":"<0.1.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Install with `pip install openinference-instrumentation-dspy` and use the correct import: `from openinference.instrumentation.dspy import DSPyInstrumentor`.","cause":"The package is not installed or the import path is wrong.","error":"ModuleNotFoundError: No module named 'openinference.instrumentation.dspy'"},{"fix":"Call `DSPyInstrumentor().instrument()` at the start of your application. Do not call it multiple times.","cause":"The instrument() method must be called exactly once before using DSPy.","error":"RuntimeError: DSPyInstrumentor is not instrumented."},{"fix":"Ensure DSPy is installed (pip install dspy) and instrument before any dspy usage: `DSPyInstrumentor().instrument(); import dspy`.","cause":"DSPy version mismatch or import order issue. The instrumentor may have modified the module incorrectly if instrumented after import.","error":"AttributeError: module 'dspy' has no attribute 'LM'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}