skills/dspy-langtrace/SKILL.md
Use Langtrace for DSPy observability and tracing. Use when you want to set up Langtrace, langtrace-python-sdk, auto-instrument DSPy, trace DSPy calls, LLM observability, app.langtrace.ai, or self-hosted tracing. Also used for langtrace setup, langtrace API key, pip install langtrace-python-sdk, DSPy tracing, auto-instrument DSPy, langtrace self-hosted, langtrace docker, trace LM calls, langtrace vs phoenix, langtrace cloud.
npx skillsauth add lebsral/dspy-programming-not-prompting-lms-skills dspy-langtraceInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Guide the user through setting up Langtrace for automatic DSPy tracing and observability.
Langtrace is an open-source LLM observability platform with first-class DSPy auto-instrumentation. One line of code traces all DSPy LM calls, retrievals, module executions, token counts, and cost — no manual decorators needed.
| Component | Details captured |
|-----------|-----------------|
| LM calls | Prompts, responses, token counts, cost, latency |
| Retrievals | Queries, retrieved passages, scores |
| Module executions | Input/output per dspy.Module.forward() call |
| Nested pipelines | Full call tree with parent-child relationships |
Use Langtrace when:
Do NOT use Langtrace when:
/dspy-phoenix (Phoenix has built-in evals)/dspy-weave/dspy-mlflowpip install langtrace-python-sdk
from langtrace_python_sdk import langtrace
langtrace.init(api_key="your-key") # or set LANGTRACE_API_KEY env var
# That's it — all DSPy calls are now traced automatically
import dspy
dspy.configure(lm=dspy.LM("openai/gpt-4o-mini")) # or "anthropic/claude-sonnet-4-5-20250929", etc.
program = dspy.ChainOfThought("question -> answer")
result = program(question="What is DSPy?")
# View traces at app.langtrace.ai
For teams that need data to stay on-premises:
# Clone and start Langtrace
git clone https://github.com/Scale3-Labs/langtrace.git
cd langtrace
docker compose up -d
Then point your SDK at your local instance:
from langtrace_python_sdk import langtrace
langtrace.init(api_host="http://localhost:3000")
# All traces go to your self-hosted instance
export LANGTRACE_API_KEY="your-key" # Cloud API key
# OR
export LANGTRACE_API_HOST="http://localhost:3000" # Self-hosted URL
from langtrace_python_sdk import langtrace
langtrace.init() # Picks up from environment variables
Langtrace auto-instruments the entire call tree. No changes to your DSPy code:
from langtrace_python_sdk import langtrace
langtrace.init(api_key="your-key")
import dspy
dspy.configure(lm=dspy.LM("openai/gpt-4o-mini")) # or "anthropic/claude-sonnet-4-5-20250929", etc.
class RAGPipeline(dspy.Module):
def __init__(self):
self.retrieve = dspy.Retrieve(k=3)
self.answer = dspy.ChainOfThought("context, question -> answer")
def forward(self, question):
context = self.retrieve(question).passages
return self.answer(context=context, question=question)
pipeline = RAGPipeline()
result = pipeline(question="How do refunds work?")
# Langtrace captures:
# - The top-level RAGPipeline call
# - The Retrieve call (query, passages, latency)
# - The ChainOfThought LM call (prompt, response, tokens, cost)
Langtrace traces optimizer internals too — useful for understanding what MIPROv2 or GEPA tried:
from langtrace_python_sdk import langtrace
langtrace.init(api_key="your-key")
import dspy
dspy.configure(lm=dspy.LM("openai/gpt-4o-mini")) # or "anthropic/claude-sonnet-4-5-20250929", etc.
trainset = [...] # your training examples
program = dspy.ChainOfThought("question -> answer")
optimizer = dspy.MIPROv2(metric=my_metric, auto="light")
optimized = optimizer.compile(program, trainset=trainset)
# Every LM call the optimizer makes is traced — see which candidates it tried
The Langtrace dashboard shows:
Tag traces with metadata for filtering:
from langtrace_python_sdk import langtrace, with_langtrace_root_span
@with_langtrace_root_span("customer-query")
def handle_query(user_id, question):
# Custom attributes appear in the UI for filtering
langtrace.inject_additional_attributes({
"user_id": user_id,
"environment": "production",
})
return pipeline(question=question)
| Feature | Langtrace | Arize Phoenix | Jaeger | |---------|-----------|---------------|--------| | DSPy auto-instrumentation | Yes (built-in) | Yes (plugin) | Manual | | Setup effort | One line | Two lines + launch | Docker + manual spans | | Self-hosted option | Yes (Docker) | Yes | Yes | | Cloud option | Yes (app.langtrace.ai) | Yes (Arize platform) | No | | LM call details | Prompts, tokens, cost | Prompts, tokens | Custom attributes | | Evals/evaluation | Basic | Built-in evals module | No | | Best for | DSPy-first teams | Teams wanting evals + traces | Teams already using Jaeger |
Want DSPy tracing?
|
+- Easiest setup, auto-instrument everything? -> Langtrace
+- Need built-in evaluation features? -> Arize Phoenix (/dspy-phoenix)
+- Team already uses W&B? -> W&B Weave (/dspy-weave)
+- Need full ML lifecycle (registry, deploy)? -> MLflow (/dspy-mlflow)
+- Team already uses Jaeger? -> Jaeger (see /ai-tracing-requests)
langtrace.init() after importing and configuring DSPy. Langtrace must be initialized before any DSPy imports or configuration — it patches DSPy modules at import time. Always call langtrace.init() as the first line after from langtrace_python_sdk import langtrace, before import dspy.dspy.configure_cache(enable=False).TRACE_DSPY_CHECKPOINT=false in production. Checkpoint tracing is enabled by default and serializes predictor state at each step, adding latency. For production deployments, set export TRACE_DSPY_CHECKPOINT=false to disable it.@with_langtrace_root_span when auto-instrumentation already traces everything. The root span decorator is only needed when you want to group DSPy calls under a named parent span with custom metadata. For basic tracing, langtrace.init() alone is sufficient — do not add decorators unless you need metadata filtering.Install any skill:
npx skills add lebsral/DSPy-Programming-not-prompting-LMs-skills --skill <name>
/dspy-phoenix/dspy-weave/dspy-mlflow/ai-monitoring/ai-tracing-requests/ai-do if you do not have it — it routes any AI problem to the right skill and is the fastest way to work: npx skills add lebsral/DSPy-Programming-not-prompting-LMs-skills --skill ai-dotools
See what is happening during optimizer.compile() instead of waiting blind. Use when you want to watch optimization progress, see scores as they come in, know if your optimizer is working, check if optimization is stuck, understand why optimization is taking too long, get live progress during compile, monitor convergence, detect overfitting during optimization, interpret optimization results, or pick the right tool for watching optimization. Also used for optimizer progress bar, is my optimizer doing anything, optimization seems stuck, how long will optimization take, watch GEPA run, watch MIPROv2 run, live optimization dashboard, optimizer not improving, scores not going up, optimization taking forever, see what optimizer is doing, debug slow optimization, optimization visibility, optimizer metrics, track compile progress, optimization observability.
testing
Use when you want the highest-quality prompt optimization DSPy offers — jointly optimizes instructions and few-shot demos, with auto=light/medium/heavy presets. Common scenarios - you want the best possible accuracy from prompt optimization, jointly tuning instructions and few-shot demonstrations, using auto presets for different compute budgets, or when COPRO or BootstrapFewShot alone are not reaching your accuracy target. Related - ai-improving-accuracy, dspy-copro, dspy-bootstrap-few-shot. Also used for dspy.MIPROv2, best DSPy optimizer, highest quality optimization, auto=light medium heavy, joint instruction and demo optimization, most powerful prompt optimizer, MIPROv2 vs COPRO vs BootstrapFewShot, which optimizer should I use, state of the art prompt optimization, when to use MIPROv2, optimize both instructions and examples, heavy optimization for production, best optimizer for accuracy.
testing
Use LangWatch for DSPy auto-tracing and real-time optimizer progress. Use when you want to set up LangWatch, langwatch.dspy.init, auto-tracing DSPy, real-time optimization dashboard, optimizer progress tracking, app.langwatch.ai, or DSPy optimizer dashboard. Also used for langwatch setup, pip install langwatch, langwatch trace, optimizer progress, real-time optimization, watch optimizer run, LangWatch self-hosted, langwatch docker, langwatch vs langtrace, langwatch autotrack_dspy.
data-ai
Use when you want to optimize instructions without few-shot examples — a lightweight alternative to COPRO when you do not have or do not want to use demonstrations. Common scenarios - optimizing instructions when you do not have or do not want to use few-shot demonstrations, lightweight instruction search as a first step, tasks where examples in the prompt confuse the model, or when you want fast instruction optimization without the cost of COPRO. Related - ai-improving-accuracy, dspy-copro, dspy-miprov2. Also used for dspy.GEPA, instruction optimization without demos, lightweight prompt optimization, optimize instructions only, no few-shot examples needed, GEPA vs COPRO, quick instruction search, when demonstrations hurt performance, zero-shot optimization, instruction-only optimizer, simplest instruction tuner, fast prompt optimization, skip few-shot and just tune instructions, optimize Pydantic field descriptions, GEPA structured output, GEPA does not optimize field desc.