Set a global sampling rate
This section is relevant for those using the LangSmith SDK or LangChain, not for those logging directly with the LangSmith API.
LANGSMITH_TRACING_SAMPLING_RATE environment variable to any float between 0 (no traces) and 1 (all traces). For instance, setting the following environment variable will log 75% of the traces.
traceable decorator and RunTree objects.
Set different sampling rates per client
You can also set sampling rates on specificClient instances and use the tracing_context context manager:
Sampling or conditional tracing
Sampling provides probabilistic control over trace volume, while conditional tracing provides deterministic control based on business logic. Use sampling when you want to reduce overall trace volume while maintaining statistical representation of your application’s behavior. Use conditional tracing when you need guaranteed tracing behavior for specific requests, such as:- Disabling tracing for clients with zero-retention policies.
- Routing traces to different projects based on tenant.
- Handling sensitive data that should never be traced.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.