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 npm run devRecording 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: "npm run dev" # 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 npm start
# Or simply don't set it at all
npm startYour 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:TuskDrift.initialize({ apiKey: process.env.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
- If unset: Falls back to
.tusk/config.yamland then the default base rate of1.0 - Precedence: This environment variable is overridden by the
samplingRateparameter inTuskDrift.initialize(), but takes precedence overrecording.sampling.base_rateand the legacyrecording.sampling_ratesetting in.tusk/config.yaml - Scope: This only overrides the base rate. It does not change
recording.sampling.modeorrecording.sampling.min_rate
Examples:
# Record all requests (100%)
TUSK_RECORDING_SAMPLING_RATE=1.0 npm start
# Record 10% of requests
TUSK_RECORDING_SAMPLING_RATE=0.1 npm startTUSK_SAMPLING_RATE is still accepted as a backward-compatible alias, but TUSK_RECORDING_SAMPLING_RATE is the canonical variable going forward.
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.
For more details on sampling rate configuration methods and precedence, see the Initialization Guide.
Controls whether adaptive sampling emits transition logs like Adaptive sampling updated (...).
- Type: Boolean (
true/false,1/0,yes/no,on/off) - If unset: Falls back to
recording.sampling.log_transitionsin.tusk/config.yaml, then defaults totrue - Precedence: Overrides
recording.sampling.log_transitions - Scope: Only affects adaptive sampling transition logs. It does not change recording decisions or the global SDK log level
Examples:
# Keep adaptive sampling active but silence transition logs
TUSK_RECORDING_SAMPLING_LOG_TRANSITIONS=false npm start
# Explicitly re-enable transition logs
TUSK_RECORDING_SAMPLING_LOG_TRANSITIONS=true npm startControl optional Rust-accelerated paths in the SDK. Truthy (1, true, yes, on) enables, falsy (0, false, no, off) disables. Enabled when unset.
Notes:
- The SDK is fail-open: if Rust bindings are unavailable or a Rust call fails, it falls back to JavaScript implementations.
- If Rust is enabled but bindings cannot be loaded, the SDK logs startup fallback and continues on JavaScript paths.
Example usage:
# Explicitly enable Rust path (also the default when unset)
TUSK_USE_RUST_CORE=1 npm start
# Explicitly disable Rust path
TUSK_USE_RUST_CORE=0 npm startThese are set automatically by the CLI when tusk drift run --coverage is used. You should not set them manually.
| Variable | Description |
|---|---|
NODE_V8_COVERAGE |
Directory for V8 to write coverage JSON files. Enables V8 precise coverage collection. |
TUSK_COVERAGE |
Language-agnostic signal that coverage is enabled. Set to true. |
TS_NODE_EMIT |
Forces ts-node to write compiled JS to disk (needed for coverage processing). Set to true. |
See Coverage Guide for details on how coverage collection works.
- Initialization Guide - SDK initialization parameters and config file settings
- Quick Start Guide - Record and replay your first trace
- Coverage Guide - Code coverage during test replay