Users and steps
Put a user, session and tags on each run, record your own steps, and choose whether prompts and replies are kept.
Model calls are traced on their own. Two small additions make traces much easier to use: saying who a run was for, and naming the steps your code takes around the model calls.
Who a run was for
Wrap a request's work in withContext. Everything traced inside it, model calls included, carries the user, session, tags and metadata you give:
import { withContext } from 'cencori/observe';
app.post('/chat', async (req, res) => {
const reply = await withContext(
{ userId: req.user.id, sessionId: req.body.chatId, tags: ['support'] },
() => answer(req.body.message),
);
res.json(reply);
});withContext calls nest: an inner one adds to the outer one's tags and metadata, and can replace its user or session.
These are labels you choose. Cencori doesn't treat them as identity or permissions, so don't put secrets or passwords in them.
Your own steps
trace records a step of your own as part of the run, with the model calls made inside it shown beneath it:
import { trace } from 'cencori/observe';
const reply = await trace(
'answer-ticket',
async () => {
const order = await trace('lookup-order', () => db.orders.find(ticket.orderId), { type: 'tool' });
return openai.chat.completions.create({ /* ...uses order... */ });
},
{ type: 'agent', input: ticket.text },
);- name: what the step is called in the trace.
- type:
agent,chain(the default),tool,retriever,llmorembedding. It decides how the step is shown. - input: what the step started from. What the function returns is recorded as its output.
If the function throws, the step is marked failed with the error's message, and the error is thrown on to your code as before. trace works with both sync and async functions.
Prompts and replies
By default, each model call's messages and reply are kept with its trace, which is what makes a trace useful for debugging. To keep them out of Cencori:
import { observe } from 'cencori/observe';
observe({ captureContent: false });Or set CENCORI_OBSERVE_CONTENT=false, with no code change. Either way, messages, replies and tool arguments are removed in your app, before anything is sent, for every library, the Vercel AI SDK included. Cencori still records each call's model, tokens, latency, cost and errors.
When they are kept, prompts and replies are stored for as long as your plan keeps traces: see Plans and limits.
Other options
Pass them to observe() anywhere in your app. They apply from then on, even though importing cencori/observe has already started it.
Already using OpenTelemetry?
If your app already sets up OpenTelemetry (with Sentry, Datadog, @vercel/otel or your own), cencori/observe still sends your AI calls to Cencori, and logs a line saying so. To send the rest of your spans to Cencori as well, add Cencori's exporter to your setup:
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { CencoriSpanExporter } from 'cencori/observe';
// alongside your existing span processors
new BatchSpanProcessor(new CencoriSpanExporter());Or point any OpenTelemetry exporter at Cencori: see OpenTelemetry.

