@use-tusk/drift-node-sdk 0.1.21 → 0.1.23

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
@@ -11150,13 +11150,23 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11150
11150
  let requestOptions;
11151
11151
  if (typeof args[0] === "string") {
11152
11152
  const url = new URL(args[0]);
11153
+ const additionalOptions = typeof args[1] === "function" ? void 0 : args[1];
11153
11154
  requestOptions = {
11154
11155
  protocol: url.protocol,
11155
11156
  hostname: url.hostname,
11156
11157
  port: url.port ? parseInt(url.port) : void 0,
11157
11158
  path: url.pathname + url.search,
11158
- method: args[1]?.method || "GET",
11159
- headers: args[1]?.headers || {}
11159
+ method: additionalOptions?.method || "GET",
11160
+ headers: additionalOptions?.headers || {}
11161
+ };
11162
+ } else if (self._isURLObject(args[0])) {
11163
+ const url = args[0];
11164
+ const additionalOptions = typeof args[1] === "function" ? void 0 : args[1];
11165
+ requestOptions = {
11166
+ ...self._urlToRequestOptions(url),
11167
+ method: additionalOptions?.method || "GET",
11168
+ headers: additionalOptions?.headers || {},
11169
+ ...additionalOptions
11160
11170
  };
11161
11171
  } else requestOptions = args[0] || {};
11162
11172
  const method = requestOptions.method || "GET";
@@ -11246,12 +11256,21 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11246
11256
  let requestOptions;
11247
11257
  if (typeof args[0] === "string") {
11248
11258
  const url = new URL(args[0]);
11259
+ const additionalOptions = typeof args[1] === "function" ? void 0 : args[1];
11249
11260
  requestOptions = {
11250
11261
  protocol: url.protocol,
11251
11262
  hostname: url.hostname,
11252
11263
  port: url.port ? parseInt(url.port) : void 0,
11253
11264
  path: url.pathname + url.search,
11254
- headers: args[1]?.headers || {}
11265
+ headers: additionalOptions?.headers || {}
11266
+ };
11267
+ } else if (self._isURLObject(args[0])) {
11268
+ const url = args[0];
11269
+ const additionalOptions = typeof args[1] === "function" ? void 0 : args[1];
11270
+ requestOptions = {
11271
+ ...self._urlToRequestOptions(url),
11272
+ headers: additionalOptions?.headers || {},
11273
+ ...additionalOptions
11255
11274
  };
11256
11275
  } else requestOptions = args[0] || {};
11257
11276
  const method = "GET";
@@ -11357,6 +11376,25 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11357
11376
  };
11358
11377
  };
11359
11378
  }
11379
+ /**
11380
+ * Check if the input is a URL object (WHATWG URL API)
11381
+ * This is used to detect when a URL object is passed to http.get/request
11382
+ */
11383
+ _isURLObject(input) {
11384
+ return input instanceof URL || input && typeof input.href === "string" && typeof input.pathname === "string";
11385
+ }
11386
+ /**
11387
+ * Convert a URL object to RequestOptions
11388
+ * Similar to Node.js's internal urlToHttpOptions function
11389
+ */
11390
+ _urlToRequestOptions(url) {
11391
+ return {
11392
+ protocol: url.protocol,
11393
+ hostname: url.hostname,
11394
+ port: url.port ? parseInt(url.port) : void 0,
11395
+ path: url.pathname + (url.search || "")
11396
+ };
11397
+ }
11360
11398
  _normalizeProtocol(protocol, fallback) {
11361
11399
  if (!protocol) return fallback;
11362
11400
  const normalized = protocol.toLowerCase().replace(/:$/, "");
@@ -11734,6 +11772,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11734
11772
  packageName,
11735
11773
  instrumentationName: self.INSTRUMENTATION_NAME,
11736
11774
  inputValue,
11775
+ inputSchemaMerges: { values: { matchImportance: 0 } },
11737
11776
  isPreAppStart: false
11738
11777
  }, (spanInfo) => {
11739
11778
  return self.handleReplayQuery(queryConfig, inputValue, spanInfo, stackTrace);
@@ -11753,6 +11792,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11753
11792
  instrumentationName: self.INSTRUMENTATION_NAME,
11754
11793
  packageName,
11755
11794
  inputValue,
11795
+ inputSchemaMerges: { values: { matchImportance: 0 } },
11756
11796
  isPreAppStart
11757
11797
  }, (spanInfo) => {
11758
11798
  return self._handleRecordQueryInSpan(spanInfo, originalQuery, queryConfig, args, this);
@@ -11929,7 +11969,8 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11929
11969
  kind: import_src$29.SpanKind.CLIENT,
11930
11970
  stackTrace
11931
11971
  },
11932
- tuskDrift: this.tuskDrift
11972
+ tuskDrift: this.tuskDrift,
11973
+ inputValueSchemaMerges: { values: { matchImportance: 0 } }
11933
11974
  });
11934
11975
  if (!mockData) {
11935
11976
  const queryText = queryConfig.text || inputValue.text || "UNKNOWN_QUERY";
@@ -12792,6 +12833,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12792
12833
  packageName: "postgres",
12793
12834
  instrumentationName: self.INSTRUMENTATION_NAME,
12794
12835
  inputValue,
12836
+ inputSchemaMerges: { parameters: { matchImportance: 0 } },
12795
12837
  isPreAppStart
12796
12838
  }, (spanInfo) => {
12797
12839
  const wrappedOnFulfilled = (result) => {
@@ -12839,6 +12881,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12839
12881
  packageName: "postgres",
12840
12882
  instrumentationName: self.INSTRUMENTATION_NAME,
12841
12883
  inputValue,
12884
+ inputSchemaMerges: { parameters: { matchImportance: 0 } },
12842
12885
  isPreAppStart: self.tuskDrift.isAppReady() ? false : true
12843
12886
  }, async (spanInfo) => {
12844
12887
  const mockedResult = await self._handleReplayQueryOperation({
@@ -13041,7 +13084,8 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
13041
13084
  kind: import_src$27.SpanKind.CLIENT,
13042
13085
  stackTrace
13043
13086
  },
13044
- tuskDrift: this.tuskDrift
13087
+ tuskDrift: this.tuskDrift,
13088
+ inputValueSchemaMerges: { parameters: { matchImportance: 0 } }
13045
13089
  });
13046
13090
  }
13047
13091
  /**
@@ -13095,6 +13139,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
13095
13139
  packageName: "postgres",
13096
13140
  instrumentationName: self.INSTRUMENTATION_NAME,
13097
13141
  inputValue,
13142
+ inputSchemaMerges: { parameters: { matchImportance: 0 } },
13098
13143
  isPreAppStart
13099
13144
  }, (spanInfo) => {
13100
13145
  return self._executeAndRecordCursorCallback({
@@ -13153,6 +13198,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
13153
13198
  packageName: "postgres",
13154
13199
  instrumentationName: self.INSTRUMENTATION_NAME,
13155
13200
  inputValue,
13201
+ inputSchemaMerges: { parameters: { matchImportance: 0 } },
13156
13202
  isPreAppStart: self.tuskDrift.isAppReady() ? false : true
13157
13203
  }, async (spanInfo) => {
13158
13204
  try {
@@ -13354,6 +13400,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
13354
13400
  packageName: "postgres",
13355
13401
  instrumentationName: self.INSTRUMENTATION_NAME,
13356
13402
  inputValue,
13403
+ inputSchemaMerges: { parameters: { matchImportance: 0 } },
13357
13404
  isPreAppStart
13358
13405
  }, async (spanInfo) => {
13359
13406
  const allRows = [];
@@ -13408,6 +13455,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
13408
13455
  packageName: "postgres",
13409
13456
  instrumentationName: self.INSTRUMENTATION_NAME,
13410
13457
  inputValue,
13458
+ inputSchemaMerges: { parameters: { matchImportance: 0 } },
13411
13459
  isPreAppStart: self.tuskDrift.isAppReady() ? false : true
13412
13460
  }, async (spanInfo) => {
13413
13461
  try {
@@ -13462,6 +13510,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
13462
13510
  packageName: "postgres",
13463
13511
  instrumentationName: self.INSTRUMENTATION_NAME,
13464
13512
  inputValue,
13513
+ inputSchemaMerges: { parameters: { matchImportance: 0 } },
13465
13514
  isPreAppStart
13466
13515
  }, (spanInfo) => {
13467
13516
  const wrappedOnFulfilled = (result) => {
@@ -13509,6 +13558,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
13509
13558
  packageName: "postgres",
13510
13559
  instrumentationName: self.INSTRUMENTATION_NAME,
13511
13560
  inputValue,
13561
+ inputSchemaMerges: { parameters: { matchImportance: 0 } },
13512
13562
  isPreAppStart: self.tuskDrift.isAppReady() ? false : true
13513
13563
  }, async (spanInfo) => {
13514
13564
  const mockedResult = await self._handleReplayQueryOperation({
@@ -13908,7 +13958,8 @@ var TdMysqlQueryMock = class {
13908
13958
  kind: import_src$26.SpanKind.CLIENT,
13909
13959
  stackTrace
13910
13960
  },
13911
- tuskDrift: this.tuskDrift
13961
+ tuskDrift: this.tuskDrift,
13962
+ inputValueSchemaMerges: { values: { matchImportance: 0 } }
13912
13963
  });
13913
13964
  }
13914
13965
  };
@@ -14164,6 +14215,7 @@ var MysqlInstrumentation = class extends TdInstrumentationBase {
14164
14215
  packageName: "mysql",
14165
14216
  instrumentationName: self.INSTRUMENTATION_NAME,
14166
14217
  inputValue,
14218
+ inputSchemaMerges: { values: { matchImportance: 0 } },
14167
14219
  isPreAppStart: false
14168
14220
  }, (spanInfo) => {
14169
14221
  const queryEmitter = self.queryMock.handleReplayQuery({
@@ -14190,6 +14242,7 @@ var MysqlInstrumentation = class extends TdInstrumentationBase {
14190
14242
  packageName: "mysql",
14191
14243
  instrumentationName: self.INSTRUMENTATION_NAME,
14192
14244
  inputValue,
14245
+ inputSchemaMerges: { values: { matchImportance: 0 } },
14193
14246
  isPreAppStart
14194
14247
  }, (spanInfo) => {
14195
14248
  return self._handleRecordQuery(spanInfo, originalQuery, this, args, callback, isEventEmitterMode);
@@ -14212,11 +14265,13 @@ var MysqlInstrumentation = class extends TdInstrumentationBase {
14212
14265
  const connectionContext = this;
14213
14266
  return handleReplayMode({
14214
14267
  noOpRequestHandler: () => {
14268
+ connectionContext.state = "authenticated";
14215
14269
  if (callback) setImmediate(() => callback(null));
14216
14270
  setImmediate(() => connectionContext.emit("connect"));
14217
14271
  },
14218
14272
  isServerRequest: false,
14219
14273
  replayModeHandler: () => {
14274
+ connectionContext.state = "authenticated";
14220
14275
  if (callback) setImmediate(() => callback(null));
14221
14276
  setImmediate(() => connectionContext.emit("connect"));
14222
14277
  }
@@ -14637,6 +14692,7 @@ var MysqlInstrumentation = class extends TdInstrumentationBase {
14637
14692
  packageName: "mysql",
14638
14693
  instrumentationName: self.INSTRUMENTATION_NAME,
14639
14694
  inputValue,
14695
+ inputSchemaMerges: { values: { matchImportance: 0 } },
14640
14696
  isPreAppStart: false
14641
14697
  }, (spanInfo) => {
14642
14698
  const queryEmitter = self.queryMock.handleReplayQuery({
@@ -14663,6 +14719,7 @@ var MysqlInstrumentation = class extends TdInstrumentationBase {
14663
14719
  packageName: "mysql",
14664
14720
  instrumentationName: self.INSTRUMENTATION_NAME,
14665
14721
  inputValue,
14722
+ inputSchemaMerges: { values: { matchImportance: 0 } },
14666
14723
  isPreAppStart
14667
14724
  }, (spanInfo) => {
14668
14725
  return self._handleRecordQuery(spanInfo, originalQuery, connection, args, callback, isEventEmitterMode);
@@ -14782,10 +14839,12 @@ var MysqlInstrumentation = class extends TdInstrumentationBase {
14782
14839
  return function connect(callback) {
14783
14840
  if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
14784
14841
  noOpRequestHandler: () => {
14842
+ connection.state = "authenticated";
14785
14843
  if (callback) setImmediate(() => callback(null));
14786
14844
  },
14787
14845
  isServerRequest: false,
14788
14846
  replayModeHandler: () => {
14847
+ connection.state = "authenticated";
14789
14848
  if (callback) setImmediate(() => callback(null));
14790
14849
  }
14791
14850
  });
@@ -15124,6 +15183,7 @@ var MysqlInstrumentation = class extends TdInstrumentationBase {
15124
15183
  packageName: "mysql",
15125
15184
  instrumentationName: self.INSTRUMENTATION_NAME,
15126
15185
  inputValue,
15186
+ inputSchemaMerges: { values: { matchImportance: 0 } },
15127
15187
  isPreAppStart: false
15128
15188
  }, (spanInfo) => {
15129
15189
  return self._handleReplayStream(inputValue, spanInfo, stackTrace, queryInstance);
@@ -15141,6 +15201,7 @@ var MysqlInstrumentation = class extends TdInstrumentationBase {
15141
15201
  packageName: "mysql",
15142
15202
  instrumentationName: self.INSTRUMENTATION_NAME,
15143
15203
  inputValue,
15204
+ inputSchemaMerges: { values: { matchImportance: 0 } },
15144
15205
  isPreAppStart
15145
15206
  }, (spanInfo) => {
15146
15207
  return self._handleRecordStream(spanInfo, originalStream, queryInstance, streamOptions);
@@ -15352,6 +15413,7 @@ var MysqlInstrumentation = class extends TdInstrumentationBase {
15352
15413
  packageName: "mysql",
15353
15414
  instrumentationName: self.INSTRUMENTATION_NAME,
15354
15415
  inputValue,
15416
+ inputSchemaMerges: { values: { matchImportance: 0 } },
15355
15417
  isPreAppStart: false
15356
15418
  }, (spanInfo) => {
15357
15419
  const queryEmitter = self.queryMock.handleReplayQuery({
@@ -15547,6 +15609,27 @@ var TdMysql2ConnectionMock = class extends events.EventEmitter {
15547
15609
  }
15548
15610
  return Promise.resolve();
15549
15611
  }
15612
+ prepare(sql, callback) {
15613
+ const sqlStr = typeof sql === "string" ? sql : sql.sql;
15614
+ const self = this;
15615
+ const mockStatement = {
15616
+ query: sqlStr,
15617
+ id: 1,
15618
+ columns: [],
15619
+ parameters: [],
15620
+ execute: (...args) => {
15621
+ const values = Array.isArray(args[0]) ? args[0] : [];
15622
+ const execCallback = typeof args[args.length - 1] === "function" ? args[args.length - 1] : void 0;
15623
+ return self.mysql2Instrumentation.handleNoOpReplayQuery({
15624
+ sql: sqlStr,
15625
+ values,
15626
+ callback: execCallback
15627
+ });
15628
+ },
15629
+ close: () => {}
15630
+ };
15631
+ if (callback) process.nextTick(() => callback(null, mockStatement));
15632
+ }
15550
15633
  pause() {}
15551
15634
  resume() {}
15552
15635
  escape(value) {
@@ -15603,6 +15686,10 @@ var TdMysql2QueryMock = class {
15603
15686
  });
15604
15687
  }).then(onResolve, onReject);
15605
15688
  };
15689
+ const self = this;
15690
+ emitter.stream = function(streamOptions) {
15691
+ return self._createReplayStreamForQuery(emitter, streamOptions);
15692
+ };
15606
15693
  process.nextTick(() => {
15607
15694
  const callback = queryConfig.callback;
15608
15695
  if (callback) callback(null, [], []);
@@ -15629,6 +15716,10 @@ var TdMysql2QueryMock = class {
15629
15716
  });
15630
15717
  }).then(onResolve, onReject);
15631
15718
  };
15719
+ const self = this;
15720
+ emitter.stream = function(streamOptions) {
15721
+ return self._createReplayStreamForQuery(emitter, streamOptions);
15722
+ };
15632
15723
  (async () => {
15633
15724
  try {
15634
15725
  const mockData = await this._fetchMockData(inputValue, spanInfo, spanName, submoduleName, stackTrace);
@@ -15672,8 +15763,46 @@ var TdMysql2QueryMock = class {
15672
15763
  kind: import_src$24.SpanKind.CLIENT,
15673
15764
  stackTrace
15674
15765
  },
15675
- tuskDrift: this.tuskDrift
15766
+ tuskDrift: this.tuskDrift,
15767
+ inputValueSchemaMerges: { values: { matchImportance: 0 } }
15768
+ });
15769
+ }
15770
+ /**
15771
+ * Create a replay stream for query.stream() calls
15772
+ * This is called when user calls query.stream() on a query object
15773
+ */
15774
+ _createReplayStreamForQuery(queryEmitter, streamOptions) {
15775
+ logger.debug(`[Mysql2Instrumentation] Creating replay stream for query.stream()`);
15776
+ const readableStream = new stream.Readable({
15777
+ objectMode: true,
15778
+ read() {}
15779
+ });
15780
+ queryEmitter.on("result", (row) => {
15781
+ readableStream.push(row);
15782
+ });
15783
+ queryEmitter.on("error", (err) => {
15784
+ readableStream.destroy(err);
15785
+ });
15786
+ queryEmitter.on("end", () => {
15787
+ readableStream.push(null);
15676
15788
  });
15789
+ return readableStream;
15790
+ }
15791
+ /**
15792
+ * Recursively restore Buffer objects from their JSON serialized form.
15793
+ * JSON.stringify converts Buffer to {"type":"Buffer","data":[...]}
15794
+ * This function converts them back to actual Buffer instances.
15795
+ */
15796
+ _restoreBuffers(obj) {
15797
+ if (obj === null || obj === void 0) return obj;
15798
+ if (typeof obj === "object" && obj.type === "Buffer" && Array.isArray(obj.data)) return Buffer.from(obj.data);
15799
+ if (Array.isArray(obj)) return obj.map((item) => this._restoreBuffers(item));
15800
+ if (typeof obj === "object") {
15801
+ const result = {};
15802
+ for (const key of Object.keys(obj)) result[key] = this._restoreBuffers(obj[key]);
15803
+ return result;
15804
+ }
15805
+ return obj;
15677
15806
  }
15678
15807
  /**
15679
15808
  * Convert stored MySQL2 values back to appropriate JavaScript types
@@ -15683,12 +15812,17 @@ var TdMysql2QueryMock = class {
15683
15812
  rows: [],
15684
15813
  fields: []
15685
15814
  };
15686
- if (result.rows !== void 0 && result.fields !== void 0) return {
15687
- rows: result.rows,
15688
- fields: result.fields
15815
+ const restoredResult = this._restoreBuffers(result);
15816
+ if (restoredResult.rows !== void 0 && restoredResult.fields !== void 0) return {
15817
+ rows: restoredResult.rows,
15818
+ fields: restoredResult.fields
15819
+ };
15820
+ if (restoredResult.affectedRows !== void 0) return {
15821
+ rows: restoredResult,
15822
+ fields: []
15689
15823
  };
15690
15824
  return {
15691
- rows: result,
15825
+ rows: restoredResult,
15692
15826
  fields: []
15693
15827
  };
15694
15828
  }
@@ -15833,6 +15967,18 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
15833
15967
  logger.debug(`[Mysql2Instrumentation] Wrapped BaseConnection.prototype.end`);
15834
15968
  }
15835
15969
  }
15970
+ if (BaseConnectionClass.prototype && BaseConnectionClass.prototype.prepare) {
15971
+ if (!isWrapped$1(BaseConnectionClass.prototype.prepare)) {
15972
+ this._wrap(BaseConnectionClass.prototype, "prepare", this._getPreparePatchFn("connection"));
15973
+ logger.debug(`[Mysql2Instrumentation] Wrapped BaseConnection.prototype.prepare`);
15974
+ }
15975
+ }
15976
+ if (BaseConnectionClass.prototype && BaseConnectionClass.prototype.changeUser) {
15977
+ if (!isWrapped$1(BaseConnectionClass.prototype.changeUser)) {
15978
+ this._wrap(BaseConnectionClass.prototype, "changeUser", this._getChangeUserPatchFn("connection"));
15979
+ logger.debug(`[Mysql2Instrumentation] Wrapped BaseConnection.prototype.changeUser`);
15980
+ }
15981
+ }
15836
15982
  this.markModuleAsPatched(BaseConnectionClass);
15837
15983
  logger.debug(`[Mysql2Instrumentation] BaseConnection class patching complete`);
15838
15984
  return BaseConnectionClass;
@@ -15884,6 +16030,18 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
15884
16030
  logger.debug(`[Mysql2Instrumentation] Wrapped Connection.prototype.end`);
15885
16031
  }
15886
16032
  }
16033
+ if (ConnectionClass.prototype && ConnectionClass.prototype.prepare) {
16034
+ if (!isWrapped$1(ConnectionClass.prototype.prepare)) {
16035
+ this._wrap(ConnectionClass.prototype, "prepare", this._getPreparePatchFn("connection"));
16036
+ logger.debug(`[Mysql2Instrumentation] Wrapped Connection.prototype.prepare`);
16037
+ }
16038
+ }
16039
+ if (ConnectionClass.prototype && ConnectionClass.prototype.changeUser) {
16040
+ if (!isWrapped$1(ConnectionClass.prototype.changeUser)) {
16041
+ this._wrap(ConnectionClass.prototype, "changeUser", this._getChangeUserPatchFn("connection"));
16042
+ logger.debug(`[Mysql2Instrumentation] Wrapped Connection.prototype.changeUser`);
16043
+ }
16044
+ }
15887
16045
  }
15888
16046
  _patchPoolV2(PoolClass) {
15889
16047
  logger.debug(`[Mysql2Instrumentation] Patching Pool class (v2)`);
@@ -15977,6 +16135,7 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
15977
16135
  packageName: "mysql2",
15978
16136
  instrumentationName: self.INSTRUMENTATION_NAME,
15979
16137
  inputValue,
16138
+ inputSchemaMerges: { values: { matchImportance: 0 } },
15980
16139
  isPreAppStart: false
15981
16140
  }, (spanInfo) => {
15982
16141
  return self.handleReplayQuery(queryConfig, inputValue, spanInfo, "query", stackTrace);
@@ -15995,6 +16154,7 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
15995
16154
  instrumentationName: self.INSTRUMENTATION_NAME,
15996
16155
  packageName: "mysql2",
15997
16156
  inputValue,
16157
+ inputSchemaMerges: { values: { matchImportance: 0 } },
15998
16158
  isPreAppStart
15999
16159
  }, (spanInfo) => {
16000
16160
  return self._handleRecordQueryInSpan(spanInfo, originalQuery, queryConfig, args, this);
@@ -16042,6 +16202,7 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
16042
16202
  packageName: "mysql2",
16043
16203
  instrumentationName: self.INSTRUMENTATION_NAME,
16044
16204
  inputValue,
16205
+ inputSchemaMerges: { values: { matchImportance: 0 } },
16045
16206
  isPreAppStart: false
16046
16207
  }, (spanInfo) => {
16047
16208
  return self.handleReplayQuery(queryConfig, inputValue, spanInfo, "execute", stackTrace);
@@ -16060,6 +16221,7 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
16060
16221
  instrumentationName: self.INSTRUMENTATION_NAME,
16061
16222
  packageName: "mysql2",
16062
16223
  inputValue,
16224
+ inputSchemaMerges: { values: { matchImportance: 0 } },
16063
16225
  isPreAppStart
16064
16226
  }, (spanInfo) => {
16065
16227
  return self._handleRecordQueryInSpan(spanInfo, originalExecute, queryConfig, args, this);
@@ -16283,6 +16445,251 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
16283
16445
  };
16284
16446
  };
16285
16447
  }
16448
+ _getChangeUserPatchFn(clientType) {
16449
+ const self = this;
16450
+ return (originalChangeUser) => {
16451
+ return function changeUser(options, callback) {
16452
+ if (typeof options === "function") {
16453
+ callback = options;
16454
+ options = {};
16455
+ }
16456
+ const inputValue = { clientType };
16457
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
16458
+ noOpRequestHandler: () => {
16459
+ if (callback) {
16460
+ process.nextTick(() => callback(null));
16461
+ return;
16462
+ }
16463
+ return Promise.resolve();
16464
+ },
16465
+ isServerRequest: false,
16466
+ replayModeHandler: () => {
16467
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalChangeUser.apply(this, [options, callback]), {
16468
+ name: `mysql2.${clientType}.changeUser`,
16469
+ kind: import_src$22.SpanKind.CLIENT,
16470
+ submodule: "changeUser",
16471
+ packageName: "mysql2",
16472
+ packageType: PackageType.MYSQL,
16473
+ instrumentationName: self.INSTRUMENTATION_NAME,
16474
+ inputValue,
16475
+ isPreAppStart: false
16476
+ }, (spanInfo) => {
16477
+ if (callback) {
16478
+ process.nextTick(() => callback(null));
16479
+ return;
16480
+ }
16481
+ return Promise.resolve();
16482
+ });
16483
+ }
16484
+ });
16485
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
16486
+ originalFunctionCall: () => originalChangeUser.apply(this, [options, callback]),
16487
+ recordModeHandler: ({ isPreAppStart }) => {
16488
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalChangeUser.apply(this, [options, callback]), {
16489
+ name: `mysql2.${clientType}.changeUser`,
16490
+ kind: import_src$22.SpanKind.CLIENT,
16491
+ submodule: "changeUser",
16492
+ packageName: "mysql2",
16493
+ packageType: PackageType.MYSQL,
16494
+ instrumentationName: self.INSTRUMENTATION_NAME,
16495
+ inputValue,
16496
+ isPreAppStart
16497
+ }, (spanInfo) => {
16498
+ return self._handleSimpleCallbackMethod(spanInfo, originalChangeUser.bind(this, options), callback, this);
16499
+ });
16500
+ },
16501
+ spanKind: import_src$22.SpanKind.CLIENT
16502
+ });
16503
+ else return originalChangeUser.apply(this, [options, callback]);
16504
+ };
16505
+ };
16506
+ }
16507
+ _getPreparePatchFn(clientType) {
16508
+ const self = this;
16509
+ return (originalPrepare) => {
16510
+ return function prepare(...args) {
16511
+ const firstArg = args[0];
16512
+ const sql = typeof firstArg === "string" ? firstArg : firstArg?.sql;
16513
+ const originalCallback = typeof args[args.length - 1] === "function" ? args[args.length - 1] : void 0;
16514
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
16515
+ noOpRequestHandler: () => self._handleNoOpReplayPrepare(sql, originalCallback),
16516
+ isServerRequest: false,
16517
+ replayModeHandler: () => self._handleReplayPrepare(sql, originalCallback, clientType)
16518
+ });
16519
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
16520
+ originalFunctionCall: () => originalPrepare.apply(this, args),
16521
+ recordModeHandler: ({ isPreAppStart }) => self._handleRecordPrepare(originalPrepare, args, sql, originalCallback, this, clientType, isPreAppStart),
16522
+ spanKind: import_src$22.SpanKind.CLIENT
16523
+ });
16524
+ return originalPrepare.apply(this, args);
16525
+ };
16526
+ };
16527
+ }
16528
+ _handleRecordPrepare(originalPrepare, args, sql, originalCallback, context$6, clientType, isPreAppStart) {
16529
+ const self = this;
16530
+ return SpanUtils.createAndExecuteSpan(this.mode, () => originalPrepare.apply(context$6, args), {
16531
+ name: `mysql2.${clientType}.prepare`,
16532
+ kind: import_src$22.SpanKind.CLIENT,
16533
+ submodule: "prepare",
16534
+ packageType: PackageType.MYSQL,
16535
+ packageName: "mysql2",
16536
+ instrumentationName: this.INSTRUMENTATION_NAME,
16537
+ inputValue: {
16538
+ sql,
16539
+ clientType
16540
+ },
16541
+ isPreAppStart
16542
+ }, (spanInfo) => {
16543
+ const wrappedCallback = (err, statement) => {
16544
+ if (err) {
16545
+ logger.debug(`[Mysql2Instrumentation] MySQL2 prepare error: ${err.message} (${SpanUtils.getTraceInfo()})`);
16546
+ try {
16547
+ SpanUtils.endSpan(spanInfo.span, {
16548
+ code: import_src$22.SpanStatusCode.ERROR,
16549
+ message: err.message
16550
+ });
16551
+ } catch (error) {
16552
+ logger.error(`[Mysql2Instrumentation] error ending span:`, error);
16553
+ }
16554
+ } else {
16555
+ logger.debug(`[Mysql2Instrumentation] MySQL2 prepare completed successfully (${SpanUtils.getTraceInfo()})`);
16556
+ try {
16557
+ SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: {
16558
+ prepared: true,
16559
+ statementId: statement?.id
16560
+ } });
16561
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$22.SpanStatusCode.OK });
16562
+ } catch (error) {
16563
+ logger.error(`[Mysql2Instrumentation] error processing prepare response:`, error);
16564
+ }
16565
+ if (statement && statement.execute) {
16566
+ const originalExecute = statement.execute.bind(statement);
16567
+ statement.execute = self._getPreparedStatementExecuteWrapper(originalExecute, sql, clientType);
16568
+ }
16569
+ }
16570
+ if (originalCallback) originalCallback(err, statement);
16571
+ };
16572
+ const newArgs = [...args];
16573
+ const callbackIndex = newArgs.findIndex((a) => typeof a === "function");
16574
+ if (callbackIndex >= 0) newArgs[callbackIndex] = wrappedCallback;
16575
+ else newArgs.push(wrappedCallback);
16576
+ return originalPrepare.apply(context$6, newArgs);
16577
+ });
16578
+ }
16579
+ _getPreparedStatementExecuteWrapper(originalExecute, sql, clientType) {
16580
+ const self = this;
16581
+ return function execute(...args) {
16582
+ let values = [];
16583
+ let callback;
16584
+ for (const arg of args) if (typeof arg === "function") callback = arg;
16585
+ else if (Array.isArray(arg)) values = arg;
16586
+ else if (arg !== void 0) values = [arg];
16587
+ const inputValue = {
16588
+ sql,
16589
+ values,
16590
+ clientType
16591
+ };
16592
+ const queryConfig = {
16593
+ sql,
16594
+ values,
16595
+ callback
16596
+ };
16597
+ const stackTrace = captureStackTrace(["Mysql2Instrumentation"]);
16598
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
16599
+ noOpRequestHandler: () => self.queryMock.handleNoOpReplayQuery(queryConfig),
16600
+ isServerRequest: false,
16601
+ replayModeHandler: () => {
16602
+ const spanName = `mysql2.${clientType}.preparedExecute`;
16603
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalExecute(...args), {
16604
+ name: spanName,
16605
+ kind: import_src$22.SpanKind.CLIENT,
16606
+ submodule: "preparedExecute",
16607
+ packageType: PackageType.MYSQL,
16608
+ packageName: "mysql2",
16609
+ instrumentationName: self.INSTRUMENTATION_NAME,
16610
+ inputValue,
16611
+ inputSchemaMerges: { values: { matchImportance: 0 } },
16612
+ isPreAppStart: false
16613
+ }, (spanInfo) => {
16614
+ return self.handleReplayQuery(queryConfig, inputValue, spanInfo, "preparedExecute", stackTrace);
16615
+ });
16616
+ }
16617
+ });
16618
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
16619
+ originalFunctionCall: () => originalExecute(...args),
16620
+ recordModeHandler: ({ isPreAppStart }) => {
16621
+ const spanName = `mysql2.${clientType}.preparedExecute`;
16622
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalExecute(...args), {
16623
+ name: spanName,
16624
+ kind: import_src$22.SpanKind.CLIENT,
16625
+ submodule: "preparedExecute",
16626
+ packageType: PackageType.MYSQL,
16627
+ packageName: "mysql2",
16628
+ instrumentationName: self.INSTRUMENTATION_NAME,
16629
+ inputValue,
16630
+ inputSchemaMerges: { values: { matchImportance: 0 } },
16631
+ isPreAppStart
16632
+ }, (spanInfo) => {
16633
+ return self._handleRecordQueryInSpan(spanInfo, originalExecute, queryConfig, args, void 0);
16634
+ });
16635
+ },
16636
+ spanKind: import_src$22.SpanKind.CLIENT
16637
+ });
16638
+ return originalExecute(...args);
16639
+ };
16640
+ }
16641
+ _handleReplayPrepare(sql, originalCallback, clientType) {
16642
+ const self = this;
16643
+ return SpanUtils.createAndExecuteSpan(this.mode, () => {}, {
16644
+ name: `mysql2.${clientType}.prepare`,
16645
+ kind: import_src$22.SpanKind.CLIENT,
16646
+ submodule: "prepare",
16647
+ packageType: PackageType.MYSQL,
16648
+ packageName: "mysql2",
16649
+ instrumentationName: this.INSTRUMENTATION_NAME,
16650
+ inputValue: {
16651
+ sql,
16652
+ clientType
16653
+ },
16654
+ isPreAppStart: false
16655
+ }, (spanInfo) => {
16656
+ const mockStatement = {
16657
+ query: sql,
16658
+ id: 1,
16659
+ columns: [],
16660
+ parameters: [],
16661
+ execute: self._getPreparedStatementExecuteWrapper(() => {}, sql, clientType),
16662
+ close: () => {}
16663
+ };
16664
+ try {
16665
+ SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: { prepared: true } });
16666
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$22.SpanStatusCode.OK });
16667
+ } catch (error) {
16668
+ logger.error(`[Mysql2Instrumentation] error ending prepare span:`, error);
16669
+ }
16670
+ if (originalCallback) process.nextTick(() => originalCallback(null, mockStatement));
16671
+ });
16672
+ }
16673
+ _handleNoOpReplayPrepare(sql, originalCallback) {
16674
+ const self = this;
16675
+ const mockStatement = {
16676
+ query: sql,
16677
+ id: 1,
16678
+ columns: [],
16679
+ parameters: [],
16680
+ execute: (...args) => {
16681
+ const values = Array.isArray(args[0]) ? args[0] : [];
16682
+ const callback = typeof args[args.length - 1] === "function" ? args[args.length - 1] : void 0;
16683
+ return self.queryMock.handleNoOpReplayQuery({
16684
+ sql,
16685
+ values,
16686
+ callback
16687
+ });
16688
+ },
16689
+ close: () => {}
16690
+ };
16691
+ if (originalCallback) process.nextTick(() => originalCallback(null, mockStatement));
16692
+ }
16286
16693
  _handleSimpleCallbackMethod(spanInfo, originalMethod, callback, context$6) {
16287
16694
  if (callback) {
16288
16695
  const wrappedCallback = (error) => {
@@ -16354,15 +16761,29 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
16354
16761
  else if (args.length > 1 && typeof args[1] !== "function") config.values = [args[1]];
16355
16762
  return config;
16356
16763
  }
16357
- if (typeof firstArg === "object" && firstArg.sql) return {
16358
- sql: firstArg.sql,
16359
- values: firstArg.values,
16360
- callback: firstArg.callback || (typeof args[1] === "function" ? args[1] : void 0)
16361
- };
16764
+ if (typeof firstArg === "object" && firstArg.sql) {
16765
+ let values = firstArg.values;
16766
+ let callback = firstArg.callback;
16767
+ if (typeof args[1] === "function") callback = args[1];
16768
+ else {
16769
+ if (args[1] !== void 0) values = Array.isArray(args[1]) ? args[1] : [args[1]];
16770
+ if (typeof args[2] === "function") callback = args[2];
16771
+ }
16772
+ return {
16773
+ sql: firstArg.sql,
16774
+ values,
16775
+ callback
16776
+ };
16777
+ }
16362
16778
  return null;
16363
16779
  }
16364
16780
  _handleRecordQueryInSpan(spanInfo, originalQuery, queryConfig, args, context$6) {
16365
- if (!!queryConfig.callback) {
16781
+ const hasCallback = !!queryConfig.callback;
16782
+ const invokeOriginal = (invokeArgs) => {
16783
+ return context$6 ? originalQuery.apply(context$6, invokeArgs) : originalQuery(...invokeArgs);
16784
+ };
16785
+ if (hasCallback) {
16786
+ const parentContext = import_src$22.context.active();
16366
16787
  const originalCallback = queryConfig.callback;
16367
16788
  const wrappedCallback = (error, results, fields) => {
16368
16789
  if (error) {
@@ -16384,7 +16805,7 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
16384
16805
  logger.error(`[Mysql2Instrumentation] error processing response:`, error$1);
16385
16806
  }
16386
16807
  }
16387
- return originalCallback(error, results, fields);
16808
+ return import_src$22.context.with(parentContext, () => originalCallback(error, results, fields));
16388
16809
  };
16389
16810
  try {
16390
16811
  const firstArg = args[0];
@@ -16399,9 +16820,9 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
16399
16820
  } catch (error) {
16400
16821
  logger.error(`[Mysql2Instrumentation] error replacing callback:`, error, args);
16401
16822
  }
16402
- return originalQuery.apply(context$6, args);
16823
+ return invokeOriginal(args);
16403
16824
  } else {
16404
- const result = originalQuery.apply(context$6, args);
16825
+ const result = invokeOriginal(args);
16405
16826
  if (result && typeof result.on === "function") {
16406
16827
  const streamResults = [];
16407
16828
  let streamFields = null;
@@ -16607,6 +17028,34 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
16607
17028
  if (event === "error" && !this._isConnectOrErrorEmitted) return this;
16608
17029
  return super.on(event, listener);
16609
17030
  }
17031
+ once(event, listener) {
17032
+ if (!this._connectEventMock) return super.once(event, listener);
17033
+ if (event === "connect" && !this._isConnectOrErrorEmitted) {
17034
+ this._connectEventMock.getReplayedConnectionEvent(inputValue).then(({ output }) => {
17035
+ if (output !== void 0) process.nextTick(() => {
17036
+ listener.call(this, output);
17037
+ this._isConnectOrErrorEmitted = true;
17038
+ });
17039
+ }).catch((err) => {
17040
+ logger.error(`[Mysql2Instrumentation] Error replaying connection event:`, err);
17041
+ });
17042
+ return this;
17043
+ }
17044
+ if (event === "error" && !this._isConnectOrErrorEmitted) return this;
17045
+ return super.once(event, listener);
17046
+ }
17047
+ connect(callback) {
17048
+ if (!callback) return;
17049
+ this._connectEventMock.getReplayedConnectionEvent(inputValue).then(({ output }) => {
17050
+ if (output !== void 0) process.nextTick(() => {
17051
+ this._isConnectOrErrorEmitted = true;
17052
+ callback(null);
17053
+ });
17054
+ }).catch((err) => {
17055
+ logger.error(`[Mysql2Instrumentation] Error replaying connection event in connect():`, err);
17056
+ process.nextTick(() => callback(err));
17057
+ });
17058
+ }
16610
17059
  }
16611
17060
  const mockConnection = new MockConnection(...args);
16612
17061
  mockConnection.addListener("error", (_err) => {});
@@ -16634,9 +17083,13 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
16634
17083
  fields: fields || []
16635
17084
  };
16636
17085
  else if (result.affectedRows !== void 0) outputValue = {
17086
+ fieldCount: result.fieldCount,
16637
17087
  affectedRows: result.affectedRows,
16638
17088
  insertId: result.insertId,
16639
- warningCount: result.warningCount
17089
+ info: result.info ?? "",
17090
+ serverStatus: result.serverStatus ?? 0,
17091
+ warningStatus: result.warningStatus ?? 0,
17092
+ changedRows: result.changedRows ?? 0
16640
17093
  };
16641
17094
  else outputValue = result;
16642
17095
  SpanUtils.addSpanAttributes(spanInfo.span, { outputValue });
@@ -18864,16 +19317,28 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
18864
19317
  /**
18865
19318
  * Helper method to parse optional unary response arguments
18866
19319
  *
18867
- * Handles the following cases:
18868
- * 1. (metadata: Metadata, callback: Function) - no options
18869
- * 2. (metadata: Metadata, options: Object, callback: Function) - with options
19320
+ * Handles the following cases (matching grpc-node's checkOptionalUnaryResponseArguments):
19321
+ * 1. (callback: Function) - callback only, no metadata or options
19322
+ * 2. (metadata: Metadata, callback: Function) - metadata + callback, no options
19323
+ * 3. (options: Object, callback: Function) - options + callback, no metadata
19324
+ * 4. (metadata: Metadata, options: Object, callback: Function) - full signature
18870
19325
  */
18871
19326
  parseUnaryCallArguments(MetadataConstructor, arg1, arg2, arg3) {
19327
+ if (typeof arg1 === "function") return {
19328
+ metadata: new MetadataConstructor(),
19329
+ options: {},
19330
+ callback: arg1
19331
+ };
18872
19332
  if (arg1 instanceof MetadataConstructor && typeof arg2 === "function") return {
18873
19333
  metadata: arg1,
18874
19334
  options: {},
18875
19335
  callback: arg2
18876
19336
  };
19337
+ if (!(arg1 instanceof MetadataConstructor) && typeof arg1 === "object" && arg1 !== null && typeof arg2 === "function") return {
19338
+ metadata: new MetadataConstructor(),
19339
+ options: arg1,
19340
+ callback: arg2
19341
+ };
18877
19342
  if (arg1 instanceof MetadataConstructor && arg2 instanceof Object && typeof arg3 === "function") return {
18878
19343
  metadata: arg1,
18879
19344
  options: arg2,
@@ -25218,7 +25683,6 @@ var SpanTransformer = class SpanTransformer {
25218
25683
  } catch (error) {
25219
25684
  logger.warn("[SpanTransformer] Failed to parse transform metadata", error);
25220
25685
  }
25221
- const originalDate = OriginalGlobalUtils.getOriginalDate();
25222
25686
  return {
25223
25687
  traceId: span.spanContext().traceId,
25224
25688
  spanId: span.spanContext().spanId,
@@ -25244,8 +25708,8 @@ var SpanTransformer = class SpanTransformer {
25244
25708
  },
25245
25709
  isPreAppStart: attributes[TdSpanAttributes.IS_PRE_APP_START] === true,
25246
25710
  timestamp: {
25247
- seconds: Math.floor(originalDate.getTime() / 1e3),
25248
- nanos: originalDate.getTime() % 1e3 * 1e6
25711
+ seconds: span.startTime[0],
25712
+ nanos: span.startTime[1]
25249
25713
  },
25250
25714
  duration: {
25251
25715
  seconds: span.duration[0],
@@ -25815,15 +26279,13 @@ var TdSpanExporter = class {
25815
26279
  logger.debug("All adapters cleared");
25816
26280
  }
25817
26281
  /**
25818
- * Set the mode for determining which adapters to run
25819
- */
25820
- setMode(mode) {
25821
- this.mode = mode;
25822
- }
25823
- /**
25824
26282
  * Export spans using all configured adapters
25825
26283
  */
25826
26284
  export(spans, resultCallback) {
26285
+ if (this.mode !== TuskDriftMode.RECORD) {
26286
+ resultCallback({ code: import_src$5.ExportResultCode.SUCCESS });
26287
+ return;
26288
+ }
25827
26289
  logger.debug(`TdSpanExporter.export() called with ${spans.length} span(s)`);
25828
26290
  const traceBlockingManager = TraceBlockingManager.getInstance();
25829
26291
  const filteredSpansBasedOnLibraryName = spans.filter((span) => {
@@ -25862,21 +26324,16 @@ var TdSpanExporter = class {
25862
26324
  resultCallback({ code: import_src$5.ExportResultCode.SUCCESS });
25863
26325
  return;
25864
26326
  }
25865
- const activeAdapters = this.getActiveAdapters();
25866
- if (activeAdapters.length === 0) {
26327
+ if (this.adapters.length === 0) {
25867
26328
  logger.debug(`No active adapters for mode: ${this.mode}`);
25868
26329
  resultCallback({ code: import_src$5.ExportResultCode.SUCCESS });
25869
26330
  return;
25870
26331
  }
25871
- Promise.all(activeAdapters.map((adapter) => adapter.exportSpans(cleanSpans))).then(() => resultCallback({ code: import_src$5.ExportResultCode.SUCCESS })).catch((error) => resultCallback({
26332
+ Promise.all(this.adapters.map((adapter) => adapter.exportSpans(cleanSpans))).then(() => resultCallback({ code: import_src$5.ExportResultCode.SUCCESS })).catch((error) => resultCallback({
25872
26333
  code: import_src$5.ExportResultCode.FAILED,
25873
26334
  error
25874
26335
  }));
25875
26336
  }
25876
- getActiveAdapters() {
25877
- if (this.mode !== TuskDriftMode.RECORD) return this.adapters.filter((adapter) => adapter.name === "in-memory" || adapter.name === "callback");
25878
- return this.adapters;
25879
- }
25880
26337
  /**
25881
26338
  * Shutdown all adapters
25882
26339
  */
@@ -33007,7 +33464,7 @@ var require_src = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/sdk-
33007
33464
  //#endregion
33008
33465
  //#region package.json
33009
33466
  var import_src$1 = /* @__PURE__ */ __toESM(require_src(), 1);
33010
- var version = "0.1.21";
33467
+ var version = "0.1.23";
33011
33468
 
33012
33469
  //#endregion
33013
33470
  //#region src/version.ts