Next.js support is currently in beta. Reach out to Support if you have questions.
1. Configure Next.js with withTuskDrift
Wrap your Next.js configuration with the withTuskDrift
function in your next.config.js
or next.config.ts
file:
Basic Configuration
With Debug Logging for Next.js Integration
What withTuskDrift
Does
The withTuskDrift
wrapper automatically:
- Enables the Next.js instrumentation hook (for Next.js < 15.0.0-rc.1)
- Configures webpack externals for proper module interception
- Detects your Next.js version and adjusts configuration accordingly
- Preserves your existing Next.js configuration
Configuration Options
Option | Type | Default | Description |
---|---|---|---|
debug | boolean | false | Enable debug logging to see what Tusk Drift is configuring during build. |
disableInstrumentationHook | boolean | false | Disable automatic setting of experimental.instrumentationHook . Not recommended, will break Tusk Drift’s Next.js integration. |
suppressWarnings | boolean | false | Suppress all warnings from Tusk Drift’s Next.js integration. |
2. Create instrumentation file
Create aninstrumentation.ts
(or .js
) file at the root of your Next.js project, at the same level as next.config.js
:
Initialization Parameters
Option | Type | Default | Description |
---|---|---|---|
apiKey | string | Required if using Tusk Cloud | Your Tusk Drift API key from the dashboard. |
env | string | process.env.NODE_ENV | The environment name (e.g., ‘dev’, ‘staging’, ‘production’). |
logLevel | ’silent’ | ‘error’ | ‘warn’ | ‘info’ | ‘debug' | 'info’ | The logging level for the Tusk Drift SDK. |
3. Update recording configurations
Update the.tusk/config.yaml
file in your project root to include recording configuration:
Configuration Options
Option | Type | Default | Description |
---|---|---|---|
sampling_rate | number | 1.0 | The sampling rate (0.0 - 1.0). 1.0 means 100% of requests are recorded, 0.0 means no requests are recorded. |
export_spans | boolean | false | Whether to export spans to the Tusk backend. If false, spans are only saved locally in .tusk/traces . |
enable_env_var_recording | boolean | false | Whether to record and replay environment variables. Recommended for accurate replay behavior if your app’s logic depends on environment variables. |
Troubleshooting
Instrumentation not working
If your packages aren’t being instrumented:-
Check file location: Ensure
instrumentation.ts
is at the project root (same level asnext.config.js
), not in theapp
orpages
directory. -
Check runtime guard: Make sure you have the
NEXT_RUNTIME === 'nodejs'
check in yourregister()
function. -
Enable debug logging: Set
debug: true
in yourwithTuskDrift
options to see what’s being configured.