Dropping Traces
Conditionally dropping traces before they are sent to Confident AI
Overview
Dropping lets you skip tracing entirely for a request based on runtime conditions. Unlike sampling, which randomly drops a percentage of traces, this gives you full programmatic control over which requests are traced.
Drop a Trace
To drop a trace, wrap the request in a suppression scope before the work starts. Nothing inside the scope is recorded or exported — not your own spans, and not the auto-instrumented provider calls either.
from langchain_openai import ChatOpenAI
from confident_trace import init, suppress_tracing
init()
model = ChatOpenAI(model="gpt-4o")
def handle_request(query: str, is_internal: bool):
if is_internal:
with suppress_tracing():
return model.invoke(query) # this trace is dropped
return model.invoke(query) # this trace is sentimport { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { init, withTracingSuppressed } from "confident-trace";
init();
const llmApp = (query: string) =>
generateText({ model: openai("gpt-4o"), prompt: query });
const handleRequest = (query: string, isInternal: boolean) =>
isInternal
? withTracingSuppressed(() => llmApp(query)) // this trace is dropped
: llmApp(query); // this trace is sentRemember to launch your entry point with the Node preload so the Vercel AI SDK call is instrumented.
Suppression works for both sync and async code. Scopes are isolated across concurrent requests — suppressing one request never affects another running at the same time.
Next Steps
Dropping handles the traffic you never want to see. For everything else, control volume with sampling.
Sample Traces
Send only a percentage of traces to Confident AI to keep volume and cost under control in high-traffic apps.
Mask Sensitive Data
Redact PII and cap payload sizes before traces leave your process.
Last updated on