You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/environment-variables.md
+11-6Lines changed: 11 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -110,24 +110,29 @@ Your Tusk Drift API key, required when using Tusk Cloud for storing and managing
110
110
111
111
This will securely store your auth key for future replay sessions.
112
112
113
-
## TUSK_SAMPLING_RATE
113
+
## TUSK_RECORDING_SAMPLING_RATE
114
114
115
-
Controls what percentage of requests are recorded during trace collection.
115
+
Controls the base recording rate used during trace collection.
116
116
117
117
-**Type:** Number between 0.0 and 1.0
118
-
-**Default:** 1.0 (100% of requests)
119
-
-**Precedence:** This environment variable is overridden by the `sampling_rate` parameter in `TuskDrift.initialize()`, but takes precedence over the `sampling_rate` setting in `.tusk/config.yaml`
118
+
-**If unset:** Falls back to `.tusk/config.yaml` and then the default base rate of `1.0`
119
+
-**Precedence:** This environment variable is overridden by the `sampling_rate` parameter in `TuskDrift.initialize()`, but takes precedence over `recording.sampling.base_rate` and the legacy `recording.sampling_rate` setting in `.tusk/config.yaml`
120
+
-**Scope:** This only overrides the base rate. It does not change `recording.sampling.mode` or `recording.sampling.min_rate`
120
121
121
122
**Examples:**
122
123
123
124
```bash
124
125
# Record all requests (100%)
125
-
TUSK_SAMPLING_RATE=1.0 python app.py
126
+
TUSK_RECORDING_SAMPLING_RATE=1.0 python app.py
126
127
127
128
# Record 10% of requests
128
-
TUSK_SAMPLING_RATE=0.1 python app.py
129
+
TUSK_RECORDING_SAMPLING_RATE=0.1 python app.py
129
130
```
130
131
132
+
If `recording.sampling.mode: adaptive` is enabled in `.tusk/config.yaml`, this environment variable still only changes the base rate; adaptive load shedding remains active.
133
+
134
+
`TUSK_RECORDING_SAMPLING_RATE` is the canonical variable, but `TUSK_SAMPLING_RATE` is still accepted as a backward-compatible alias.
135
+
131
136
For more details on sampling rate configuration methods and precedence, see the [Initialization Guide](./initialization.md#configure-sampling-rate).
Copy file name to clipboardExpand all lines: docs/initialization.md
+76-17Lines changed: 76 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,8 +73,8 @@ Create an initialization file or add the SDK initialization to your application
73
73
<tr>
74
74
<td><code>sampling_rate</code></td>
75
75
<td><code>float</code></td>
76
-
<td><code>1.0</code></td>
77
-
<td>Override sampling rate (0.0 - 1.0) for recording. Takes precedence over <code>TUSK_SAMPLING_RATE</code> env var and config file.</td>
76
+
<td><code>None</code></td>
77
+
<td>Override the base sampling rate (0.0 - 1.0) for recording. Takes precedence over <code>TUSK_RECORDING_SAMPLING_RATE</code> and config file base-rate settings. Does not change <code>recording.sampling.mode</code>.</td>
78
78
</tr>
79
79
</tbody>
80
80
</table>
@@ -172,50 +172,91 @@ if __name__ == "__main__":
172
172
173
173
## Configure Sampling Rate
174
174
175
-
The sampling rate determines what percentage of requests are recorded during replay tests. Tusk Drift supports three ways to configure the sampling rate, with the following precedence (highest to lowest):
175
+
Sampling controls what percentage of inbound requests are recorded in `RECORD` mode.
176
+
177
+
Tusk Drift supports two sampling modes in `.tusk/config.yaml`:
178
+
179
+
-`fixed`: record requests at a constant base rate.
180
+
-`adaptive`: start from a base rate and automatically shed load when queue pressure, export failures, or memory pressure indicate the SDK should back off. In severe conditions the SDK can temporarily pause recording entirely.
Set the sampling rate directly in your initialization code:
200
+
Set the base sampling rate directly in your initialization code:
186
201
187
202
```python
188
203
sdk = TuskDrift.initialize(
189
204
api_key=os.environ.get("TUSK_API_KEY"),
190
-
sampling_rate=0.1, # 10% of requests
205
+
sampling_rate=0.1, #Base rate: 10% of requests
191
206
)
192
207
```
193
208
194
209
### Method 2: Environment Variable
195
210
196
-
Set the `TUSK_SAMPLING_RATE` environment variable:
211
+
Set the `TUSK_RECORDING_SAMPLING_RATE` environment variable to override the base sampling rate:
197
212
198
213
```bash
199
214
# Development - record everything
200
-
TUSK_SAMPLING_RATE=1.0 python app.py
215
+
TUSK_RECORDING_SAMPLING_RATE=1.0 python app.py
201
216
202
217
# Production - sample 10% of requests
203
-
TUSK_SAMPLING_RATE=0.1 python app.py
218
+
TUSK_RECORDING_SAMPLING_RATE=0.1 python app.py
204
219
```
205
220
221
+
`TUSK_SAMPLING_RATE` is still supported as a backward-compatible alias, but new setups should prefer `TUSK_RECORDING_SAMPLING_RATE`.
222
+
206
223
### Method 3: Configuration File
207
224
208
-
Update the configuration file `.tusk/config.yaml` to include a `recording` section:
225
+
Use the nested `recording.sampling` config to choose `fixed` vs `adaptive` mode and set the base/minimum rates.
226
+
227
+
**Fixed sampling example:**
209
228
210
229
```yaml
211
230
# ... existing configuration ...
212
231
213
232
recording:
214
-
sampling_rate: 0.1
233
+
sampling:
234
+
mode: fixed
235
+
base_rate: 0.1
215
236
export_spans: true
216
237
enable_env_var_recording: true
217
238
```
218
239
240
+
**Adaptive sampling example:**
241
+
242
+
```yaml
243
+
# ... existing configuration ...
244
+
245
+
recording:
246
+
sampling:
247
+
mode: adaptive
248
+
base_rate: 0.25
249
+
min_rate: 0.01
250
+
export_spans: true
251
+
```
252
+
253
+
**Legacy config still supported:**
254
+
255
+
```yaml
256
+
recording:
257
+
sampling_rate: 0.1
258
+
```
259
+
219
260
### Recording Configuration Options
220
261
221
262
<table>
@@ -229,10 +270,28 @@ recording:
229
270
</thead>
230
271
<tbody>
231
272
<tr>
232
-
<td><code>sampling_rate</code></td>
273
+
<td><code>sampling.mode</code></td>
274
+
<td><code>"fixed" | "adaptive"</code></td>
275
+
<td><code>"fixed"</code></td>
276
+
<td>Selects constant sampling or adaptive load shedding.</td>
277
+
</tr>
278
+
<tr>
279
+
<td><code>sampling.base_rate</code></td>
233
280
<td><code>float</code></td>
234
281
<td><code>1.0</code></td>
235
-
<td>The sampling rate (0.0 - 1.0). 1.0 means 100% of requests are recorded, 0.0 means 0% of requests are recorded.</td>
282
+
<td>The base sampling rate (0.0 - 1.0). This is the preferred config key and can be overridden by <code>TUSK_RECORDING_SAMPLING_RATE</code> or the <code>sampling_rate</code> init parameter.</td>
283
+
</tr>
284
+
<tr>
285
+
<td><code>sampling.min_rate</code></td>
286
+
<td><code>float</code></td>
287
+
<td><code>0.001</code> in <code>adaptive</code> mode</td>
288
+
<td>The minimum steady-state sampling rate for adaptive mode. In critical conditions the SDK can still temporarily pause recording.</td>
289
+
</tr>
290
+
<tr>
291
+
<td><code>sampling_rate</code></td>
292
+
<td><code>float</code></td>
293
+
<td><code>None</code></td>
294
+
<td>Legacy fallback for the base sampling rate. Still supported for backward compatibility, but <code>recording.sampling.base_rate</code> is preferred.</td>
0 commit comments