Skip to main content

DSPy observability SDK for cmpnd-track

Project description

cmpnd

DSPy observability SDK for cmpnd-track.

Automatically trace your DSPy programs with one line of code.

Installation

pip install cmpnd-observe

For DSPy integration:

pip install cmpnd-observe[dspy]

Quick Start

import cmpnd

# Configure with your API key
cmpnd.configure(api_key="ct_xxx", project="my-project")

# Enable automatic DSPy instrumentation
cmpnd.auto_instrument()

# Your DSPy code is now automatically traced!
import dspy

lm = dspy.LM("openai/gpt-4o-mini")
dspy.configure(lm=lm)

cot = dspy.ChainOfThought("question -> answer")
result = cot(question="What is DSPy?")
# Trace is automatically sent to cmpnd-track

Configuration

Using environment variables

export CMPND_API_KEY="ct_your_api_key"
export CMPND_ENDPOINT="https://api.cmpnd.io"  # optional
import cmpnd

cmpnd.configure()  # Reads from environment
cmpnd.auto_instrument()

Configuration options

cmpnd.configure(
    api_key="ct_xxx",                # Required: API key
    endpoint="https://api.cmpnd.io", # Optional: Backend URL
    project="my-project",            # Optional: Project name
    batch_size=100,                  # Optional: Batch size for export
    flush_interval_seconds=5.0,      # Optional: Flush interval
    capture_inputs=True,             # Optional: Capture function inputs
    capture_outputs=True,            # Optional: Capture function outputs
    default_tags={"env": "prod"},    # Optional: Tags for all traces
)

Custom Spans

Add custom spans to trace non-DSPy code:

Using the decorator

from cmpnd import trace, SpanType

@trace(name="fetch_documents", span_type=SpanType.RETRIEVE)
def fetch_documents(query: str) -> list[str]:
    # Your retrieval logic
    return documents

Using the context manager

from cmpnd import start_span, SpanType

def run_pipeline(query: str):
    with start_span("vector_search", span_type=SpanType.RETRIEVE) as span:
        span.set_attribute("index", "my-faiss-index")
        docs = search(query)
        span.set_outputs({"doc_count": len(docs)})

    return generate(query, docs)

What Gets Traced

The SDK automatically captures:

Module Execution

  • Module type (Predict, ChainOfThought, ReAct, etc.)
  • Signature name and instructions
  • Input/output field names
  • Demo count

LM Calls

  • Model name and provider
  • Token usage (prompt, completion, total)
  • Request/response content

Adapters

  • Format and parse operations
  • Input/output transformations

Tools

  • Tool name and description
  • Invocation inputs/outputs

Evaluations

  • Evaluation scores
  • Program being evaluated

Span Types

Available span types for categorization:

  • SpanType.MODULE - Generic DSPy module
  • SpanType.PREDICT - Predict module
  • SpanType.CHAIN_OF_THOUGHT - ChainOfThought module
  • SpanType.REACT - ReAct agent
  • SpanType.RETRIEVE - Retrieval operations
  • SpanType.LM_CALL - Language model calls
  • SpanType.ADAPTER_FORMAT - Adapter formatting
  • SpanType.ADAPTER_PARSE - Adapter parsing
  • SpanType.TOOL - Tool invocations
  • SpanType.EVALUATION - Evaluation runs

API Reference

cmpnd.configure()

Initialize the SDK with your API key and options.

cmpnd.auto_instrument()

Automatically register the callback with DSPy.

cmpnd.CmpndCallback

The callback class for manual registration:

import dspy
import cmpnd

cmpnd.configure(api_key="ct_xxx")
dspy.configure(callbacks=[cmpnd.CmpndCallback()])

cmpnd.trace()

Decorator for custom traced functions.

cmpnd.start_span()

Context manager for custom spans.

cmpnd.get_current_trace()

Get the current trace (if any).

cmpnd.get_current_span()

Get the current span (if any).

cmpnd.shutdown_exporter()

Gracefully shutdown the background exporter.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cmpnd_observe-0.0.1.tar.gz (112.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cmpnd_observe-0.0.1-py3-none-any.whl (59.1 kB view details)

Uploaded Python 3

File details

Details for the file cmpnd_observe-0.0.1.tar.gz.

File metadata

  • Download URL: cmpnd_observe-0.0.1.tar.gz
  • Upload date:
  • Size: 112.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for cmpnd_observe-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4affa52df71716d4df080c791c7238c99678157e332b1fdc67564e359fb48ec6
MD5 230de48f6d1bd8ae3247844e4e4f5856
BLAKE2b-256 e1696099cda207fbe86f9c1f59c29f6d4a14d433bc96af06d1e3f27b2987b2dd

See more details on using hashes here.

File details

Details for the file cmpnd_observe-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: cmpnd_observe-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 59.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for cmpnd_observe-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 42a1052927713ccabf086292cf22b89565902fac60b7e0e64946e77827b74119
MD5 afe49199126acbb66e70f398c52dbdce
BLAKE2b-256 49377c390b74b79b4af6f25a18b97e453e704954e305f00d77ccaa74bb4b0189

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page