Framework guide
OpenAI
Record OpenAI calls as SupaTrace events from Python or Node.
Python SDK: Beta. JavaScript SDK: Coming soon. pip install supatrace==0.1.0 (alpha, Python 3.10+). The JavaScript package is not published to npm. See SDK availability.
Record a call in source mode
Source mode is the default. It makes no network request. The SDK checks your events against the server's batch rules and writes one file to a local spool for you to review. The example records the model name and token counts, not the prompt or reply.
Python Beta
pip install supatrace==0.1.0import datetime
import supatrace
from openai import OpenAI
trace = supatrace.init(service="support-bot", spool="./spool")
now = lambda: datetime.datetime.now(datetime.timezone.utc).isoformat()
started = now()
reply = OpenAI().chat.completions.create(model="YOUR_MODEL", messages=[{"role": "user", "content": "Say hello."}])
result = trace.batch([
{"id": "req-1", "time": started, "kind": "request", "name": "chat.completions", "data": {"model": "YOUR_MODEL"}},
{"id": "res-1", "time": now(), "kind": "response", "name": "chat.completions", "data": {"total_tokens": reply.usage.total_tokens}},
])
print(result["report"]["valid"], result["report"]["path"])Node Coming soon
npm install ./packages/supatrace-js # from the public repository root. Node 22 or later, ESM onlyimport { init } from "supatrace";
import OpenAI from "openai";
const trace = init("support-bot", { spool: "./spool" });
const started = new Date().toISOString();
const reply = await new OpenAI().chat.completions.create({ model: "YOUR_MODEL", messages: [{ role: "user", content: "Say hello." }] });
const result = trace.batch([
{ id: "req-1", time: started, kind: "request", name: "chat.completions", data: { model: "YOUR_MODEL" } },
{ id: "res-1", time: new Date().toISOString(), kind: "response", name: "chat.completions", data: { total_tokens: reply.usage.total_tokens } },
]);
console.log(result.report.valid, result.report.path);The JavaScript SDK has no automatic OpenAI instrumentation.
Review, then upload
Read the spooled file. Remove anything you do not want stored. Then upload it as shown in the quickstart. Batch limits apply.
Automatic Python spans over OTLP Beta
With mode="otlp" the Python SDK registers the opentelemetry-instrumentation-openai instrumentor when it is installed and exports spans to SUPATRACE_OTLP_ENDPOINT + /v1/traces, authenticated with your write key. Framework instrumentation has local tests but no hosted acceptance proof. For a first trace, use a stock exporter from the OpenTelemetry guide.
pip install "opentelemetry-sdk>=1.27" "opentelemetry-exporter-otlp-proto-http>=1.27" opentelemetry-instrumentation-openai
export SUPATRACE_OTLP_ENDPOINT="https://supatrace.dev" # SupaTrace SDK OTLP mode (Python Beta; JavaScript source only)
export SUPATRACE_API_KEY="YOUR_WRITE_KEY"import supatrace
trace = supatrace.init(service="support-bot", mode="otlp", instruments=["openai"])
print(trace.capture["sending"], trace.capture["instrumented"], trace.capture["skipped"])Nothing is sent unless the endpoint, the key and the OpenTelemetry packages are all present. When one is missing, trace.capture["skipped"] says which. Prompt and response content is not captured unless you pass capture_content=True or set SUPATRACE_CAPTURE_CONTENT=1.