Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: add tracing_context sampling rate docs
  • Loading branch information
victorm-lc committed Aug 19, 2025
commit aee71627031fa5d6bef25ae9c886c74b8ae7b59a
30 changes: 30 additions & 0 deletions docs/observability/how_to_guides/sample_traces.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ sidebar_position: 4
This section is relevant for those using the LangSmith SDK or LangChain, not for those logging directly with the LangSmith API.
:::

## Set global sampling rate

By default, all traces are logged to LangSmith.
To down-sample the number of traces logged to LangSmith, set the `LANGSMITH_TRACING_SAMPLING_RATE` environment variable to
any float between `0` (no traces) and `1` (all traces).
Expand All @@ -18,3 +20,31 @@ export LANGSMITH_TRACING_SAMPLING_RATE=0.75
```

This works for the `traceable` decorator and `RunTree` objects.

## Setting different sampling rates per client

You can also set sampling rates on specific `Client` instances and using the `tracing_context` context manager:

```python
from langsmith import Client, tracing_context

# Create clients with different sampling rates
client_1 = Client(tracing_sampling_rate=0.5) # 50% sampling
client_2 = Client(tracing_sampling_rate=0.25) # 25% sampling
client_no_trace = Client(tracing_sampling_rate=0.0) # No tracing

# Use different sampling rates for different operations
with tracing_context(client=client_1):
# Your code here - will be traced with 50% sampling rate
agent_1.invoke(...)

with tracing_context(client=client_2):
# Your code here - will be traced with 25% sampling rate
agent_1.invoke(...)

with tracing_context(client=client_no_trace):
# Your code here - will not be traced
agent_1.invoke(...)
```

This allows you to control sampling rates at the operation level.
Loading