Set TCC environment variables
.env.local
Instrument AI SDK
If your API calls are directly made from your Next.js API routes, you can use theregisterOTelTCC function to instrument your calls.
If you’re using a Node.js framework (e.g. Express, Fastify, etc.), you can configure the NodeSDK directly with the TCCSpanProcessor.
- Next.js
- Node.js
Step 1: Install dependencies
Step 2: Add instrumentation to Next.js
If you haven’t already, add aninstrumentation.[js|ts] file to your project, under the app directory. See the Next.js Instrumentation guide for more information on instrumenting your Next.js application.Call the registerOTelTCC function and provide your API key. This allows your app to export any AI SDK related traces to The Context Company.instrumentation.ts
TCCSpanProcessor for use with the registerOTel function from @vercel/otel. This is essentially the same as using registerOTelTCC, but allows you to pass in additional span processors.Step 3: Enable telemetry for AI SDK calls
As of AI SDK v5, telemetry is experimental and requires theexperimental_telemetry flag to be set to true. Ensure you set this flag to true for all AI SDK calls.Adding custom metadata
Custom metadata allows you to add additional properties to your agent runs. This is particularly useful for tying agent runs to your own specific business logic, letting you filter and analyze agent runs by user, organization, feature, or some other dimension. Custom metadata must be passed as a key-value pair to themetadata object.
route.ts
The
tcc.* namespace is reserved. Only the reserved TCC metadata keys (tcc.runId, tcc.sessionId, tcc.conversational, tcc.agent, tcc.userId, tcc.userName, tcc.orgId, tcc.orgName) are recognized; any other tcc.* keys are ignored. None of them appear in your custom metadata.Adding user feedback
User feedback allows you to collect score (thumbs up & thumbs down) and text feedback (up to 2000 characters) from end users on your agent runs. This is useful for tracking user satisfaction, identifying problematic responses, and filtering agent runs in the dashboard to focus on positive or negative feedback.Step 1: Generate and pass a run ID
route.ts
Step 2: Submit feedback from your client
Store therunId on your client, then when the user provides feedback, submit it using the submitFeedback function.
Both score and text are optional individually, but each request must include at least one of them:
score is the thumbs rating. Use only "thumbs_up" or "thumbs_down".
text is written feedback from your user, up to 2000 characters.
feedback-route.ts
Tracking agent sessions
Agent sessions represent multiple agent runs that are grouped together. The most common use case is tracking entire conversations between a human user and an AI agent in chatbot interfaces. Agent sessions can be tracked by setting atcc.sessionId key under metadata.
route.ts
tcc.sessionId should be a unique identifier for the agent session. This can be any string, but it’s generally recommended to use a UUID.
Agent sessions are automatically indexed and can be filtered directly in the dashboard.
Marking runs as conversational
A conversational run is an agent run that was initiated by a user. Marking a run as conversational tells The Context Company that this run involves direct user interaction. This is important because conversational runs are the only runs monitored for user insights, such as user confusion, frustration, or any other custom insights you want to track. Runs that are not marked as conversational (e.g. background jobs, cron tasks, or internal automations) are excluded from user insight analysis. Mark a run as conversational by settingtcc.conversational to "true" in metadata:
route.ts
Identifying the agent
If your product ships more than one named agent, set the reservedtcc.agent metadata key to scope the run to a specific agent. The dashboard’s top-level agent selector, per-agent patterns and recaps, and the agent filter on the REST API and MCP tools all read from this key.
route.ts
Agent names that collide with reserved dashboard routes (for example
runs, sessions, patterns, recaps, overview, search, failures, feedback, tools, topics, views, settings, mcp-and-api) are dropped.Identifying users and organizations
Attach the end user and their organization to a run as first-class identity using the reservedtcc.userId, tcc.userName, tcc.orgId, and tcc.orgName metadata keys. This is not the same as adding a userId field to custom metadata — these keys promote user and org identity to dedicated dashboard filters and unlock native user/org search, per-user views, and per-org analytics. See User and organization identity for the full concept.
Set these whenever you have a stable identifier for the end user or their organization in your product.
route.ts
tcc.userName and tcc.orgName require the corresponding ID (tcc.userId / tcc.orgId) to also be set. Names without IDs are dropped.Debug mode
You can enable debug mode, which will log any spans that are created and exported.Examples
See our examples repository for more detailed usage examples. Examples currently include:Local mode
Local mode allows you to run The Context Company in a local-first mode. This is 100% open-source and requires no account or API key. We also offer a free, cloud development environment for all users.
Setup
Step 1: Install dependencies
Step 2: Add instrumentation to Next.js
If you haven’t already, add aninstrumentation.[js|ts] file in the root directory of your project (or inside the src folder if you’re using one). Call the registerOTelTCC function to instrument your AI SDK calls.
See the Next.js Instrumentation guide for more information on instrumenting your Next.js application.
instrumentation.ts
Step 3: Add widget to layout
Add the Local Mode widget to the root layout of your Next.js application.app/layout.tsx
Step 4: Enable telemetry for AI SDK calls
As of AI SDK v5, telemetry is experimental and requires theexperimental_telemetry flag to be set to true. Ensure you set this flag to true for all AI SDK calls.
Anonymous telemetry
By default, The Context Company collects limited anonymous usage data when running local mode. This helps us understand how developers use the tool and guides us in improving it. No sensitive or personally identifiable information is ever collected. You can view exactly which events and values are tracked here. To disable anonymous telemetry, set theTCC_DISABLE_ANONYMOUS_TELEMETRY environment variable to true in your Next.js project.