-
Notifications
You must be signed in to change notification settings - Fork 0
docs: better docs #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| # Environment Variables | ||
|
|
||
| This guide covers the environment variables that can be set when using the Tusk Drift SDK. | ||
|
|
||
| ## TUSK_DRIFT_MODE | ||
|
|
||
| The `TUSK_DRIFT_MODE` environment variable controls how the SDK operates in your application. | ||
|
|
||
| ### Available Modes | ||
|
|
||
| | 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 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 | | ||
|
|
||
| ### Important Notes | ||
|
|
||
| **Recording Traces:** | ||
|
|
||
| - Set `TUSK_DRIFT_MODE=RECORD` in any environment where you want to record traces | ||
| - This is typically staging, production, or local development environments | ||
| - Traces will be saved according to your `recording` configuration in `.tusk/config.yaml` | ||
|
|
||
| **Replaying Traces:** | ||
|
|
||
| - `TUSK_DRIFT_MODE` is automatically set to `REPLAY` by the Tusk CLI when you run `tusk run` | ||
| - **Do NOT** manually set `TUSK_DRIFT_MODE=REPLAY` in your application startup commands | ||
| - The start command specified in your `.tusk/config.yaml` should NOT cause `TUSK_DRIFT_MODE` to be set to anything - the CLI handles this automatically | ||
|
|
||
| **Disabling Tusk:** | ||
|
|
||
| - If `TUSK_DRIFT_MODE` is unset or set to `DISABLED`, 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 | ||
|
|
||
| ### Examples | ||
|
|
||
| **Recording in development:** | ||
|
|
||
| ```bash | ||
| TUSK_DRIFT_MODE=RECORD python app.py | ||
| ``` | ||
|
|
||
| **Recording in production (via environment variable):** | ||
|
|
||
| ```bash | ||
| # In your .env file or deployment configuration | ||
| TUSK_DRIFT_MODE=RECORD | ||
| ``` | ||
|
|
||
| **Start command in config.yaml (correct):** | ||
|
|
||
| ```yaml | ||
| # .tusk/config.yaml | ||
| start_command: "python app.py" # Do NOT include TUSK_DRIFT_MODE here | ||
| ``` | ||
|
|
||
| **Replaying traces (handled by CLI):** | ||
|
|
||
| ```bash | ||
| # The CLI automatically sets TUSK_DRIFT_MODE=REPLAY | ||
| tusk run | ||
| ``` | ||
|
|
||
| **Disabling Tusk:** | ||
|
|
||
| ```bash | ||
| # Either unset the variable or explicitly disable | ||
| TUSK_DRIFT_MODE=DISABLED python app.py | ||
|
|
||
| # Or simply don't set it at all | ||
| python app.py | ||
| ``` | ||
|
|
||
| ## TUSK_API_KEY | ||
|
|
||
| Your 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](https://usetusk.ai/app/settings/api-keys) | ||
|
|
||
| ### How to Set | ||
|
|
||
| **For Recording:** | ||
|
|
||
| - Must be provided in the `TuskDrift.initialize()` call: | ||
|
|
||
| ```python | ||
| 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: | ||
|
|
||
| ```bash | ||
| TUSK_API_KEY=your-api-key-here tusk run | ||
| ``` | ||
|
|
||
| - Or use the Tusk CLI login command (recommended): | ||
|
|
||
| ```bash | ||
| tusk auth login | ||
| ``` | ||
|
|
||
| This will securely store your auth key for future replay sessions. | ||
|
|
||
| ## TUSK_SAMPLING_RATE | ||
|
|
||
| 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_rate` parameter in `TuskDrift.initialize()`, but takes precedence over the `sampling_rate` setting in `.tusk/config.yaml` | ||
|
|
||
| **Examples:** | ||
|
|
||
| ```bash | ||
| # Record all requests (100%) | ||
| TUSK_SAMPLING_RATE=1.0 python app.py | ||
|
|
||
| # Record 10% of requests | ||
| TUSK_SAMPLING_RATE=0.1 python app.py | ||
| ``` | ||
|
|
||
| For more details on sampling rate configuration methods and precedence, see the [Initialization Guide](./initialization.md#configure-sampling-rate). | ||
|
|
||
| ## Connection Variables | ||
|
|
||
| These 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. | ||
|
|
||
| --- | ||
|
|
||
| ## Related Documentation | ||
|
|
||
| - [Initialization Guide](./initialization.md) - SDK initialization parameters and config file settings | ||
| - [Quick Start Guide](./quickstart.md) - Record and replay your first trace |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.