@use-tusk/drift-node-sdk 0.1.10 → 0.1.11
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/dist/index.cjs +40 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +40 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -206,6 +206,7 @@ interface InitParams {
|
|
|
206
206
|
env?: string;
|
|
207
207
|
logLevel?: LogLevel;
|
|
208
208
|
transforms?: TransformConfigs;
|
|
209
|
+
samplingRate?: number;
|
|
209
210
|
}
|
|
210
211
|
interface TuskDriftPublicAPI {
|
|
211
212
|
/**
|
|
@@ -217,6 +218,7 @@ interface TuskDriftPublicAPI {
|
|
|
217
218
|
* - apiKey: string - Your TuskDrift API key (required)
|
|
218
219
|
* - env: string - The environment name (e.g., 'development', 'staging', 'production') (required)
|
|
219
220
|
* - logLevel?: LogLevel - Optional logging level ('silent' | 'error' | 'warn' | 'info' | 'debug'), defaults to 'info'
|
|
221
|
+
* - samplingRate?: number - Optional sampling rate (0.0-1.0) for recording requests. Overrides TUSK_SAMPLING_RATE env var and config.yaml. Defaults to 1.0
|
|
220
222
|
*
|
|
221
223
|
* @returns void - Initializes the SDK
|
|
222
224
|
*
|
|
@@ -227,7 +229,8 @@ interface TuskDriftPublicAPI {
|
|
|
227
229
|
* TuskDrift.initialize({
|
|
228
230
|
* apiKey: 'your-api-key',
|
|
229
231
|
* env: 'production',
|
|
230
|
-
* logLevel: 'debug'
|
|
232
|
+
* logLevel: 'debug',
|
|
233
|
+
* samplingRate: 1 // Record 100% of requests
|
|
231
234
|
* });
|
|
232
235
|
*
|
|
233
236
|
* ```
|
package/dist/index.d.ts
CHANGED
|
@@ -208,6 +208,7 @@ interface InitParams {
|
|
|
208
208
|
env?: string;
|
|
209
209
|
logLevel?: LogLevel;
|
|
210
210
|
transforms?: TransformConfigs;
|
|
211
|
+
samplingRate?: number;
|
|
211
212
|
}
|
|
212
213
|
interface TuskDriftPublicAPI {
|
|
213
214
|
/**
|
|
@@ -219,6 +220,7 @@ interface TuskDriftPublicAPI {
|
|
|
219
220
|
* - apiKey: string - Your TuskDrift API key (required)
|
|
220
221
|
* - env: string - The environment name (e.g., 'development', 'staging', 'production') (required)
|
|
221
222
|
* - logLevel?: LogLevel - Optional logging level ('silent' | 'error' | 'warn' | 'info' | 'debug'), defaults to 'info'
|
|
223
|
+
* - samplingRate?: number - Optional sampling rate (0.0-1.0) for recording requests. Overrides TUSK_SAMPLING_RATE env var and config.yaml. Defaults to 1.0
|
|
222
224
|
*
|
|
223
225
|
* @returns void - Initializes the SDK
|
|
224
226
|
*
|
|
@@ -229,7 +231,8 @@ interface TuskDriftPublicAPI {
|
|
|
229
231
|
* TuskDrift.initialize({
|
|
230
232
|
* apiKey: 'your-api-key',
|
|
231
233
|
* env: 'production',
|
|
232
|
-
* logLevel: 'debug'
|
|
234
|
+
* logLevel: 'debug',
|
|
235
|
+
* samplingRate: 1 // Record 100% of requests
|
|
233
236
|
* });
|
|
234
237
|
*
|
|
235
238
|
* ```
|
package/dist/index.js
CHANGED
|
@@ -208,17 +208,9 @@ function withTuskDrift(nextConfig = {}, options = {}) {
|
|
|
208
208
|
const originalExternals = webpackConfig.externals;
|
|
209
209
|
const coreExternals = ["require-in-the-middle", "jsonpath"];
|
|
210
210
|
const externalsMapping = {};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
for (const pkg of coreExternals) {
|
|
215
|
-
const pkgPath = __require("path").join(sdkNodeModules, pkg);
|
|
216
|
-
externalsMapping[pkg] = `commonjs ${pkgPath}`;
|
|
217
|
-
debugLog(debug, `Mapped external ${pkg} -> ${pkgPath}`);
|
|
218
|
-
}
|
|
219
|
-
} catch (e) {
|
|
220
|
-
warn(suppressAllWarnings || false, `Could not resolve SDK path, falling back to regular externals: ${e instanceof Error ? e.message : String(e)}`);
|
|
221
|
-
for (const pkg of coreExternals) externalsMapping[pkg] = `commonjs ${pkg}`;
|
|
211
|
+
for (const pkg of coreExternals) {
|
|
212
|
+
externalsMapping[pkg] = `commonjs ${pkg}`;
|
|
213
|
+
debugLog(debug, `Mapped external ${pkg} -> commonjs ${pkg}`);
|
|
222
214
|
}
|
|
223
215
|
if (!originalExternals) {
|
|
224
216
|
webpackConfig.externals = [externalsMapping];
|
|
@@ -264,7 +256,7 @@ var TdInstrumentationAbstract = class {
|
|
|
264
256
|
|
|
265
257
|
//#endregion
|
|
266
258
|
//#region package.json
|
|
267
|
-
var version = "0.1.
|
|
259
|
+
var version = "0.1.11";
|
|
268
260
|
|
|
269
261
|
//#endregion
|
|
270
262
|
//#region src/version.ts
|
|
@@ -12956,6 +12948,41 @@ var TuskDriftCore = class TuskDriftCore {
|
|
|
12956
12948
|
default: return TuskDriftMode.DISABLED;
|
|
12957
12949
|
}
|
|
12958
12950
|
}
|
|
12951
|
+
validateSamplingRate(value, source) {
|
|
12952
|
+
if (typeof value !== "number" || isNaN(value)) {
|
|
12953
|
+
logger.warn(`Invalid sampling rate from ${source}: not a number. Ignoring.`);
|
|
12954
|
+
return false;
|
|
12955
|
+
}
|
|
12956
|
+
if (value < 0 || value > 1) {
|
|
12957
|
+
logger.warn(`Invalid sampling rate from ${source}: ${value}. Must be between 0.0 and 1.0. Ignoring.`);
|
|
12958
|
+
return false;
|
|
12959
|
+
}
|
|
12960
|
+
return true;
|
|
12961
|
+
}
|
|
12962
|
+
determineSamplingRate(initParams) {
|
|
12963
|
+
if (initParams.samplingRate !== void 0) {
|
|
12964
|
+
if (this.validateSamplingRate(initParams.samplingRate, "init params")) {
|
|
12965
|
+
logger.debug(`Using sampling rate from init params: ${initParams.samplingRate}`);
|
|
12966
|
+
return initParams.samplingRate;
|
|
12967
|
+
}
|
|
12968
|
+
}
|
|
12969
|
+
const envSamplingRate = OriginalGlobalUtils.getOriginalProcessEnvVar("TUSK_SAMPLING_RATE");
|
|
12970
|
+
if (envSamplingRate !== void 0) {
|
|
12971
|
+
const parsed = parseFloat(envSamplingRate);
|
|
12972
|
+
if (this.validateSamplingRate(parsed, "TUSK_SAMPLING_RATE env var")) {
|
|
12973
|
+
logger.debug(`Using sampling rate from TUSK_SAMPLING_RATE env var: ${parsed}`);
|
|
12974
|
+
return parsed;
|
|
12975
|
+
}
|
|
12976
|
+
}
|
|
12977
|
+
if (this.config.recording?.sampling_rate !== void 0) {
|
|
12978
|
+
if (this.validateSamplingRate(this.config.recording.sampling_rate, "config.yaml")) {
|
|
12979
|
+
logger.debug(`Using sampling rate from config.yaml: ${this.config.recording.sampling_rate}`);
|
|
12980
|
+
return this.config.recording.sampling_rate;
|
|
12981
|
+
}
|
|
12982
|
+
}
|
|
12983
|
+
logger.debug("Using default sampling rate: 1.0");
|
|
12984
|
+
return 1;
|
|
12985
|
+
}
|
|
12959
12986
|
registerDefaultInstrumentations() {
|
|
12960
12987
|
const transforms = this.config.transforms ?? this.initParams.transforms;
|
|
12961
12988
|
new HttpInstrumentation({
|
|
@@ -13054,7 +13081,7 @@ var TuskDriftCore = class TuskDriftCore {
|
|
|
13054
13081
|
logLevel: initParams.logLevel || "info",
|
|
13055
13082
|
prefix: "TuskDrift"
|
|
13056
13083
|
});
|
|
13057
|
-
this.samplingRate = this.
|
|
13084
|
+
this.samplingRate = this.determineSamplingRate(initParams);
|
|
13058
13085
|
this.initParams = initParams;
|
|
13059
13086
|
if (!this.initParams.env) {
|
|
13060
13087
|
const nodeEnv = OriginalGlobalUtils.getOriginalProcessEnvVar("NODE_ENV") || "development";
|