Choosing an AI SDK Observability Level

The Countly AI SDK measures every LLM call it tracks in the same way, but you decide how much of that detail leaves your application. The observabilityLevel setting controls it, from cost and token metrics only, up to previews of the prompts and responses themselves.

This article explains what each level sends, which privacy protections apply whatever level you choose, and how to pick and set the right level for your application.

Before you start

This article assumes you have already installed an AI SDK adapter and wrapped your AI client. The setting works the same way in every adapter: OpenAI, Anthropic, Google GenAI, Cohere, Vercel AI SDK, LangChain, Mastra, and LlamaIndex.

Understanding Observability Levels

There are three levels: 0, 1, and 2. Each level sends everything the level below it sends, plus more. The default is 0.

Levels decide what leaves your application, not what is measured. Token counts, cost, and latency are identical at every level, so moving between levels never changes your cost or usage figures. A higher level only adds detail on top.

Level Events Sent What Leaves Your Application
0 Metrics only (default) [CLY]_llm_interaction, one per generation Tokens, cost, latency, model, and status, plus the names and number of the tools each generation requested. No prompt text and no per-tool events.
1 Aggregate Adds [CLY]_llm_tool_used, one per tool or MCP call Each tool call's name, type, status, and latency, where the framework reports them
2 Full Adds [CLY]_llm_tool_usage_parameter, one per tool argument, and text previews on [CLY]_llm_interaction Tool argument values, and the start of prompts, responses, and reasoning text

You see tool names even at level 0. Which tools a generation asked for, and how many calls it asked for, is a non-sensitive fact about the call, so the tools_requested and tool_request_count fields stay on the interaction event at every level.

Latency traces and crash reports for LLM errors are switched on and off separately, with trackAPM and trackErrors.

What Level 2 Adds by Framework

At level 2, every adapter adds input and output previews (text_input_preview and text_output_preview) and a [CLY]_llm_tool_usage_parameter event per tool argument. Some adapters send more:

Adapter Also Sent at Level 2
Google GenAI Content-bearing metadata: groundingMetadata, citationMetadata, logprobsResult, and safetyRatings. At lower levels, only derived counts are sent, such as grounding_chunk_count, citation_count, safety_blocked_count, and avg_logprobs.
Cohere The model's toolPlan and thinking blocks, as the reasoning preview
Vercel AI SDK Reasoning text, as the reasoning preview
Mastra For each registered workflow step, one [CLY]_llm_tool_usage_parameter event per key of the step's inputData
Anthropic Nothing extra. Thinking text is not sent as a preview at any level.

Choosing a Level

We recommend starting at level 1. It adds per-tool analysis without sending any prompt or response text.

If You Want To Use Level
Track cost, tokens, latency, errors, and which tools models request 0
Also analyze individual tool calls: how often each tool runs, how long it takes, and how often it fails 1
Debug individual conversations, including what was asked, what was answered, and which arguments were passed to tools 2

Tool status and latency are only real where the framework reports them. The Vercel AI SDK, LangChain, LlamaIndex, and Mastra integrations report the actual outcome. With the OpenAI, Anthropic, Google GenAI, and Cohere adapters, your code runs the tool, so its status is recorded as unknown.

Use level 2 only when you need conversation-level debugging, and only where it is acceptable for prompt text to leave your application. Because the level is an ordinary configuration value, you can set it per environment, for example level 2 in staging and level 1 in production.

Understanding the Privacy Guarantees

Protections at Every Level

The following protections apply whatever level you choose:

  • No text at levels 0 and 1: prompt, response, and reasoning text is never sent below level 2.
  • Endpoint hostname only: the api_host field carries the hostname of the AI endpoint and nothing else. The path, query, and credentials are removed, because provider URLs often carry API keys and deployment IDs.
  • System and tool messages filtered: at level 2, previews leave out system prompts and tool messages.
  • Previews are truncated: only the first textPreviewLength characters are sent, 200 by default, with a hard maximum of 8192.
  • Tool arguments are capped: each value is cut at paramValueLength characters, 1024 by default, with a hard maximum of 8192. This cap also protects ingestion, since one oversized argument could otherwise cause its whole batch to fail.
  • Truncation is visible: each capped field has a matching state field, such as text_input_preview_state or param_value_state, set to complete or truncated. A truncated tool argument also carries its original length in param_value_length.
  • Data residency: on a self-hosted Countly Server, the data never leaves your infrastructure.

If you use Mastra, the adapter also supports Mastra's SensitiveDataFilter for automatic redaction.

Understanding the Server-Side Masking Gap

Level 2 data cannot be masked on the Server

Countly's server-side data masking does not currently cover the AI event fields. Text previews (text_input_preview and text_output_preview), tool argument values (param_value), and feedback comments stay unmasked even when masking is enabled.

Until this changes, treat level 2 as the point at which prompt text leaves your application, and keep it off wherever that is not acceptable.

Feedback comments are free-form text that your own code passes to feedback.track(). They fall under the same gap, so only send a comment if it is acceptable to store that text unmasked.

Setting the Observability Level

Setting the Level in Your Configuration

Every adapter accepts observabilityLevel in its configuration object, including the Mastra exporter and the Vercel AI SDK, LangChain, and LlamaIndex integrations.

import OpenAI from "openai";
import { observeOpenAI } from "@countly/ai-sdk-openai";

const openai = observeOpenAI(new OpenAI(), {
  appKey: "YOUR_APP_KEY",
  url: "https://your-countly-server.com",
  observabilityLevel: 1, // 0 = metrics only, 1 = + tool calls, 2 = + text previews
});

To use a different level per environment, derive the value from your own configuration:

observabilityLevel: process.env.NODE_ENV === "production" ? 1 : 2,

Adjusting Preview and Argument Lengths

At level 2, two settings control how much text is sent:

  • textPreviewLength: the maximum number of characters in each text preview. The default is 200.
  • paramValueLength: the maximum number of characters in each tool argument value. The default is 1024.

Neither can be raised above 8192. At levels 0 and 1, both settings have no effect, because no text or argument values are sent.

observeOpenAI(client, {
  appKey: "YOUR_APP_KEY",
  url: "https://your-countly-server.com",
  observabilityLevel: 2,
  textPreviewLength: 500,
  paramValueLength: 2048,
});

FAQ and Troubleshooting

Why Are My Text Previews Cut Off?

Previews are capped at textPreviewLength characters, 200 by default. A cut preview ends with an ellipsis (…) and its state field, such as text_output_preview_state, reads truncated. To see more, raise textPreviewLength, up to 8192.

Why Do My Previews Leave Out the System Prompt?

This is by design. System and tool messages are filtered out of previews, so only the conversation itself is sent.

Why Is There No Reasoning Preview for My Anthropic Calls?

The Anthropic adapter does not send thinking text as a preview, at any level. You still get the rest of the call, including its tokens and cost.

Related Resources

Was this page helpful?
Reach out to us for any other questions.
Helpful?

Looking For More Help?