@use-tusk/drift-node-sdk 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -16
- package/dist/index.cjs +261 -151
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +262 -152
- package/dist/index.js.map +1 -1
- package/package.json +17 -8
package/README.md
CHANGED
|
@@ -50,25 +50,26 @@ npm install @use-tusk/drift-node-sdk
|
|
|
50
50
|
Before setting up the SDK, ensure you have:
|
|
51
51
|
|
|
52
52
|
- Completed the [CLI wizard](https://github.com/Use-Tusk/tusk-drift-cli?tab=readme-ov-file#quick-start)
|
|
53
|
-
- Obtained an API key from the [Tusk Drift dashboard](https://usetusk.ai/app/settings/api-
|
|
53
|
+
- Obtained an API key from the [Tusk Drift dashboard](https://usetusk.ai/app/settings/api-keys) (only required if using Tusk Cloud)
|
|
54
54
|
|
|
55
55
|
Follow these steps in order to properly initialize the Tusk Drift SDK:
|
|
56
56
|
|
|
57
57
|
### 1. Create SDK Initialization File
|
|
58
58
|
|
|
59
|
-
Create a separate file (e.g. `
|
|
59
|
+
Create a separate file (e.g. `tuskDriftInit.ts`) to initialize the Tusk Drift SDK. This ensures the SDK is initialized as early as possible before any other modules are loaded.
|
|
60
|
+
|
|
61
|
+
**IMPORTANT**: Ensure that `TuskDrift` is initialized before any other telemetry providers (e.g. OpenTelemetry, Sentry, etc.). If not, your existing telemetry may not work properly.
|
|
60
62
|
|
|
61
63
|
#### For CommonJS Applications
|
|
62
64
|
|
|
63
65
|
```typescript
|
|
64
|
-
//
|
|
66
|
+
// tuskDriftInit.ts
|
|
65
67
|
import { TuskDrift } from "@use-tusk/drift-node-sdk";
|
|
66
68
|
|
|
67
69
|
// Initialize SDK immediately
|
|
68
70
|
TuskDrift.initialize({
|
|
69
71
|
apiKey: process.env.TUSK_DRIFT_API_KEY,
|
|
70
|
-
env: process.env.
|
|
71
|
-
logLevel: process.env.TUSK_DRIFT_LOG_LEVEL,
|
|
72
|
+
env: process.env.NODE_ENV,
|
|
72
73
|
});
|
|
73
74
|
|
|
74
75
|
export { TuskDrift };
|
|
@@ -79,7 +80,7 @@ export { TuskDrift };
|
|
|
79
80
|
ESM applications require additional setup to properly intercept module imports:
|
|
80
81
|
|
|
81
82
|
```typescript
|
|
82
|
-
//
|
|
83
|
+
// tuskDriftInit.ts
|
|
83
84
|
import { register } from 'node:module';
|
|
84
85
|
import { pathToFileURL } from 'node:url';
|
|
85
86
|
|
|
@@ -92,8 +93,7 @@ import { TuskDrift } from "@use-tusk/drift-node-sdk";
|
|
|
92
93
|
// Initialize SDK immediately
|
|
93
94
|
TuskDrift.initialize({
|
|
94
95
|
apiKey: process.env.TUSK_DRIFT_API_KEY,
|
|
95
|
-
env: process.env.
|
|
96
|
-
logLevel: process.env.TUSK_DRIFT_LOG_LEVEL,
|
|
96
|
+
env: process.env.NODE_ENV,
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
export { TuskDrift };
|
|
@@ -116,13 +116,13 @@ export { TuskDrift };
|
|
|
116
116
|
<tr>
|
|
117
117
|
<td><code>apiKey</code></td>
|
|
118
118
|
<td><code>string</code></td>
|
|
119
|
-
<td><b>Required
|
|
119
|
+
<td><b>Required if using Tusk Cloud</b></td>
|
|
120
120
|
<td>Your Tusk Drift API key.</td>
|
|
121
121
|
</tr>
|
|
122
122
|
<tr>
|
|
123
123
|
<td><code>env</code></td>
|
|
124
124
|
<td><code>string</code></td>
|
|
125
|
-
<td><
|
|
125
|
+
<td><code>process.env.NODE_ENV</code></td>
|
|
126
126
|
<td>The environment name.</td>
|
|
127
127
|
</tr>
|
|
128
128
|
<tr>
|
|
@@ -142,7 +142,7 @@ In your main server file (e.g., `server.ts`, `index.ts`, `app.ts`), require the
|
|
|
142
142
|
|
|
143
143
|
```typescript
|
|
144
144
|
// server.ts
|
|
145
|
-
import { TuskDrift } from "./
|
|
145
|
+
import { TuskDrift } from "./tuskDriftInit"; // MUST be the first import
|
|
146
146
|
|
|
147
147
|
// ... other imports ...
|
|
148
148
|
|
|
@@ -160,8 +160,8 @@ For ESM applications, you **cannot** control import order within your applicatio
|
|
|
160
160
|
```json
|
|
161
161
|
{
|
|
162
162
|
"scripts": {
|
|
163
|
-
"dev": "node --import ./dist/
|
|
164
|
-
"dev:record": "TUSK_DRIFT_MODE=RECORD node --import ./dist/
|
|
163
|
+
"dev": "node --import ./dist/tuskDriftInit.js dist/server.js",
|
|
164
|
+
"dev:record": "TUSK_DRIFT_MODE=RECORD node --import ./dist/tuskDriftInit.js dist/server.js"
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
```
|
|
@@ -214,13 +214,13 @@ recording:
|
|
|
214
214
|
</tbody>
|
|
215
215
|
</table>
|
|
216
216
|
|
|
217
|
-
###
|
|
217
|
+
### 4. Mark App as Ready
|
|
218
218
|
|
|
219
219
|
Once your application has completed initialization (database connections, middleware setup, etc.), mark it as ready:
|
|
220
220
|
|
|
221
221
|
```typescript
|
|
222
222
|
// server.ts
|
|
223
|
-
import { TuskDrift } from "./
|
|
223
|
+
import { TuskDrift } from "./tuskDriftInit";
|
|
224
224
|
|
|
225
225
|
// ... other imports ...
|
|
226
226
|
|
|
@@ -308,7 +308,11 @@ You should see output similar to:
|
|
|
308
308
|
|
|
309
309
|
1. **Check sampling rate**: Ensure `sampling_rate` in `.tusk/config.yaml` is 1.0
|
|
310
310
|
2. **Verify app readiness**: Make sure you're calling `TuskDrift.markAppAsReady()`
|
|
311
|
-
3. **
|
|
311
|
+
3. **Use debug mode in SDK**: Add `logLevel: 'debug'` to the initialization parameters
|
|
312
|
+
|
|
313
|
+
#### Existing telemetry not working
|
|
314
|
+
|
|
315
|
+
Ensure that `TuskDrift.initialize()` is called before any other telemetry providers (e.g. OpenTelemetry, Sentry, etc.).
|
|
312
316
|
|
|
313
317
|
#### Replay failures
|
|
314
318
|
|