instrument-typescript
Instrument TypeScript Agents
Prerequisite: npm install opik (get API key)
Basic Tracing
import { Opik } from "opik";
const client = new Opik({ projectName: process.env.OPIK_PROJECT_NAME || "my-agent" });
const trace = client.trace({ name: "my-agent", input: { query } });
const span = trace.span({ name: "llm-call", type: "llm" });
span.end({ output: { response } });
trace.end({ output: { response } });
await client.flush();
Entrypoint (Local Runner)
import { track } from "opik";
const myAgent = track(
{ name: "my-agent", entrypoint: true, params: [{ name: "query", type: "string" }] },
async (query: string) => {
// agent logic
return result;
}
);
params must be explicit — TS compilation strips param names/types. If omitted, all assumed string.
Express Example
import express from "express";
import { track } from "opik";
const summarize = track(
{ name: "summarize", entrypoint: true, params: [{ name: "message", type: "string" }] },
async (message: string) => `Summary of: ${message}`
);
const app = express();
app.get("/summarize", async (req, res) => {
res.send(await summarize(String(req.query.message ?? "")));
});
app.listen(3000);
Pair with: opik connect --pair <CODE> npx tsx app.ts
Framework Integrations
import { trackOpenAI } from "opik/openai"; // OpenAI
import { OpikTracer } from "opik/vercel"; // Vercel AI SDK
import { OpikTracer } from "opik"; // LangChain.js
Pitfalls
- Always
await client.flush()before exit - Span types:
general,llm,tool,guardrailonly - Missing
paramsintrack()means UI can't show typed input fields
More from comet-ml/opik-skills
opik
Opik observability for LLM agents — Agent Configuration, Local Runner (opik connect), Test Suites, threads, integrations. Use for "configure my agent", "connect my agent", "evaluate my agent" or "integrate with Opik".
147instrument
Add Opik tracing to an existing codebase. Detects language (Python/TypeScript), identifies LLM frameworks, adds appropriate decorators and integrations, marks entrypoints, and wires up environment config. Use for "instrument my code", "add opik tracing", "add observability", or "trace my agent".
131agent-config
Opik Agent Configuration — Blueprints, get_agent_config() with selectors, environment tags, Prompt/ChatPrompt fields, deploy_to(), MaskIDs, and config lifecycle.
5agent-ops
Agent lifecycle — architecture, configuration (Blueprints), Local Runner, evaluation, threads, production monitoring. Use for "evaluate my agent", "connect my agent", "configure my agent", "add guardrails".
5opik-connect
Opik Connect (Local Runner) — pair your local agent with the Opik browser UI for Python and TypeScript.
5evaluation-suites
Opik Evaluation Suites — assertions, execution policies, CI integration. Replaces old Datasets API.
5