Launch Week 3: Five days of launches

Trace Sampling

Sending only part of your traces to Confident AI

Included on the Enterprise plan. Book a demo, opens in a new tab. Included on the Team plan. Included on the Starter plan. Not included on the Free plan.

Overview

Sampling allows you to control what percentage of traces are sent to Confident's observatory.

Sampling is decided once, at the start of each trace. That means a trace is either fully exported or not at all — you'll never see half a trace in the Observatory.

For dropping based on conditions you discover during a request, see dropping traces.

Configure Sample Rate

Configure the sampling rate by setting the CONFIDENT_SAMPLE_RATE environment variable, which represents the proportion of traces that will be sent to the observatory. The value is a ratio between 0 and 1; the default 1.0 exports every trace.

export CONFIDENT_SAMPLE_RATE=0.5

Alternatively, you can set the sampling rate directly in code by passing sample_rate / sampleRate to init():

main.py
from openai import OpenAI
from confident_trace import init, span, shutdown

init(sample_rate=0.5)
client = OpenAI()

@span(type="agent")
def llm_app(query: str):
    return client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": query}]
    ).choices[0].message.content

try:
    for _ in range(10):
        llm_app("Write me a poem.")  # roughly half of these traces will be sent
finally:
    shutdown()

Next Steps

Sampling controls volume across the board. For finer control over individual requests, or over what's inside each trace, see:

Ready to monitor AI in production?Connect traces, alerts, dashboards, and evals in one production workflowBook a demo

Last updated on

Built byConfident AI