trace-claude-code
Control Opik tracing for your Claude Code sessions
Add Opik observability to your code - automatically detects frameworks and adds the correct integration
> /plugin marketplace add comet-ml/opik-claude-code-plugin > /plugin install opik@opik
How it fires
How this command gets triggered: by you, by Claude, or both.
/instrumentContext preview
What this command does when you run it.
Add Opik observability to your code - automatically detects frameworks and adds the correct integration
description: Add Opik observability to your code - automatically detects frameworks and adds the correct integration argument-hint: [file or description of what to instrument] allowed-tools: - Read - Write - Edit - Glob - Grep - Skill - Bash model: sonnet
Add tracing to the user's code so their LLM application is observable in Opik.
**User request:** $ARGUMENTS
Use the Skill tool to load BOTH of these skills before doing anything else:
1. **`opik`** — Opik SDK reference: all integrations, tracing patterns, span types, code snippets 2. **`agent-ops`** — Agent architecture patterns, evaluation, what to trace and why
Load them both now. Do not proceed until both are loaded.
**Do NOT rely only on import statements.** Code may use dynamic imports (`__import__`, `importlib`), factory patterns, or lazy loading that makes frameworks invisible to import scanning.
Instead, start by reading dependency manifests to build a checklist of frameworks that MUST be instrumented:
1. **Read dependency files** — check `requirements.txt`, `pyproject.toml`, `setup.py`, `setup.cfg`, `Pipfile`, `package.json` (for TypeScript/Node) 2. **Build a framework checklist** — for each dependency that has an Opik integration (OpenAI, Anthropic, LangChain, CrewAI, LlamaIndex, etc.), add it to your checklist 3. **Note ALL languages** — if the project has both Python files AND TypeScript/JavaScript files (check for `package.json`, `tsconfig.json`, `*.ts`, `*.js`), you must instrument BOTH languages
This checklist is your source of truth. Every framework on it must be accounted for by the end.
Now read the code to understand how it actually works. **Follow the execution flow**, don't just scan files in isolation:
1. **Find entry points** — look for `if __name__ == "__main__"`, CLI commands, HTTP handlers, exported functions. There may be MULTIPLE entry points. 2. **Trace the call graph** — from each entry point, follow function calls to understand the full execution path. Read every file that gets called. 3. **Find where each framework on your checklist is actually used** — it may be behind factories, registries, decorators, proxies, or dynamic imports. Search for:
4. **Identify existing tracing** — check if there's already tracing code. Verify it actually sends to Opik (not a homegrown stub or different tracing system). If it's fake or non-Opik, replace it.
Before deciding what integration to use where, **map out what a single trace should look like** for one user request. A single request to the agent should produce exactly ONE trace with nested spans — never multiple disconnected traces.
Draw out the trace tree based on the call graph you traced in Step 3:
Trace: "agent_name" (general) ├── Span: "step_1" (tool) — e.g., search, retrieval │ └── Span: "llm_call" (llm) — e.g., embedding, completion ├── Span: "step_2" (llm) — e.g., summarize └── Span: "step_3" (llm) — e.g., synthesize final answer
For each node in the tree, decide:
NEVER create a new top-level trace for work that is part of an existing user request. If a component handles part of a request, its spans MUST be linked to the parent trace.
**Follow the trace tree from Step 4.** For each node, apply the integration pattern that matches its position in the tree.
**Before writing any integration code, read the exact reference file for the language/framework you're about to instrument.** Do NOT guess import paths or API patterns from memory. Use the Read tool on the relevant reference:
Copy the exact import paths and usage patterns from the reference. Key principles:
1. **Follow the trace tree** — Each node in your trace tree from Step 4 tells you w
Log Claude Code sessions to Opik for LLM observability, plus skills and agents for building observable AI applications. Opik is the open-source LLM observability and evaluation platform, built by Comet.
Repo: comet-ml/opik-claude-code-plugin
Control Opik tracing for your Claude Code sessions