{"slug": "dspy-observability-monitoring-with-opentelemetry", "title": "DSPy Observability & Monitoring with OpenTelemetry", "summary": "SigNoz announced support for monitoring DSPy programs via OpenTelemetry, enabling real-time visibility into DSPy module calls and language model requests. The integration uses the OpenInference DSPy instrumentation to capture traces with DSPy-native attributes, allowing users to trace program runs, compare model usage, and set alerts on latency and errors. SigNoz offers both no-code auto-instrumentation and code-based instrumentation for connecting DSPy applications to its observability platform.", "body_md": "What is DSPy Observability?\n\nDSPy observability gives you real-time visibility into your DSPy programs by collecting traces using [OpenTelemetry](https://opentelemetry.io/). The [OpenInference DSPy instrumentation](https://pypi.org/project/openinference-instrumentation-dspy/) automatically captures every DSPy module call (`Predict`\n\n, `ChainOfThought`\n\n, `ReAct`\n\n, custom `Module`\n\npipelines) and the underlying language model request as spans, tagged with DSPy-native attributes such as `openinference.span.kind`\n\n(CHAIN, LLM, TOOL), `llm.model_name`\n\n, and `llm.provider`\n\n.\n\nWith full DSPy monitoring in SigNoz, you can trace every program run end to end, break down module and tool activity, compare model usage and latency, set alerts on latency and errors, and continuously improve the reliability of your DSPy applications.\n\nPrerequisites\n\n- A\n[SigNoz Cloud account](https://signoz.io/teams/)with an active ingestion key or[Self Hosted SigNoz instance](https://signoz.io/docs/install/self-host/) - Python 3.9 or later\n- A DSPy program and a configured language model provider (for example, an Anthropic or OpenAI API key)\n\nMonitoring DSPy with OpenTelemetry\n\nDSPy does not ship with OpenTelemetry built in, so you add the [OpenInference DSPy instrumentation](https://pypi.org/project/openinference-instrumentation-dspy/) and export traces to SigNoz over OTLP/HTTP. You can wire this up two ways. For more details, refer to the [DSPy documentation](https://dspy.ai/).\n\nNo-code auto-instrumentation is recommended for quick setup with minimal code changes. It is ideal when you want observability up and running without modifying your application code, using the OpenInference DSPy instrumentor loaded automatically at startup.\n\n**Step 1:** Install the necessary packages in your Python environment.\n\n```\npip install \\\n  dspy \\\n  opentelemetry-distro \\\n  opentelemetry-exporter-otlp \\\n  openinference-instrumentation-dspy\n```\n\n**Step 2:** Add automatic instrumentation.\n\n```\nopentelemetry-bootstrap --action=install\n```\n\n**Step 3:** Run an example.\n\n``` python\nimport dspy\n\ndspy.configure(lm=dspy.LM(\"anthropic/claude-sonnet-5\"))\n\npredict = dspy.Predict(\"question -> answer\")\nresult = predict(question=\"What is OpenTelemetry in one sentence?\")\nprint(result.answer)\n```\n\n**Step 4:** Run your application with auto-instrumentation.\n\n```\nOTEL_RESOURCE_ATTRIBUTES=\"service.name=<service_name>\" \\\nOTEL_EXPORTER_OTLP_ENDPOINT=\"https://ingest.<region>.signoz.cloud:443\" \\\nOTEL_EXPORTER_OTLP_HEADERS=\"signoz-ingestion-key=<your-ingestion-key>\" \\\nOTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \\\nOTEL_TRACES_EXPORTER=otlp \\\nopentelemetry-instrument <your_run_command>\n```\n\n**Verify these values:**\n\n`<service_name>`\n\n: The name your DSPy service appears under in SigNoz.`<region>`\n\n: Your[SigNoz Cloud region](https://signoz.io/docs/ingestion/signoz-cloud/overview/#endpoint).`<your-ingestion-key>`\n\n: Your SigNoz[ingestion key](https://signoz.io/docs/ingestion/signoz-cloud/keys/).`<your_run_command>`\n\n: The command you use to run your application, for example`python main.py`\n\n.\n\nCode-based instrumentation gives you fine-grained control over your telemetry configuration. Use this approach when you need to customize resource attributes, sampling strategies, or integrate with existing observability infrastructure.\n\n**Step 1:** Install the necessary packages in your Python environment.\n\n```\npip install \\\n  dspy \\\n  openinference-instrumentation-dspy \\\n  opentelemetry-sdk \\\n  opentelemetry-exporter-otlp-proto-http\n```\n\n**Step 2:** Configure the OpenTelemetry exporter.\n\nCreate a `telemetry.py`\n\nmodule that sets up the tracer provider, wires the OTLP/HTTP exporter to SigNoz, and turns on the DSPy instrumentation:\n\n``` python\nfrom openinference.instrumentation.dspy import DSPyInstrumentor\nfrom opentelemetry import trace as trace_api\nfrom opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter\nfrom opentelemetry.sdk import trace as trace_sdk\nfrom opentelemetry.sdk.resources import Resource\nfrom opentelemetry.sdk.trace.export import BatchSpanProcessor\n\ndef setup_tracing() -> None:\n    resource = Resource.create({\"service.name\": \"<service_name>\"})\n    tracer_provider = trace_sdk.TracerProvider(resource=resource)\n\n    exporter = OTLPSpanExporter(\n        endpoint=\"https://ingest.<region>.signoz.cloud:443/v1/traces\",\n        headers={\"signoz-ingestion-key\": \"<your-ingestion-key>\"},\n    )\n    tracer_provider.add_span_processor(BatchSpanProcessor(exporter))\n    trace_api.set_tracer_provider(tracer_provider)\n\n    # Turn on OpenInference DSPy auto-instrumentation.\n    DSPyInstrumentor().instrument(tracer_provider=tracer_provider)\n```\n\n**Verify these values:**\n\n`<service_name>`\n\n: The name your DSPy service appears under in SigNoz.`<region>`\n\n: Your[SigNoz Cloud region](https://signoz.io/docs/ingestion/signoz-cloud/overview/#endpoint).`<your-ingestion-key>`\n\n: Your SigNoz[ingestion key](https://signoz.io/docs/ingestion/signoz-cloud/keys/).\n\n**Step 3:** Instrument your DSPy program.\n\nCall `setup_tracing()`\n\nonce, before you configure DSPy and run your modules. Every DSPy module call and each underlying model request is then captured automatically:\n\n``` python\nimport dspy\n\nfrom telemetry import setup_tracing\n\nsetup_tracing()\n\ndspy.configure(lm=dspy.LM(\"anthropic/claude-sonnet-5\"))\n\npredict = dspy.Predict(\"question -> answer\")\nresult = predict(question=\"What is OpenTelemetry in one sentence?\")\nprint(result.answer)\n```\n\nEach run emits a trace whose spans carry `openinference.span.kind`\n\n(CHAIN, LLM, TOOL) along with `llm.model_name`\n\nand `llm.provider`\n\non the model spans. OpenTelemetry batches spans before sending, so allow a few seconds after a run for data to appear in SigNoz.\n\nView DSPy Traces in SigNoz\n\nOnce configured, your DSPy program automatically emits traces for every run.\n\nTraces are available in SigNoz under the Traces tab:\n\nWhen you click on a trace in SigNoz, you'll see a detailed view of the trace, including all associated spans, along with their events and attributes. CHAIN spans represent DSPy module and pipeline steps, LLM spans carry `llm.model_name`\n\nand `llm.provider`\n\n, and TOOL spans capture ReAct tool calls.\n\nDSPy Observability Dashboard\n\nYou can also check out our custom [DSPy dashboard](https://signoz.io/docs/dashboards/dashboard-templates/dspy-dashboard/) which provides specialized visualizations for monitoring your DSPy programs. The dashboard includes pre-built charts for module, chain, and tool activity, per-model usage, latency percentiles, and errors, along with import instructions to get started quickly.\n\nTroubleshooting DSPy Observability\n\n[Troubleshooting DSPy Observability](#troubleshooting-dspy-observability)\n\nNo traces in SigNoz\n\n- Confirm your program actually ran a DSPy module. Setting up tracing alone emits nothing.\n- Verify\n`setup_tracing()`\n\nis called before`dspy.configure(...)`\n\nand before any module runs. - Check that the region in the OTLP endpoint matches your SigNoz account.\n- OpenTelemetry batches data before sending, so wait 10-30 seconds after a run.\n\nVerify the instrumentor\n\nMake sure `DSPyInstrumentor().instrument(...)`\n\nruns against the same tracer provider you registered with `trace_api.set_tracer_provider(...)`\n\n. If you build multiple providers, spans can be dropped silently.\n\nAuth errors (401 / 403)\n\nRe-check the ingestion key in the `signoz-ingestion-key`\n\nheader. It must be the exact key from your SigNoz Ingestion Settings, with no extra spaces or quotes.\n\nEndpoint issues\n\nKeep the `https://`\n\nscheme and `:443`\n\nport on the endpoint, and the `/v1/traces`\n\npath for OTLP/HTTP. Do not send OTLP/HTTP traffic to the gRPC port.\n\nSetup OpenTelemetry Collector (Optional)\n\n[Setup OpenTelemetry Collector (Optional)](#setup-opentelemetry-collector-optional)\n\nWhat is the OpenTelemetry Collector?\n\nThink of the OTel Collector as a middleman between your app and SigNoz. Instead of your application sending data directly to SigNoz, it sends everything to the Collector first, which then forwards it along.\n\nWhy use it?\n\n**Cleaning up data**- Filter out noisy traces you don't care about, or remove sensitive info before it leaves your servers.** Keeping your app lightweight**- Let the Collector handle batching, retries, and compression instead of your application code.** Adding context automatically**- The Collector can tag your data with useful info like which Kubernetes pod or cloud region it came from.** Future flexibility**- Want to send data to multiple backends later? The Collector makes that easy without changing your app.\n\nSee [Switch from direct export to Collector](https://signoz.io/docs/opentelemetry-collection-agents/opentelemetry-collector/switch-to-collector/) for step-by-step instructions to convert your setup.\n\nFor more details, see [Why use the OpenTelemetry Collector?](https://signoz.io/docs/opentelemetry-collection-agents/opentelemetry-collector/why-to-use-collector/) and the [Collector configuration guide](https://signoz.io/docs/opentelemetry-collection-agents/opentelemetry-collector/configuration/).\n\nAdditional resources:\n\n- Set up\n[alerts](https://signoz.io/docs/alerts/)for high latency or error rates - Learn more about\n[querying traces](https://signoz.io/docs/userguide/traces/) - Explore\n[log correlation](https://signoz.io/docs/userguide/logs_query_builder/)", "url": "https://wpnews.pro/news/dspy-observability-monitoring-with-opentelemetry", "canonical_source": "https://signoz.io/docs/dspy-observability", "published_at": "2026-07-21 00:00:00+00:00", "updated_at": "2026-07-22 04:25:12.255518+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools", "artificial-intelligence"], "entities": ["SigNoz", "OpenTelemetry", "OpenInference", "DSPy", "Anthropic", "OpenAI"], "alternates": {"html": "https://wpnews.pro/news/dspy-observability-monitoring-with-opentelemetry", "markdown": "https://wpnews.pro/news/dspy-observability-monitoring-with-opentelemetry.md", "text": "https://wpnews.pro/news/dspy-observability-monitoring-with-opentelemetry.txt", "jsonld": "https://wpnews.pro/news/dspy-observability-monitoring-with-opentelemetry.jsonld"}}