This guide covers the environment variables that can be set when using the Tusk Drift SDK.
The TUSK_DRIFT_MODE environment variable controls how the SDK operates in your application.
| Mode | Description | When to Use |
|---|---|---|
RECORD |
Records traces for all instrumented operations | Set this in environments where you want to capture API traces (e.g., staging, production) |
REPLAY |
Replays previously recorded traces | Automatically set by the Tusk CLI when running tusk drift run - you should NOT set this manually |
DISABLED |
Disables all instrumentation and recording | Use when you want to completely disable Tusk with no performance impact |
| Unset | Same as DISABLED - no instrumentation or recording |
Default state when the variable is not set |
Recording Traces:
- Set
TUSK_DRIFT_MODE=RECORDin any environment where you want to record traces - This is typically staging, production, or local development environments
- Traces will be saved according to your
recordingconfiguration in.tusk/config.yaml
Replaying Traces:
TUSK_DRIFT_MODEis automatically set toREPLAYby the Tusk CLI when you runtusk drift run- Do NOT manually set
TUSK_DRIFT_MODE=REPLAYin your application startup commands - The start command specified in your
.tusk/config.yamlshould NOT causeTUSK_DRIFT_MODEto be set to anything - the CLI handles this automatically
Disabling Tusk:
- If
TUSK_DRIFT_MODEis unset or set toDISABLED, the SDK will not add any instrumentation - No data will be recorded and there should be no performance impact
- This is useful for environments where you don't need Tusk functionality
Recording in development:
TUSK_DRIFT_MODE=RECORD python app.pyRecording in production (via environment variable):
# In your .env file or deployment configuration
TUSK_DRIFT_MODE=RECORDStart command in config.yaml (correct):
# .tusk/config.yaml
start_command: "python app.py" # Do NOT include TUSK_DRIFT_MODE hereReplaying traces (handled by CLI):
# The CLI automatically sets TUSK_DRIFT_MODE=REPLAY
tusk drift runDisabling Tusk:
# Either unset the variable or explicitly disable
TUSK_DRIFT_MODE=DISABLED python app.py
# Or simply don't set it at all
python app.pyYour Tusk Drift API key, required when using Tusk Cloud for storing and managing traces.
- Required: Only if using Tusk Cloud (not needed for local-only trace storage)
- Where to get it: Tusk Drift Dashboard
For Recording:
-
Must be provided in the
TuskDrift.initialize()call:sdk = TuskDrift.initialize( api_key=os.environ.get("TUSK_API_KEY"), # or hard-coded for non-production # ... other options )
For Replay:
-
Can be set as an environment variable:
TUSK_API_KEY=your-api-key-here tusk drift run
-
Or use the Tusk CLI login command (recommended):
tusk auth login
This will securely store your auth key for future replay sessions.
Controls what percentage of requests are recorded during trace collection.
- Type: Number between 0.0 and 1.0
- Default: 1.0 (100% of requests)
- Precedence: This environment variable is overridden by the
sampling_rateparameter inTuskDrift.initialize(), but takes precedence over thesampling_ratesetting in.tusk/config.yaml
Examples:
# Record all requests (100%)
TUSK_SAMPLING_RATE=1.0 python app.py
# Record 10% of requests
TUSK_SAMPLING_RATE=0.1 python app.pyFor more details on sampling rate configuration methods and precedence, see the Initialization Guide.
These variables control optional Rust-accelerated paths in the SDK.
| Variable | Description | Default |
|---|---|---|
TUSK_USE_RUST_CORE |
Controls Rust binding usage. Truthy (1, true, yes, on) enables, falsy (0, false, no, off) disables. |
Enabled when unset |
TUSK_SKIP_PROTO_VALIDATION |
Skips expensive protobuf validation in hot path (1, true, yes) |
0 (disabled) |
Notes:
- The SDK is fail-open: if Rust bindings are unavailable or a Rust call fails, it falls back to Python implementation.
TUSK_USE_RUST_COREdefaults to enabled when unset.TUSK_USE_RUST_COREdoes not install Rust bindings automatically. Thedrift-core-pythonpackage still must be installed in your environment.- If Rust is enabled but bindings cannot be loaded, the SDK logs startup fallback and continues on Python paths.
TUSK_SKIP_PROTO_VALIDATIONis performance-focused and should be used with confidence in parity tests and serialization correctness.
See rust-core-bindings.md for more details.
Example usage:
# Explicitly enable Rust path (also the default when unset)
TUSK_USE_RUST_CORE=1 python app.py
# Explicitly disable Rust path
TUSK_USE_RUST_CORE=0 python app.py
# Enable Rust path and skip proto validation
TUSK_USE_RUST_CORE=1 TUSK_SKIP_PROTO_VALIDATION=1 python app.pyThese variables configure how the SDK connects to the Tusk CLI during replay:
| Variable | Description | Default |
|---|---|---|
TUSK_MOCK_HOST |
CLI host for TCP connection | - |
TUSK_MOCK_PORT |
CLI port for TCP connection | - |
TUSK_MOCK_SOCKET |
Unix socket path for CLI connection | /tmp/tusk-connect.sock |
These are typically set automatically by the Tusk CLI and do not need to be configured manually.
- Initialization Guide - SDK initialization parameters and config file settings
- Quick Start Guide - Record and replay your first trace