Skip to content
GitHubLog inStart free
cetra is not released yet. These docs describe the development version.

Context (TypeScript)

Use withContext to group traces by session and user.

const turn = observe(({ question }: { question: string }) => `answered: ${question}`, {
name: "turn",
});
withContext({ sessionId: "chat-42", userId: "u-17", tags: ["beta"] }, () =>
turn({ question: "why?" }),
);

The values live in the OpenTelemetry context, so they follow AsyncLocalStorage into promises and concurrent flows; nested blocks merge (inner session and user win, tags union, metadata merges by key). They are stamped on every span of the SDK’s provider: session and user ids, tags, metadata, environment and release. Metadata is recorded to be read back by the server: keep personal data out of it, or mask it (see Masking). propagate: true also sets the session and user ids as W3C baggage entries for downstream services.

prompt links the spans to a prompt from getPrompt(): withContext({ prompt }, fn) stamps cetra.prompt.name and cetra.prompt.version on every span inside the block, and an inner prompt replaces an outer one. A fallback prompt has no version, so only its name is stamped. Any value that is not a Prompt is ignored. The Prompts page shows the whole flow.