@use-tusk/drift-node-sdk 0.1.9 → 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 CHANGED
@@ -230,17 +230,9 @@ function withTuskDrift(nextConfig = {}, options = {}) {
230
230
  const originalExternals = webpackConfig.externals;
231
231
  const coreExternals = ["require-in-the-middle", "jsonpath"];
232
232
  const externalsMapping = {};
233
- try {
234
- const sdkPath = require.resolve("@use-tusk/drift-node-sdk");
235
- const sdkNodeModules = require("path").resolve(sdkPath, "../..", "node_modules");
236
- for (const pkg of coreExternals) {
237
- const pkgPath = require("path").join(sdkNodeModules, pkg);
238
- externalsMapping[pkg] = `commonjs ${pkgPath}`;
239
- debugLog(debug, `Mapped external ${pkg} -> ${pkgPath}`);
240
- }
241
- } catch (e) {
242
- warn(suppressAllWarnings || false, `Could not resolve SDK path, falling back to regular externals: ${e instanceof Error ? e.message : String(e)}`);
243
- for (const pkg of coreExternals) externalsMapping[pkg] = `commonjs ${pkg}`;
233
+ for (const pkg of coreExternals) {
234
+ externalsMapping[pkg] = `commonjs ${pkg}`;
235
+ debugLog(debug, `Mapped external ${pkg} -> commonjs ${pkg}`);
244
236
  }
245
237
  if (!originalExternals) {
246
238
  webpackConfig.externals = [externalsMapping];
@@ -286,7 +278,7 @@ var TdInstrumentationAbstract = class {
286
278
 
287
279
  //#endregion
288
280
  //#region package.json
289
- var version = "0.1.9";
281
+ var version = "0.1.11";
290
282
 
291
283
  //#endregion
292
284
  //#region src/version.ts
@@ -1228,6 +1220,7 @@ async function httpBodyEncoder({ bodyBuffer, contentEncoding }) {
1228
1220
  * @returns The corresponding DecodedType enum value
1229
1221
  */
1230
1222
  function getDecodedType(contentType) {
1223
+ if (!contentType) return;
1231
1224
  const contentTypeString = Array.isArray(contentType) && contentType.length > 0 ? contentType[0] : contentType;
1232
1225
  if (!contentTypeString || typeof contentTypeString !== "string") {
1233
1226
  logger.debug(`Invalid Content-Type header: ${contentType}`);
@@ -1236,22 +1229,7 @@ function getDecodedType(contentType) {
1236
1229
  const mainType = contentTypeString.toLowerCase().split(";")[0].trim();
1237
1230
  return CONTENT_TYPE_MAPPING[mainType];
1238
1231
  }
1239
- const STATIC_ASSET_TYPES = new Set([
1240
- __use_tusk_drift_schemas_core_json_schema.DecodedType.HTML,
1241
- __use_tusk_drift_schemas_core_json_schema.DecodedType.CSS,
1242
- __use_tusk_drift_schemas_core_json_schema.DecodedType.JAVASCRIPT,
1243
- __use_tusk_drift_schemas_core_json_schema.DecodedType.JPEG,
1244
- __use_tusk_drift_schemas_core_json_schema.DecodedType.PNG,
1245
- __use_tusk_drift_schemas_core_json_schema.DecodedType.GIF,
1246
- __use_tusk_drift_schemas_core_json_schema.DecodedType.WEBP,
1247
- __use_tusk_drift_schemas_core_json_schema.DecodedType.SVG,
1248
- __use_tusk_drift_schemas_core_json_schema.DecodedType.PDF,
1249
- __use_tusk_drift_schemas_core_json_schema.DecodedType.AUDIO,
1250
- __use_tusk_drift_schemas_core_json_schema.DecodedType.VIDEO,
1251
- __use_tusk_drift_schemas_core_json_schema.DecodedType.BINARY,
1252
- __use_tusk_drift_schemas_core_json_schema.DecodedType.ZIP,
1253
- __use_tusk_drift_schemas_core_json_schema.DecodedType.GZIP
1254
- ]);
1232
+ const ACCEPTABLE_CONTENT_TYPES = new Set([__use_tusk_drift_schemas_core_json_schema.DecodedType.JSON, __use_tusk_drift_schemas_core_json_schema.DecodedType.PLAIN_TEXT]);
1255
1233
 
1256
1234
  //#endregion
1257
1235
  //#region src/instrumentation/libraries/http/mocks/TdHttpMockSocket.ts
@@ -2831,9 +2809,9 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
2831
2809
  } : { code: __opentelemetry_api.SpanStatusCode.OK };
2832
2810
  SpanUtils.setStatus(spanInfo.span, status);
2833
2811
  const decodedType = getDecodedType(outputValue.headers?.["content-type"] || "");
2834
- if (decodedType && STATIC_ASSET_TYPES.has(decodedType)) {
2812
+ if (decodedType && !ACCEPTABLE_CONTENT_TYPES.has(decodedType)) {
2835
2813
  TraceBlockingManager.getInstance().blockTrace(spanInfo.traceId);
2836
- logger.debug(`[HttpInstrumentation] Blocking trace ${spanInfo.traceId} because it is an static asset response. Decoded type: ${decodedType}`);
2814
+ logger.debug(`[HttpInstrumentation] Blocking trace ${spanInfo.traceId} because it is not an acceptable decoded type: ${decodedType}`, { acceptableContentTypes: Array.from(ACCEPTABLE_CONTENT_TYPES) });
2837
2815
  }
2838
2816
  SpanUtils.endSpan(spanInfo.span);
2839
2817
  } catch (error) {
@@ -9821,9 +9799,9 @@ var NextjsInstrumentation = class extends TdInstrumentationBase {
9821
9799
  } : { code: __opentelemetry_api.SpanStatusCode.OK };
9822
9800
  SpanUtils.setStatus(spanInfo.span, status);
9823
9801
  const decodedType = getDecodedType(outputValue.headers?.["content-type"] || "");
9824
- if (decodedType && STATIC_ASSET_TYPES.has(decodedType)) {
9802
+ if (decodedType && !ACCEPTABLE_CONTENT_TYPES.has(decodedType)) {
9825
9803
  TraceBlockingManager.getInstance().blockTrace(spanInfo.traceId);
9826
- logger.debug(`[NextjsInstrumentation] Blocking trace ${spanInfo.traceId} because it is an static asset response. Decoded type: ${decodedType}`);
9804
+ logger.debug(`[NextjsInstrumentation] Blocking trace ${spanInfo.traceId} because it is not an acceptable decoded type: ${decodedType}`, { acceptableContentTypes: Array.from(ACCEPTABLE_CONTENT_TYPES) });
9827
9805
  }
9828
9806
  SpanUtils.endSpan(spanInfo.span);
9829
9807
  if (self.mode === TuskDriftMode.REPLAY) try {
@@ -12992,6 +12970,41 @@ var TuskDriftCore = class TuskDriftCore {
12992
12970
  default: return TuskDriftMode.DISABLED;
12993
12971
  }
12994
12972
  }
12973
+ validateSamplingRate(value, source) {
12974
+ if (typeof value !== "number" || isNaN(value)) {
12975
+ logger.warn(`Invalid sampling rate from ${source}: not a number. Ignoring.`);
12976
+ return false;
12977
+ }
12978
+ if (value < 0 || value > 1) {
12979
+ logger.warn(`Invalid sampling rate from ${source}: ${value}. Must be between 0.0 and 1.0. Ignoring.`);
12980
+ return false;
12981
+ }
12982
+ return true;
12983
+ }
12984
+ determineSamplingRate(initParams) {
12985
+ if (initParams.samplingRate !== void 0) {
12986
+ if (this.validateSamplingRate(initParams.samplingRate, "init params")) {
12987
+ logger.debug(`Using sampling rate from init params: ${initParams.samplingRate}`);
12988
+ return initParams.samplingRate;
12989
+ }
12990
+ }
12991
+ const envSamplingRate = OriginalGlobalUtils.getOriginalProcessEnvVar("TUSK_SAMPLING_RATE");
12992
+ if (envSamplingRate !== void 0) {
12993
+ const parsed = parseFloat(envSamplingRate);
12994
+ if (this.validateSamplingRate(parsed, "TUSK_SAMPLING_RATE env var")) {
12995
+ logger.debug(`Using sampling rate from TUSK_SAMPLING_RATE env var: ${parsed}`);
12996
+ return parsed;
12997
+ }
12998
+ }
12999
+ if (this.config.recording?.sampling_rate !== void 0) {
13000
+ if (this.validateSamplingRate(this.config.recording.sampling_rate, "config.yaml")) {
13001
+ logger.debug(`Using sampling rate from config.yaml: ${this.config.recording.sampling_rate}`);
13002
+ return this.config.recording.sampling_rate;
13003
+ }
13004
+ }
13005
+ logger.debug("Using default sampling rate: 1.0");
13006
+ return 1;
13007
+ }
12995
13008
  registerDefaultInstrumentations() {
12996
13009
  const transforms = this.config.transforms ?? this.initParams.transforms;
12997
13010
  new HttpInstrumentation({
@@ -13090,7 +13103,7 @@ var TuskDriftCore = class TuskDriftCore {
13090
13103
  logLevel: initParams.logLevel || "info",
13091
13104
  prefix: "TuskDrift"
13092
13105
  });
13093
- this.samplingRate = this.config.recording?.sampling_rate ?? 1;
13106
+ this.samplingRate = this.determineSamplingRate(initParams);
13094
13107
  this.initParams = initParams;
13095
13108
  if (!this.initParams.env) {
13096
13109
  const nodeEnv = OriginalGlobalUtils.getOriginalProcessEnvVar("NODE_ENV") || "development";