@use-tusk/drift-node-sdk 0.1.14 → 0.1.16

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
@@ -60,10 +60,10 @@ let crypto = require("crypto");
60
60
  crypto = __toESM(crypto);
61
61
  let jsonpath = require("jsonpath");
62
62
  jsonpath = __toESM(jsonpath);
63
- let net = require("net");
64
- net = __toESM(net);
65
63
  let stream = require("stream");
66
64
  stream = __toESM(stream);
65
+ let net = require("net");
66
+ net = __toESM(net);
67
67
  let child_process = require("child_process");
68
68
  child_process = __toESM(child_process);
69
69
 
@@ -4351,14 +4351,14 @@ var require_context$1 = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetr
4351
4351
  self._currentContext = parentContext ? new Map(parentContext) : /* @__PURE__ */ new Map();
4352
4352
  self.getValue = (key) => self._currentContext.get(key);
4353
4353
  self.setValue = (key, value) => {
4354
- const context$4 = new BaseContext(self._currentContext);
4355
- context$4._currentContext.set(key, value);
4356
- return context$4;
4354
+ const context$6 = new BaseContext(self._currentContext);
4355
+ context$6._currentContext.set(key, value);
4356
+ return context$6;
4357
4357
  };
4358
4358
  self.deleteValue = (key) => {
4359
- const context$4 = new BaseContext(self._currentContext);
4360
- context$4._currentContext.delete(key);
4361
- return context$4;
4359
+ const context$6 = new BaseContext(self._currentContext);
4360
+ context$6._currentContext.delete(key);
4361
+ return context$6;
4362
4362
  };
4363
4363
  }
4364
4364
  };
@@ -4614,8 +4614,8 @@ var require_context = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/
4614
4614
  * @param thisArg optional receiver to be used for calling fn
4615
4615
  * @param args optional arguments forwarded to fn
4616
4616
  */
4617
- with(context$4, fn, thisArg, ...args) {
4618
- return this._getContextManager().with(context$4, fn, thisArg, ...args);
4617
+ with(context$6, fn, thisArg, ...args) {
4618
+ return this._getContextManager().with(context$6, fn, thisArg, ...args);
4619
4619
  }
4620
4620
  /**
4621
4621
  * Bind a context to a target function or event emitter
@@ -4623,8 +4623,8 @@ var require_context = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/
4623
4623
  * @param context context to bind to the event emitter or function. Defaults to the currently active context
4624
4624
  * @param target function or event emitter to bind
4625
4625
  */
4626
- bind(context$4, target) {
4627
- return this._getContextManager().bind(context$4, target);
4626
+ bind(context$6, target) {
4627
+ return this._getContextManager().bind(context$6, target);
4628
4628
  }
4629
4629
  _getContextManager() {
4630
4630
  return (0, global_utils_1$3.getGlobal)(API_NAME$3) || NOOP_CONTEXT_MANAGER;
@@ -4725,8 +4725,8 @@ var require_context_utils = /* @__PURE__ */ __commonJS({ "node_modules/@opentele
4725
4725
  *
4726
4726
  * @param context context to get span from
4727
4727
  */
4728
- function getSpan(context$4) {
4729
- return context$4.getValue(SPAN_KEY) || void 0;
4728
+ function getSpan(context$6) {
4729
+ return context$6.getValue(SPAN_KEY) || void 0;
4730
4730
  }
4731
4731
  exports.getSpan = getSpan;
4732
4732
  /**
@@ -4742,8 +4742,8 @@ var require_context_utils = /* @__PURE__ */ __commonJS({ "node_modules/@opentele
4742
4742
  * @param context context to use as parent
4743
4743
  * @param span span to set active
4744
4744
  */
4745
- function setSpan(context$4, span) {
4746
- return context$4.setValue(SPAN_KEY, span);
4745
+ function setSpan(context$6, span) {
4746
+ return context$6.setValue(SPAN_KEY, span);
4747
4747
  }
4748
4748
  exports.setSpan = setSpan;
4749
4749
  /**
@@ -4751,8 +4751,8 @@ var require_context_utils = /* @__PURE__ */ __commonJS({ "node_modules/@opentele
4751
4751
  *
4752
4752
  * @param context context to delete span from
4753
4753
  */
4754
- function deleteSpan(context$4) {
4755
- return context$4.deleteValue(SPAN_KEY);
4754
+ function deleteSpan(context$6) {
4755
+ return context$6.deleteValue(SPAN_KEY);
4756
4756
  }
4757
4757
  exports.deleteSpan = deleteSpan;
4758
4758
  /**
@@ -4762,8 +4762,8 @@ var require_context_utils = /* @__PURE__ */ __commonJS({ "node_modules/@opentele
4762
4762
  * @param context context to set active span on
4763
4763
  * @param spanContext span context to be wrapped
4764
4764
  */
4765
- function setSpanContext(context$4, spanContext) {
4766
- return setSpan(context$4, new NonRecordingSpan_1$2.NonRecordingSpan(spanContext));
4765
+ function setSpanContext(context$6, spanContext) {
4766
+ return setSpan(context$6, new NonRecordingSpan_1$2.NonRecordingSpan(spanContext));
4767
4767
  }
4768
4768
  exports.setSpanContext = setSpanContext;
4769
4769
  /**
@@ -4771,9 +4771,9 @@ var require_context_utils = /* @__PURE__ */ __commonJS({ "node_modules/@opentele
4771
4771
  *
4772
4772
  * @param context context to get values from
4773
4773
  */
4774
- function getSpanContext(context$4) {
4774
+ function getSpanContext(context$6) {
4775
4775
  var _a;
4776
- return (_a = getSpan(context$4)) === null || _a === void 0 ? void 0 : _a.spanContext();
4776
+ return (_a = getSpan(context$6)) === null || _a === void 0 ? void 0 : _a.spanContext();
4777
4777
  }
4778
4778
  exports.getSpanContext = getSpanContext;
4779
4779
  }) });
@@ -4829,9 +4829,9 @@ var require_NoopTracer = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemet
4829
4829
  * No-op implementations of {@link Tracer}.
4830
4830
  */
4831
4831
  var NoopTracer = class {
4832
- startSpan(name, options, context$4 = contextApi.active()) {
4832
+ startSpan(name, options, context$6 = contextApi.active()) {
4833
4833
  if (Boolean(options === null || options === void 0 ? void 0 : options.root)) return new NonRecordingSpan_1.NonRecordingSpan();
4834
- const parentFromContext = context$4 && (0, context_utils_1$1.getSpanContext)(context$4);
4834
+ const parentFromContext = context$6 && (0, context_utils_1$1.getSpanContext)(context$6);
4835
4835
  if (isSpanContext(parentFromContext) && (0, spancontext_utils_1$2.isSpanContextValid)(parentFromContext)) return new NonRecordingSpan_1.NonRecordingSpan(parentFromContext);
4836
4836
  else return new NonRecordingSpan_1.NonRecordingSpan();
4837
4837
  }
@@ -4877,8 +4877,8 @@ var require_ProxyTracer = /* @__PURE__ */ __commonJS({ "node_modules/@openteleme
4877
4877
  this.version = version$1;
4878
4878
  this.options = options;
4879
4879
  }
4880
- startSpan(name, options, context$4) {
4881
- return this._getTracer().startSpan(name, options, context$4);
4880
+ startSpan(name, options, context$6) {
4881
+ return this._getTracer().startSpan(name, options, context$6);
4882
4882
  }
4883
4883
  startActiveSpan(_name, _options, _context, _fn) {
4884
4884
  const tracer = this._getTracer();
@@ -4989,31 +4989,31 @@ var require_SamplingResult = /* @__PURE__ */ __commonJS({ "node_modules/@opentel
4989
4989
  var require_span_kind = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/api/build/src/trace/span_kind.js": ((exports) => {
4990
4990
  Object.defineProperty(exports, "__esModule", { value: true });
4991
4991
  exports.SpanKind = void 0;
4992
- (function(SpanKind$22) {
4992
+ (function(SpanKind$24) {
4993
4993
  /** Default value. Indicates that the span is used internally. */
4994
- SpanKind$22[SpanKind$22["INTERNAL"] = 0] = "INTERNAL";
4994
+ SpanKind$24[SpanKind$24["INTERNAL"] = 0] = "INTERNAL";
4995
4995
  /**
4996
4996
  * Indicates that the span covers server-side handling of an RPC or other
4997
4997
  * remote request.
4998
4998
  */
4999
- SpanKind$22[SpanKind$22["SERVER"] = 1] = "SERVER";
4999
+ SpanKind$24[SpanKind$24["SERVER"] = 1] = "SERVER";
5000
5000
  /**
5001
5001
  * Indicates that the span covers the client-side wrapper around an RPC or
5002
5002
  * other remote request.
5003
5003
  */
5004
- SpanKind$22[SpanKind$22["CLIENT"] = 2] = "CLIENT";
5004
+ SpanKind$24[SpanKind$24["CLIENT"] = 2] = "CLIENT";
5005
5005
  /**
5006
5006
  * Indicates that the span describes producer sending a message to a
5007
5007
  * broker. Unlike client and server, there is no direct critical path latency
5008
5008
  * relationship between producer and consumer spans.
5009
5009
  */
5010
- SpanKind$22[SpanKind$22["PRODUCER"] = 3] = "PRODUCER";
5010
+ SpanKind$24[SpanKind$24["PRODUCER"] = 3] = "PRODUCER";
5011
5011
  /**
5012
5012
  * Indicates that the span describes consumer receiving a message from a
5013
5013
  * broker. Unlike client and server, there is no direct critical path latency
5014
5014
  * relationship between producer and consumer spans.
5015
5015
  */
5016
- SpanKind$22[SpanKind$22["CONSUMER"] = 4] = "CONSUMER";
5016
+ SpanKind$24[SpanKind$24["CONSUMER"] = 4] = "CONSUMER";
5017
5017
  })(exports.SpanKind || (exports.SpanKind = {}));
5018
5018
  }) });
5019
5019
 
@@ -5022,20 +5022,20 @@ var require_span_kind = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetr
5022
5022
  var require_status = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/api/build/src/trace/status.js": ((exports) => {
5023
5023
  Object.defineProperty(exports, "__esModule", { value: true });
5024
5024
  exports.SpanStatusCode = void 0;
5025
- (function(SpanStatusCode$12) {
5025
+ (function(SpanStatusCode$13) {
5026
5026
  /**
5027
5027
  * The default status.
5028
5028
  */
5029
- SpanStatusCode$12[SpanStatusCode$12["UNSET"] = 0] = "UNSET";
5029
+ SpanStatusCode$13[SpanStatusCode$13["UNSET"] = 0] = "UNSET";
5030
5030
  /**
5031
5031
  * The operation has been validated by an Application developer or
5032
5032
  * Operator to have completed successfully.
5033
5033
  */
5034
- SpanStatusCode$12[SpanStatusCode$12["OK"] = 1] = "OK";
5034
+ SpanStatusCode$13[SpanStatusCode$13["OK"] = 1] = "OK";
5035
5035
  /**
5036
5036
  * The operation contains an error.
5037
5037
  */
5038
- SpanStatusCode$12[SpanStatusCode$12["ERROR"] = 2] = "ERROR";
5038
+ SpanStatusCode$13[SpanStatusCode$13["ERROR"] = 2] = "ERROR";
5039
5039
  })(exports.SpanStatusCode || (exports.SpanStatusCode = {}));
5040
5040
  }) });
5041
5041
 
@@ -5267,8 +5267,8 @@ var require_NoopTextMapPropagator = /* @__PURE__ */ __commonJS({ "node_modules/@
5267
5267
  /** Noop inject function does nothing */
5268
5268
  inject(_context, _carrier) {}
5269
5269
  /** Noop extract function does nothing and returns the input context */
5270
- extract(context$4, _carrier) {
5271
- return context$4;
5270
+ extract(context$6, _carrier) {
5271
+ return context$6;
5272
5272
  }
5273
5273
  fields() {
5274
5274
  return [];
@@ -5293,8 +5293,8 @@ var require_context_helpers = /* @__PURE__ */ __commonJS({ "node_modules/@opente
5293
5293
  * @param {Context} Context that manage all context values
5294
5294
  * @returns {Baggage} Extracted baggage from the context
5295
5295
  */
5296
- function getBaggage(context$4) {
5297
- return context$4.getValue(BAGGAGE_KEY) || void 0;
5296
+ function getBaggage(context$6) {
5297
+ return context$6.getValue(BAGGAGE_KEY) || void 0;
5298
5298
  }
5299
5299
  exports.getBaggage = getBaggage;
5300
5300
  /**
@@ -5312,8 +5312,8 @@ var require_context_helpers = /* @__PURE__ */ __commonJS({ "node_modules/@opente
5312
5312
  * @param {Context} Context that manage all context values
5313
5313
  * @param {Baggage} baggage that will be set in the actual context
5314
5314
  */
5315
- function setBaggage(context$4, baggage) {
5316
- return context$4.setValue(BAGGAGE_KEY, baggage);
5315
+ function setBaggage(context$6, baggage) {
5316
+ return context$6.setValue(BAGGAGE_KEY, baggage);
5317
5317
  }
5318
5318
  exports.setBaggage = setBaggage;
5319
5319
  /**
@@ -5321,8 +5321,8 @@ var require_context_helpers = /* @__PURE__ */ __commonJS({ "node_modules/@opente
5321
5321
  *
5322
5322
  * @param {Context} Context that manage all context values
5323
5323
  */
5324
- function deleteBaggage(context$4) {
5325
- return context$4.deleteValue(BAGGAGE_KEY);
5324
+ function deleteBaggage(context$6) {
5325
+ return context$6.deleteValue(BAGGAGE_KEY);
5326
5326
  }
5327
5327
  exports.deleteBaggage = deleteBaggage;
5328
5328
  }) });
@@ -5372,8 +5372,8 @@ var require_propagation = /* @__PURE__ */ __commonJS({ "node_modules/@openteleme
5372
5372
  * @param carrier carrier to inject context into
5373
5373
  * @param setter Function used to set values on the carrier
5374
5374
  */
5375
- inject(context$4, carrier, setter = TextMapPropagator_1$1.defaultTextMapSetter) {
5376
- return this._getGlobalPropagator().inject(context$4, carrier, setter);
5375
+ inject(context$6, carrier, setter = TextMapPropagator_1$1.defaultTextMapSetter) {
5376
+ return this._getGlobalPropagator().inject(context$6, carrier, setter);
5377
5377
  }
5378
5378
  /**
5379
5379
  * Extract context from a carrier
@@ -5382,8 +5382,8 @@ var require_propagation = /* @__PURE__ */ __commonJS({ "node_modules/@openteleme
5382
5382
  * @param carrier Carrier to extract context from
5383
5383
  * @param getter Function used to extract keys from a carrier
5384
5384
  */
5385
- extract(context$4, carrier, getter = TextMapPropagator_1$1.defaultTextMapGetter) {
5386
- return this._getGlobalPropagator().extract(context$4, carrier, getter);
5385
+ extract(context$6, carrier, getter = TextMapPropagator_1$1.defaultTextMapGetter) {
5386
+ return this._getGlobalPropagator().extract(context$6, carrier, getter);
5387
5387
  }
5388
5388
  /**
5389
5389
  * Return a list of all fields which may be used by the propagator.
@@ -5684,7 +5684,7 @@ var require_src$7 = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/ap
5684
5684
 
5685
5685
  //#endregion
5686
5686
  //#region node_modules/@use-tusk/drift-schemas/dist/duration-B3fwb4jB.js
5687
- var import_src$32 = /* @__PURE__ */ __toESM(require_src$7(), 1);
5687
+ var import_src$34 = /* @__PURE__ */ __toESM(require_src$7(), 1);
5688
5688
  var import_commonjs$9 = /* @__PURE__ */ __toESM(require_commonjs$2(), 1);
5689
5689
  var Duration$Type = class extends import_commonjs$9.MessageType {
5690
5690
  constructor() {
@@ -6997,11 +6997,11 @@ const Trace = new Trace$Type();
6997
6997
  const toStruct = (obj) => obj ? objectToProtobufStruct(obj) : void 0;
6998
6998
  const mapOtToPb = (k) => {
6999
6999
  switch (k) {
7000
- case import_src$32.SpanKind.INTERNAL: return SpanKind.INTERNAL;
7001
- case import_src$32.SpanKind.SERVER: return SpanKind.SERVER;
7002
- case import_src$32.SpanKind.CLIENT: return SpanKind.CLIENT;
7003
- case import_src$32.SpanKind.PRODUCER: return SpanKind.PRODUCER;
7004
- case import_src$32.SpanKind.CONSUMER: return SpanKind.CONSUMER;
7000
+ case import_src$34.SpanKind.INTERNAL: return SpanKind.INTERNAL;
7001
+ case import_src$34.SpanKind.SERVER: return SpanKind.SERVER;
7002
+ case import_src$34.SpanKind.CLIENT: return SpanKind.CLIENT;
7003
+ case import_src$34.SpanKind.PRODUCER: return SpanKind.PRODUCER;
7004
+ case import_src$34.SpanKind.CONSUMER: return SpanKind.CONSUMER;
7005
7005
  default: return SpanKind.UNSPECIFIED;
7006
7006
  }
7007
7007
  };
@@ -7405,13 +7405,13 @@ var TdInstrumentationNodeModule = class {
7405
7405
 
7406
7406
  //#endregion
7407
7407
  //#region src/core/types.ts
7408
- var import_src$31 = /* @__PURE__ */ __toESM(require_src$7(), 1);
7408
+ var import_src$33 = /* @__PURE__ */ __toESM(require_src$7(), 1);
7409
7409
  const TD_INSTRUMENTATION_LIBRARY_NAME = "tusk-drift-sdk";
7410
- const REPLAY_TRACE_ID_CONTEXT_KEY = (0, import_src$31.createContextKey)("td.replayTraceId");
7411
- const SPAN_KIND_CONTEXT_KEY = (0, import_src$31.createContextKey)("td.spanKind");
7412
- const IS_PRE_APP_START_CONTEXT_KEY = (0, import_src$31.createContextKey)("td.isPreAppStart");
7413
- const STOP_RECORDING_CHILD_SPANS_CONTEXT_KEY = (0, import_src$31.createContextKey)("td.stopRecordingChildSpans");
7414
- const CALLING_LIBRARY_CONTEXT_KEY = (0, import_src$31.createContextKey)("td.callingLibrary");
7410
+ const REPLAY_TRACE_ID_CONTEXT_KEY = (0, import_src$33.createContextKey)("td.replayTraceId");
7411
+ const SPAN_KIND_CONTEXT_KEY = (0, import_src$33.createContextKey)("td.spanKind");
7412
+ const IS_PRE_APP_START_CONTEXT_KEY = (0, import_src$33.createContextKey)("td.isPreAppStart");
7413
+ const STOP_RECORDING_CHILD_SPANS_CONTEXT_KEY = (0, import_src$33.createContextKey)("td.stopRecordingChildSpans");
7414
+ const CALLING_LIBRARY_CONTEXT_KEY = (0, import_src$33.createContextKey)("td.callingLibrary");
7415
7415
  let TdSpanAttributes = /* @__PURE__ */ function(TdSpanAttributes$1) {
7416
7416
  /**
7417
7417
  * Presentational information:
@@ -7523,7 +7523,7 @@ TraceBlockingManager.instance = null;
7523
7523
 
7524
7524
  //#endregion
7525
7525
  //#region src/core/tracing/SpanUtils.ts
7526
- var import_src$30 = /* @__PURE__ */ __toESM(require_src$7(), 1);
7526
+ var import_src$32 = /* @__PURE__ */ __toESM(require_src$7(), 1);
7527
7527
  var SpanUtils = class SpanUtils {
7528
7528
  /**
7529
7529
  * Creates a new span and returns span info including trace ID and span ID
@@ -7531,8 +7531,8 @@ var SpanUtils = class SpanUtils {
7531
7531
  static createSpan(options) {
7532
7532
  try {
7533
7533
  const tracer = TuskDriftCore.getInstance().getTracer();
7534
- const parentContext = options.parentContext || import_src$30.context.active();
7535
- const activeSpan = import_src$30.trace.getSpan(parentContext);
7534
+ const parentContext = options.parentContext || import_src$32.context.active();
7535
+ const activeSpan = import_src$32.trace.getSpan(parentContext);
7536
7536
  if (activeSpan) {
7537
7537
  const parentTraceId = activeSpan.spanContext().traceId;
7538
7538
  if (TraceBlockingManager.getInstance().isTraceBlocked(parentTraceId)) {
@@ -7541,11 +7541,11 @@ var SpanUtils = class SpanUtils {
7541
7541
  }
7542
7542
  }
7543
7543
  const span = tracer.startSpan(options.name, {
7544
- kind: options.kind || import_src$30.SpanKind.CLIENT,
7544
+ kind: options.kind || import_src$32.SpanKind.CLIENT,
7545
7545
  attributes: options.attributes || {}
7546
7546
  }, parentContext);
7547
7547
  const spanContext = span.spanContext();
7548
- const newContext = import_src$30.trace.setSpan(parentContext, span).setValue(SPAN_KIND_CONTEXT_KEY, options.kind).setValue(IS_PRE_APP_START_CONTEXT_KEY, options.isPreAppStart);
7548
+ const newContext = import_src$32.trace.setSpan(parentContext, span).setValue(SPAN_KIND_CONTEXT_KEY, options.kind).setValue(IS_PRE_APP_START_CONTEXT_KEY, options.isPreAppStart);
7549
7549
  return {
7550
7550
  traceId: spanContext.traceId,
7551
7551
  spanId: spanContext.spanId,
@@ -7562,7 +7562,7 @@ var SpanUtils = class SpanUtils {
7562
7562
  * Executes a function within a span context
7563
7563
  */
7564
7564
  static withSpan(spanInfo, fn) {
7565
- return import_src$30.context.with(spanInfo.context, fn);
7565
+ return import_src$32.context.with(spanInfo.context, fn);
7566
7566
  }
7567
7567
  /**
7568
7568
  * Execute a function within a properly configured span
@@ -7579,9 +7579,9 @@ var SpanUtils = class SpanUtils {
7579
7579
  * @returns The result of the function execution
7580
7580
  */
7581
7581
  static createAndExecuteSpan(mode, originalFunctionCall, options, fn) {
7582
- const spanContext = import_src$30.trace.getActiveSpan()?.spanContext();
7582
+ const spanContext = import_src$32.trace.getActiveSpan()?.spanContext();
7583
7583
  if (spanContext) {
7584
- if (import_src$30.context.active().getValue(STOP_RECORDING_CHILD_SPANS_CONTEXT_KEY)) {
7584
+ if (import_src$32.context.active().getValue(STOP_RECORDING_CHILD_SPANS_CONTEXT_KEY)) {
7585
7585
  logger.debug(`[SpanUtils] Stopping recording of child spans for span ${spanContext.spanId}, packageName: ${options.packageName}, instrumentationName: ${options.instrumentationName}`);
7586
7586
  return originalFunctionCall();
7587
7587
  }
@@ -7619,15 +7619,15 @@ var SpanUtils = class SpanUtils {
7619
7619
  */
7620
7620
  static getCurrentSpanInfo() {
7621
7621
  try {
7622
- const activeSpan = import_src$30.trace.getActiveSpan();
7622
+ const activeSpan = import_src$32.trace.getActiveSpan();
7623
7623
  if (!activeSpan) return null;
7624
7624
  const spanContext = activeSpan.spanContext();
7625
7625
  return {
7626
7626
  traceId: spanContext.traceId,
7627
7627
  spanId: spanContext.spanId,
7628
7628
  span: activeSpan,
7629
- context: import_src$30.context.active(),
7630
- isPreAppStart: import_src$30.context.active().getValue(IS_PRE_APP_START_CONTEXT_KEY)
7629
+ context: import_src$32.context.active(),
7630
+ isPreAppStart: import_src$32.context.active().getValue(IS_PRE_APP_START_CONTEXT_KEY)
7631
7631
  };
7632
7632
  } catch (error) {
7633
7633
  logger.error("SpanUtils error getting current span info:", error);
@@ -7691,7 +7691,7 @@ var SpanUtils = class SpanUtils {
7691
7691
  }
7692
7692
  static setCurrentReplayTraceId(replayTraceId) {
7693
7693
  try {
7694
- return import_src$30.context.active().setValue(REPLAY_TRACE_ID_CONTEXT_KEY, replayTraceId);
7694
+ return import_src$32.context.active().setValue(REPLAY_TRACE_ID_CONTEXT_KEY, replayTraceId);
7695
7695
  } catch (error) {
7696
7696
  logger.error("SpanUtils error setting current replay trace id:", error);
7697
7697
  return null;
@@ -7702,7 +7702,7 @@ var SpanUtils = class SpanUtils {
7702
7702
  */
7703
7703
  static getCurrentReplayTraceId() {
7704
7704
  try {
7705
- return import_src$30.context.active().getValue(REPLAY_TRACE_ID_CONTEXT_KEY);
7705
+ return import_src$32.context.active().getValue(REPLAY_TRACE_ID_CONTEXT_KEY);
7706
7706
  } catch (error) {
7707
7707
  logger.error("SpanUtils error getting current replay trace id:", error);
7708
7708
  return null;
@@ -8364,7 +8364,7 @@ function findMockResponseSync({ mockRequestData, tuskDrift, inputValueSchemaMerg
8364
8364
 
8365
8365
  //#endregion
8366
8366
  //#region src/instrumentation/libraries/http/mocks/TdMockClientRequest.ts
8367
- var import_src$29 = /* @__PURE__ */ __toESM(require_src$7(), 1);
8367
+ var import_src$31 = /* @__PURE__ */ __toESM(require_src$7(), 1);
8368
8368
  let ClientRequest;
8369
8369
  /**
8370
8370
  * Mock ClientRequest implementation for Tusk Drift HTTP replay
@@ -8535,7 +8535,7 @@ var TdMockClientRequest = class TdMockClientRequest extends events.EventEmitter
8535
8535
  instrumentationName: this.INSTRUMENTATION_NAME,
8536
8536
  submoduleName: rawInputValue.method,
8537
8537
  inputValue,
8538
- kind: import_src$29.SpanKind.CLIENT,
8538
+ kind: import_src$31.SpanKind.CLIENT,
8539
8539
  stackTrace: this.stackTrace
8540
8540
  },
8541
8541
  tuskDrift: this.tuskDrift,
@@ -8712,7 +8712,7 @@ var HttpReplayHooks = class {
8712
8712
 
8713
8713
  //#endregion
8714
8714
  //#region src/instrumentation/core/utils/modeUtils.ts
8715
- var import_src$28 = /* @__PURE__ */ __toESM(require_src$7(), 1);
8715
+ var import_src$30 = /* @__PURE__ */ __toESM(require_src$7(), 1);
8716
8716
  /**
8717
8717
  * Utility function that abstracts the common record mode pattern of checking for current span context
8718
8718
  * and deciding whether to execute record mode logic or just call the original function.
@@ -8733,7 +8733,7 @@ function handleRecordMode({ originalFunctionCall, recordModeHandler, spanKind })
8733
8733
  return originalFunctionCall();
8734
8734
  }
8735
8735
  if (!isAppReady) return recordModeHandler({ isPreAppStart: true });
8736
- if (!currentSpanInfo && spanKind !== import_src$28.SpanKind.SERVER || currentSpanInfo?.isPreAppStart) return originalFunctionCall();
8736
+ if (!currentSpanInfo && spanKind !== import_src$30.SpanKind.SERVER || currentSpanInfo?.isPreAppStart) return originalFunctionCall();
8737
8737
  else return recordModeHandler({ isPreAppStart: false });
8738
8738
  }
8739
8739
  /**
@@ -10213,7 +10213,7 @@ function captureStackTrace(excludeClassNames = []) {
10213
10213
 
10214
10214
  //#endregion
10215
10215
  //#region src/instrumentation/libraries/http/HttpTransformEngine.ts
10216
- var import_src$27 = /* @__PURE__ */ __toESM(require_src$7(), 1);
10216
+ var import_src$29 = /* @__PURE__ */ __toESM(require_src$7(), 1);
10217
10217
  /**
10218
10218
  * Creates an empty HttpClientInputValue object for dropped spans
10219
10219
  */
@@ -10266,7 +10266,7 @@ var HttpTransformEngine = class {
10266
10266
  const testSpan = {
10267
10267
  traceId: "",
10268
10268
  spanId: "",
10269
- kind: import_src$27.SpanKind.SERVER,
10269
+ kind: import_src$29.SpanKind.SERVER,
10270
10270
  protocol: "http",
10271
10271
  inputValue: {
10272
10272
  method,
@@ -10289,7 +10289,7 @@ var HttpTransformEngine = class {
10289
10289
  const testSpan = {
10290
10290
  traceId: "",
10291
10291
  spanId: "",
10292
- kind: import_src$27.SpanKind.CLIENT,
10292
+ kind: import_src$29.SpanKind.CLIENT,
10293
10293
  protocol: inputValue.protocol || "http",
10294
10294
  inputValue: clonedInputValue
10295
10295
  };
@@ -10316,8 +10316,8 @@ var HttpTransformEngine = class {
10316
10316
  const matcherFunction = this.compileMatcher(matcher);
10317
10317
  if (action.type === "drop") return (span) => {
10318
10318
  if (!matcherFunction(span)) return;
10319
- if (span.inputValue) span.inputValue = span.kind === import_src$27.SpanKind.CLIENT ? createEmptyClientInputValue(span.protocol) : createEmptyServerInputValue();
10320
- if (span.outputValue) span.outputValue = span.kind === import_src$27.SpanKind.CLIENT ? createEmptyClientOutputValue() : createEmptyServerOutputValue();
10319
+ if (span.inputValue) span.inputValue = span.kind === import_src$29.SpanKind.CLIENT ? createEmptyClientInputValue(span.protocol) : createEmptyServerInputValue();
10320
+ if (span.outputValue) span.outputValue = span.kind === import_src$29.SpanKind.CLIENT ? createEmptyClientOutputValue() : createEmptyServerOutputValue();
10321
10321
  return {
10322
10322
  type: "drop",
10323
10323
  field: "entire_span",
@@ -10347,8 +10347,8 @@ var HttpTransformEngine = class {
10347
10347
  }
10348
10348
  compileMatcher(matcher) {
10349
10349
  const checks = [];
10350
- if (matcher.direction === "outbound") checks.push((span) => span.kind === import_src$27.SpanKind.CLIENT);
10351
- else if (matcher.direction === "inbound") checks.push((span) => span.kind === import_src$27.SpanKind.SERVER);
10350
+ if (matcher.direction === "outbound") checks.push((span) => span.kind === import_src$29.SpanKind.CLIENT);
10351
+ else if (matcher.direction === "inbound") checks.push((span) => span.kind === import_src$29.SpanKind.SERVER);
10352
10352
  if (matcher.method) if (matcher.method.length === 0) {} else {
10353
10353
  const methods = matcher.method.map((method) => method.toUpperCase());
10354
10354
  checks.push((span) => {
@@ -10576,7 +10576,7 @@ var HttpTransformEngine = class {
10576
10576
 
10577
10577
  //#endregion
10578
10578
  //#region src/instrumentation/libraries/http/Instrumentation.ts
10579
- var import_src$26 = /* @__PURE__ */ __toESM(require_src$7(), 1);
10579
+ var import_src$28 = /* @__PURE__ */ __toESM(require_src$7(), 1);
10580
10580
  var HttpInstrumentation = class extends TdInstrumentationBase {
10581
10581
  constructor(config) {
10582
10582
  super("http", config);
@@ -10670,10 +10670,10 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10670
10670
  }
10671
10671
  const ctxWithReplayTraceId = SpanUtils.setCurrentReplayTraceId(replayTraceId);
10672
10672
  if (!ctxWithReplayTraceId) throw new Error("Error setting current replay trace id");
10673
- return import_src$26.context.with(ctxWithReplayTraceId, () => {
10673
+ return import_src$28.context.with(ctxWithReplayTraceId, () => {
10674
10674
  return SpanUtils.createAndExecuteSpan(this.mode, () => originalHandler.call(this), {
10675
10675
  name: `${target}`,
10676
- kind: import_src$26.SpanKind.SERVER,
10676
+ kind: import_src$28.SpanKind.SERVER,
10677
10677
  packageName: spanProtocol,
10678
10678
  submodule: method,
10679
10679
  packageType: PackageType.HTTP,
@@ -10718,7 +10718,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10718
10718
  logger.debug(`[HttpInstrumentation] Http inbound request arriving, inputValue: ${JSON.stringify(inputValue)}`);
10719
10719
  return SpanUtils.createAndExecuteSpan(this.mode, () => originalHandler.call(this), {
10720
10720
  name: `${target}`,
10721
- kind: import_src$26.SpanKind.SERVER,
10721
+ kind: import_src$28.SpanKind.SERVER,
10722
10722
  packageName: spanProtocol,
10723
10723
  packageType: PackageType.HTTP,
10724
10724
  submodule: method,
@@ -10738,7 +10738,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10738
10738
  });
10739
10739
  });
10740
10740
  },
10741
- spanKind: import_src$26.SpanKind.SERVER
10741
+ spanKind: import_src$28.SpanKind.SERVER
10742
10742
  });
10743
10743
  } else return originalHandler.call(this);
10744
10744
  }
@@ -10755,8 +10755,8 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10755
10755
  _handleInboundRequestInSpan({ req, res, originalHandler, spanInfo, inputValue, schemaMerges, protocol }) {
10756
10756
  const self = this;
10757
10757
  const spanProtocol = this._normalizeProtocol(protocol, "http");
10758
- import_src$26.context.bind(spanInfo.context, req);
10759
- import_src$26.context.bind(spanInfo.context, res);
10758
+ import_src$28.context.bind(spanInfo.context, req);
10759
+ import_src$28.context.bind(spanInfo.context, res);
10760
10760
  let completeInputValue = inputValue;
10761
10761
  this._captureServerRequestBody(req, spanInfo, inputValue, schemaMerges, (updatedInputValue) => {
10762
10762
  completeInputValue = updatedInputValue;
@@ -10794,7 +10794,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10794
10794
  const spanData = {
10795
10795
  traceId: spanInfo.traceId,
10796
10796
  spanId: spanInfo.spanId,
10797
- kind: import_src$26.SpanKind.SERVER,
10797
+ kind: import_src$28.SpanKind.SERVER,
10798
10798
  protocol: spanProtocol,
10799
10799
  inputValue: completeInputValue,
10800
10800
  outputValue
@@ -10815,9 +10815,9 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10815
10815
  });
10816
10816
  EnvVarTracker.clearEnvVars(spanInfo.traceId);
10817
10817
  const status = statusCode >= 400 ? {
10818
- code: import_src$26.SpanStatusCode.ERROR,
10818
+ code: import_src$28.SpanStatusCode.ERROR,
10819
10819
  message: `HTTP ${statusCode}`
10820
- } : { code: import_src$26.SpanStatusCode.OK };
10820
+ } : { code: import_src$28.SpanStatusCode.OK };
10821
10821
  SpanUtils.setStatus(spanInfo.span, status);
10822
10822
  const decodedType = getDecodedType(outputValue.headers?.["content-type"] || "");
10823
10823
  if (decodedType && !ACCEPTABLE_CONTENT_TYPES.has(decodedType)) {
@@ -10866,7 +10866,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10866
10866
  outputSchemaHash: JsonSchemaHelper.generateDeterministicHash(outputSchema),
10867
10867
  inputValueHash,
10868
10868
  outputValueHash,
10869
- kind: import_src$26.SpanKind.SERVER,
10869
+ kind: import_src$28.SpanKind.SERVER,
10870
10870
  packageType: PackageType.HTTP,
10871
10871
  status: {
10872
10872
  code: statusCode >= 400 ? StatusCode.ERROR : StatusCode.OK,
@@ -10895,7 +10895,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10895
10895
  try {
10896
10896
  logger.debug(`[HttpInstrumentation] Server request error: ${error.message} (${SpanUtils.getTraceInfo()})`);
10897
10897
  SpanUtils.endSpan(spanInfo.span, {
10898
- code: import_src$26.SpanStatusCode.ERROR,
10898
+ code: import_src$28.SpanStatusCode.ERROR,
10899
10899
  message: error.message
10900
10900
  });
10901
10901
  } catch (error$1) {
@@ -10906,7 +10906,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10906
10906
  try {
10907
10907
  logger.debug(`[HttpInstrumentation] Server response error: ${error.message} (${SpanUtils.getTraceInfo()})`);
10908
10908
  SpanUtils.endSpan(spanInfo.span, {
10909
- code: import_src$26.SpanStatusCode.ERROR,
10909
+ code: import_src$28.SpanStatusCode.ERROR,
10910
10910
  message: error.message
10911
10911
  });
10912
10912
  } catch (error$1) {
@@ -11111,7 +11111,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11111
11111
  inputValue: completeInputValue
11112
11112
  });
11113
11113
  SpanUtils.endSpan(spanInfo.span, {
11114
- code: import_src$26.SpanStatusCode.ERROR,
11114
+ code: import_src$28.SpanStatusCode.ERROR,
11115
11115
  message: error.message
11116
11116
  });
11117
11117
  } catch (error$1) {
@@ -11128,7 +11128,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11128
11128
  const spanData = {
11129
11129
  traceId: spanInfo.traceId,
11130
11130
  spanId: spanInfo.spanId,
11131
- kind: import_src$26.SpanKind.CLIENT,
11131
+ kind: import_src$28.SpanKind.CLIENT,
11132
11132
  protocol: normalizedProtocol,
11133
11133
  inputValue,
11134
11134
  outputValue
@@ -11141,9 +11141,9 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11141
11141
  transformMetadata: spanData.transformMetadata ? spanData.transformMetadata : void 0
11142
11142
  });
11143
11143
  const status = statusCode >= 400 ? {
11144
- code: import_src$26.SpanStatusCode.ERROR,
11144
+ code: import_src$28.SpanStatusCode.ERROR,
11145
11145
  message: `HTTP ${statusCode}`
11146
- } : { code: import_src$26.SpanStatusCode.OK };
11146
+ } : { code: import_src$28.SpanStatusCode.OK };
11147
11147
  SpanUtils.endSpan(spanInfo.span, status);
11148
11148
  }
11149
11149
  _captureHeadersFromRawHeaders(rawHeaders) {
@@ -11197,7 +11197,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11197
11197
  };
11198
11198
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalRequest.apply(this, args), {
11199
11199
  name: requestOptions.path || `${requestProtocol.toUpperCase()} ${method}`,
11200
- kind: import_src$26.SpanKind.CLIENT,
11200
+ kind: import_src$28.SpanKind.CLIENT,
11201
11201
  packageName: requestProtocol,
11202
11202
  packageType: PackageType.HTTP,
11203
11203
  instrumentationName: self.INSTRUMENTATION_NAME,
@@ -11232,7 +11232,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11232
11232
  };
11233
11233
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalRequest.apply(this, args), {
11234
11234
  name: requestOptions.path || `${requestProtocol.toUpperCase()} ${method}`,
11235
- kind: import_src$26.SpanKind.CLIENT,
11235
+ kind: import_src$28.SpanKind.CLIENT,
11236
11236
  packageName: requestProtocol,
11237
11237
  packageType: PackageType.HTTP,
11238
11238
  instrumentationName: self.INSTRUMENTATION_NAME,
@@ -11244,7 +11244,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11244
11244
  return self._handleOutboundRequestInSpan(originalRequest, args, spanInfo, inputValue, { headers: { matchImportance: 0 } });
11245
11245
  });
11246
11246
  },
11247
- spanKind: import_src$26.SpanKind.CLIENT
11247
+ spanKind: import_src$28.SpanKind.CLIENT
11248
11248
  });
11249
11249
  else return originalRequest.apply(this, args);
11250
11250
  };
@@ -11290,7 +11290,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11290
11290
  };
11291
11291
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalGet.apply(this, args), {
11292
11292
  name: requestOptions.path || `${requestProtocol.toUpperCase()} ${method}`,
11293
- kind: import_src$26.SpanKind.CLIENT,
11293
+ kind: import_src$28.SpanKind.CLIENT,
11294
11294
  packageName: requestProtocol,
11295
11295
  packageType: PackageType.HTTP,
11296
11296
  instrumentationName: self.INSTRUMENTATION_NAME,
@@ -11324,7 +11324,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11324
11324
  };
11325
11325
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalGet.apply(this, args), {
11326
11326
  name: requestOptions.path || `${requestProtocol.toUpperCase()} ${method}`,
11327
- kind: import_src$26.SpanKind.CLIENT,
11327
+ kind: import_src$28.SpanKind.CLIENT,
11328
11328
  packageName: requestProtocol,
11329
11329
  packageType: PackageType.HTTP,
11330
11330
  instrumentationName: self.INSTRUMENTATION_NAME,
@@ -11336,7 +11336,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11336
11336
  return self._handleOutboundRequestInSpan(originalGet, args, spanInfo, inputValue, { headers: { matchImportance: 0 } });
11337
11337
  });
11338
11338
  },
11339
- spanKind: import_src$26.SpanKind.CLIENT
11339
+ spanKind: import_src$28.SpanKind.CLIENT
11340
11340
  });
11341
11341
  else return originalGet.apply(this, args);
11342
11342
  };
@@ -11471,7 +11471,7 @@ var EnvInstrumentation = class extends TdInstrumentationBase {
11471
11471
 
11472
11472
  //#endregion
11473
11473
  //#region src/instrumentation/libraries/date/Instrumentation.ts
11474
- var import_src$25 = /* @__PURE__ */ __toESM(require_src$7(), 1);
11474
+ var import_src$27 = /* @__PURE__ */ __toESM(require_src$7(), 1);
11475
11475
  /**
11476
11476
  * Date instrumentation that provides consistent dates in replay mode.
11477
11477
  * In replay mode, new Date() calls return the latest mock response timestamp.
@@ -11510,7 +11510,7 @@ var DateInstrumentation = class DateInstrumentation extends TdInstrumentationBas
11510
11510
  if (this.mode !== TuskDriftMode.REPLAY) return this._callOriginalDate(args, isConstructorCall);
11511
11511
  const currentSpanInfo = SpanUtils.getCurrentSpanInfo();
11512
11512
  if (!currentSpanInfo) return this._callOriginalDate(args, isConstructorCall);
11513
- if (currentSpanInfo.context.getValue(SPAN_KIND_CONTEXT_KEY) !== import_src$25.SpanKind.SERVER) return this._callOriginalDate(args, isConstructorCall);
11513
+ if (currentSpanInfo.context.getValue(SPAN_KIND_CONTEXT_KEY) !== import_src$27.SpanKind.SERVER) return this._callOriginalDate(args, isConstructorCall);
11514
11514
  this.isInPatchedCall = true;
11515
11515
  try {
11516
11516
  return this._handleReplayDate(args, isConstructorCall);
@@ -11630,10 +11630,10 @@ var GraphqlInstrumentation = class extends TdInstrumentationBase {
11630
11630
  /**
11631
11631
  * Handle GraphQL execution - add metadata to parent server span if present
11632
11632
  */
11633
- _handleGraphQLExecution(methodName, originalMethod, args, context$4) {
11633
+ _handleGraphQLExecution(methodName, originalMethod, args, context$6) {
11634
11634
  if (this.tuskDrift.getMode() !== TuskDriftMode.RECORD) {
11635
11635
  logger.debug(`[GraphQLInstrumentation] Not in RECORD mode, skipping instrumentation`);
11636
- return originalMethod.apply(context$4, args);
11636
+ return originalMethod.apply(context$6, args);
11637
11637
  }
11638
11638
  let currentSpanInfo = null;
11639
11639
  try {
@@ -11643,7 +11643,7 @@ var GraphqlInstrumentation = class extends TdInstrumentationBase {
11643
11643
  }
11644
11644
  if (!currentSpanInfo) {
11645
11645
  logger.debug(`[GraphQLInstrumentation] No current span found for ${methodName}, calling original`);
11646
- return originalMethod.apply(context$4, args);
11646
+ return originalMethod.apply(context$6, args);
11647
11647
  }
11648
11648
  try {
11649
11649
  logger.debug(`[GraphQLInstrumentation] Update span attributes with GraphQL info`);
@@ -11651,7 +11651,7 @@ var GraphqlInstrumentation = class extends TdInstrumentationBase {
11651
11651
  } catch (error) {
11652
11652
  logger.warn(`[GraphQLInstrumentation] Failed to update span attributes with GraphQL info:`, error);
11653
11653
  }
11654
- return originalMethod.apply(context$4, args);
11654
+ return originalMethod.apply(context$6, args);
11655
11655
  }
11656
11656
  /**
11657
11657
  * Extract GraphQL metadata from execution args and add to span
@@ -11756,7 +11756,7 @@ var TdPgClientMock = class extends events.EventEmitter {
11756
11756
 
11757
11757
  //#endregion
11758
11758
  //#region src/instrumentation/libraries/pg/Instrumentation.ts
11759
- var import_src$24 = /* @__PURE__ */ __toESM(require_src$7(), 1);
11759
+ var import_src$26 = /* @__PURE__ */ __toESM(require_src$7(), 1);
11760
11760
  var PgInstrumentation = class extends TdInstrumentationBase {
11761
11761
  constructor(config = {}) {
11762
11762
  super("pg", config);
@@ -11810,6 +11810,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11810
11810
  const inputValue = {
11811
11811
  text: queryConfig.text,
11812
11812
  values: queryConfig.values || [],
11813
+ rowMode: queryConfig.rowMode,
11813
11814
  clientType
11814
11815
  };
11815
11816
  if (self.mode === TuskDriftMode.REPLAY) {
@@ -11824,7 +11825,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11824
11825
  const spanName = inputValue.clientType === "pool" ? "pg-pool.query" : "pg.query";
11825
11826
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(this, args), {
11826
11827
  name: spanName,
11827
- kind: import_src$24.SpanKind.CLIENT,
11828
+ kind: import_src$26.SpanKind.CLIENT,
11828
11829
  submodule: "query",
11829
11830
  packageType: PackageType.PG,
11830
11831
  packageName,
@@ -11843,7 +11844,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11843
11844
  const spanName = inputValue.clientType === "pool" ? "pg-pool.query" : "pg.query";
11844
11845
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(this, args), {
11845
11846
  name: spanName,
11846
- kind: import_src$24.SpanKind.CLIENT,
11847
+ kind: import_src$26.SpanKind.CLIENT,
11847
11848
  submodule: "query",
11848
11849
  packageType: PackageType.PG,
11849
11850
  instrumentationName: self.INSTRUMENTATION_NAME,
@@ -11854,7 +11855,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11854
11855
  return self._handleRecordQueryInSpan(spanInfo, originalQuery, queryConfig, args, this);
11855
11856
  });
11856
11857
  },
11857
- spanKind: import_src$24.SpanKind.CLIENT
11858
+ spanKind: import_src$26.SpanKind.CLIENT
11858
11859
  });
11859
11860
  else return originalQuery.apply(this, args);
11860
11861
  };
@@ -11876,7 +11877,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11876
11877
  replayModeHandler: () => {
11877
11878
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
11878
11879
  name: `pg.connect`,
11879
- kind: import_src$24.SpanKind.CLIENT,
11880
+ kind: import_src$26.SpanKind.CLIENT,
11880
11881
  submodule: "connect",
11881
11882
  packageName: "pg",
11882
11883
  packageType: PackageType.PG,
@@ -11893,7 +11894,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11893
11894
  recordModeHandler: ({ isPreAppStart }) => {
11894
11895
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
11895
11896
  name: `pg.connect`,
11896
- kind: import_src$24.SpanKind.CLIENT,
11897
+ kind: import_src$26.SpanKind.CLIENT,
11897
11898
  submodule: "connect",
11898
11899
  packageName: "pg",
11899
11900
  packageType: PackageType.PG,
@@ -11904,7 +11905,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11904
11905
  return self._handleRecordConnectInSpan(spanInfo, originalConnect, callback, this);
11905
11906
  });
11906
11907
  },
11907
- spanKind: import_src$24.SpanKind.CLIENT
11908
+ spanKind: import_src$26.SpanKind.CLIENT
11908
11909
  });
11909
11910
  else return originalConnect.apply(this, [callback]);
11910
11911
  };
@@ -11924,11 +11925,12 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11924
11925
  if (typeof firstArg === "object" && firstArg.text) return {
11925
11926
  text: firstArg.text,
11926
11927
  values: firstArg.values,
11928
+ rowMode: firstArg.rowMode,
11927
11929
  callback: firstArg.callback || (typeof args[1] === "function" ? args[1] : void 0)
11928
11930
  };
11929
11931
  return null;
11930
11932
  }
11931
- _handleRecordQueryInSpan(spanInfo, originalQuery, queryConfig, args, context$4) {
11933
+ _handleRecordQueryInSpan(spanInfo, originalQuery, queryConfig, args, context$6) {
11932
11934
  if (!!queryConfig.callback) {
11933
11935
  const originalCallback = queryConfig.callback;
11934
11936
  const wrappedCallback = (error, result) => {
@@ -11936,7 +11938,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11936
11938
  logger.debug(`[PgInstrumentation] PG query error (hasCallback): ${error.message} (${SpanUtils.getTraceInfo()})`);
11937
11939
  try {
11938
11940
  SpanUtils.endSpan(spanInfo.span, {
11939
- code: import_src$24.SpanStatusCode.ERROR,
11941
+ code: import_src$26.SpanStatusCode.ERROR,
11940
11942
  message: error.message
11941
11943
  });
11942
11944
  } catch (error$1) {
@@ -11946,7 +11948,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11946
11948
  logger.debug(`[PgInstrumentation] PG query completed successfully (hasCallback) (${SpanUtils.getTraceInfo()})`);
11947
11949
  try {
11948
11950
  this._addOutputAttributesToSpan(spanInfo, result);
11949
- SpanUtils.endSpan(spanInfo.span, { code: import_src$24.SpanStatusCode.OK });
11951
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$26.SpanStatusCode.OK });
11950
11952
  } catch (error$1) {
11951
11953
  logger.error(`[PgInstrumentation] error processing response:`, error$1);
11952
11954
  }
@@ -11968,12 +11970,12 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11968
11970
  } catch (error) {
11969
11971
  logger.error(`[PgInstrumentation] error replacing callback:`, error, args);
11970
11972
  }
11971
- return originalQuery.apply(context$4, args);
11972
- } else return originalQuery.apply(context$4, args).then((result) => {
11973
+ return originalQuery.apply(context$6, args);
11974
+ } else return originalQuery.apply(context$6, args).then((result) => {
11973
11975
  logger.debug(`[PgInstrumentation] PG query completed successfully (${SpanUtils.getTraceInfo()})`);
11974
11976
  try {
11975
11977
  this._addOutputAttributesToSpan(spanInfo, result);
11976
- SpanUtils.endSpan(spanInfo.span, { code: import_src$24.SpanStatusCode.OK });
11978
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$26.SpanStatusCode.OK });
11977
11979
  } catch (error) {
11978
11980
  logger.error(`[PgInstrumentation] error processing response:`, error);
11979
11981
  }
@@ -11982,7 +11984,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11982
11984
  logger.debug(`[PgInstrumentation] PG query error: ${error.message} (${SpanUtils.getTraceInfo()})`);
11983
11985
  try {
11984
11986
  SpanUtils.endSpan(spanInfo.span, {
11985
- code: import_src$24.SpanStatusCode.ERROR,
11987
+ code: import_src$26.SpanStatusCode.ERROR,
11986
11988
  message: error.message
11987
11989
  });
11988
11990
  } catch (error$1) {
@@ -12014,7 +12016,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12014
12016
  packageName,
12015
12017
  instrumentationName: this.INSTRUMENTATION_NAME,
12016
12018
  submoduleName: "query",
12017
- kind: import_src$24.SpanKind.CLIENT,
12019
+ kind: import_src$26.SpanKind.CLIENT,
12018
12020
  stackTrace
12019
12021
  },
12020
12022
  tuskDrift: this.tuskDrift
@@ -12024,7 +12026,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12024
12026
  logger.warn(`[PgInstrumentation] No mock data found for PG query: ${queryText}`);
12025
12027
  throw new Error(`[PgInstrumentation] No mock data found for PG query: ${queryText}`);
12026
12028
  }
12027
- const processedResult = this.convertPostgresTypes(mockData.result);
12029
+ const processedResult = this.convertPostgresTypes(mockData.result, inputValue.rowMode);
12028
12030
  if (queryConfig.callback) {
12029
12031
  process.nextTick(() => {
12030
12032
  queryConfig.callback(null, processedResult);
@@ -12033,35 +12035,56 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12033
12035
  } else return Promise.resolve(processedResult);
12034
12036
  }
12035
12037
  /**
12038
+ * Convert a single value based on its PostgreSQL data type.
12039
+ *
12040
+ * Reference for data type IDs: https://jdbc.postgresql.org/documentation/publicapi/constant-values.html
12041
+ */
12042
+ convertPostgresValue(value, dataTypeID) {
12043
+ if (value === null || value === void 0) return value;
12044
+ switch (dataTypeID) {
12045
+ case 1184:
12046
+ case 1114:
12047
+ case 1082:
12048
+ if (typeof value === "string") return new Date(value);
12049
+ break;
12050
+ case 1083:
12051
+ case 1266: break;
12052
+ default: break;
12053
+ }
12054
+ return value;
12055
+ }
12056
+ /**
12036
12057
  * Convert PostgreSQL string values back to appropriate JavaScript types
12037
12058
  * based on field metadata from the recorded response.
12038
12059
  *
12039
12060
  * Reference for data type IDs: https://jdbc.postgresql.org/documentation/publicapi/constant-values.html
12040
12061
  */
12041
- convertPostgresTypes(result) {
12062
+ convertPostgresTypes(result, rowMode) {
12042
12063
  if (!result || !result.fields || !result.rows) return result;
12064
+ if (rowMode === "array") {
12065
+ const convertedRows$1 = result.rows.map((row) => {
12066
+ if (!Array.isArray(row)) return row;
12067
+ return row.map((value, index) => {
12068
+ const field = result.fields[index];
12069
+ if (!field) return value;
12070
+ return this.convertPostgresValue(value, field.dataTypeID);
12071
+ });
12072
+ });
12073
+ return {
12074
+ ...result,
12075
+ rows: convertedRows$1
12076
+ };
12077
+ }
12043
12078
  const fieldTypeMap = {};
12044
12079
  result.fields.forEach((field) => {
12045
12080
  fieldTypeMap[field.name] = field.dataTypeID;
12046
12081
  });
12047
- const convertedRows = result.rows.map((row, rowIndex) => {
12082
+ const convertedRows = result.rows.map((row) => {
12048
12083
  const convertedRow = { ...row };
12049
12084
  Object.keys(row).forEach((fieldName) => {
12050
12085
  const dataTypeID = fieldTypeMap[fieldName];
12051
12086
  const value = row[fieldName];
12052
- if (value === null || value === void 0) return;
12053
- switch (dataTypeID) {
12054
- case 1184:
12055
- case 1114:
12056
- if (typeof value === "string") convertedRow[fieldName] = new Date(value);
12057
- break;
12058
- case 1082:
12059
- if (typeof value === "string") convertedRow[fieldName] = new Date(value);
12060
- break;
12061
- case 1083:
12062
- case 1266: break;
12063
- default: break;
12064
- }
12087
+ convertedRow[fieldName] = this.convertPostgresValue(value, dataTypeID);
12065
12088
  });
12066
12089
  return convertedRow;
12067
12090
  });
@@ -12070,14 +12093,14 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12070
12093
  rows: convertedRows
12071
12094
  };
12072
12095
  }
12073
- _handleRecordConnectInSpan(spanInfo, originalConnect, callback, context$4) {
12096
+ _handleRecordConnectInSpan(spanInfo, originalConnect, callback, context$6) {
12074
12097
  if (callback) {
12075
12098
  const wrappedCallback = (error) => {
12076
12099
  if (error) {
12077
12100
  logger.debug(`[PgInstrumentation] PG connect error: ${error.message} (${SpanUtils.getTraceInfo()})`);
12078
12101
  try {
12079
12102
  SpanUtils.endSpan(spanInfo.span, {
12080
- code: import_src$24.SpanStatusCode.ERROR,
12103
+ code: import_src$26.SpanStatusCode.ERROR,
12081
12104
  message: error.message
12082
12105
  });
12083
12106
  } catch (error$1) {
@@ -12087,19 +12110,19 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12087
12110
  logger.debug(`[PgInstrumentation] PG connect completed successfully (${SpanUtils.getTraceInfo()})`);
12088
12111
  try {
12089
12112
  SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: { connected: true } });
12090
- SpanUtils.endSpan(spanInfo.span, { code: import_src$24.SpanStatusCode.OK });
12113
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$26.SpanStatusCode.OK });
12091
12114
  } catch (error$1) {
12092
12115
  logger.error(`[PgInstrumentation] error processing connect response:`, error$1);
12093
12116
  }
12094
12117
  }
12095
12118
  return callback(error);
12096
12119
  };
12097
- return originalConnect.call(context$4, wrappedCallback);
12098
- } else return originalConnect.call(context$4).then((result) => {
12120
+ return originalConnect.call(context$6, wrappedCallback);
12121
+ } else return originalConnect.call(context$6).then((result) => {
12099
12122
  logger.debug(`[PgInstrumentation] PG connect completed successfully (${SpanUtils.getTraceInfo()})`);
12100
12123
  try {
12101
12124
  SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: { connected: true } });
12102
- SpanUtils.endSpan(spanInfo.span, { code: import_src$24.SpanStatusCode.OK });
12125
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$26.SpanStatusCode.OK });
12103
12126
  } catch (error) {
12104
12127
  logger.error(`[PgInstrumentation] error processing connect response:`, error);
12105
12128
  }
@@ -12108,7 +12131,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12108
12131
  logger.debug(`[PgInstrumentation] PG connect error: ${error.message} (${SpanUtils.getTraceInfo()})`);
12109
12132
  try {
12110
12133
  SpanUtils.endSpan(spanInfo.span, {
12111
- code: import_src$24.SpanStatusCode.ERROR,
12134
+ code: import_src$26.SpanStatusCode.ERROR,
12112
12135
  message: error.message
12113
12136
  });
12114
12137
  } catch (error$1) {
@@ -12169,7 +12192,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12169
12192
  replayModeHandler: () => {
12170
12193
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
12171
12194
  name: `pg-pool.connect`,
12172
- kind: import_src$24.SpanKind.CLIENT,
12195
+ kind: import_src$26.SpanKind.CLIENT,
12173
12196
  submodule: "connect",
12174
12197
  packageName: "pg-pool",
12175
12198
  packageType: PackageType.PG,
@@ -12186,7 +12209,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12186
12209
  recordModeHandler: ({ isPreAppStart }) => {
12187
12210
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
12188
12211
  name: `pg-pool.connect`,
12189
- kind: import_src$24.SpanKind.CLIENT,
12212
+ kind: import_src$26.SpanKind.CLIENT,
12190
12213
  submodule: "connect",
12191
12214
  packageName: "pg-pool",
12192
12215
  packageType: PackageType.PG,
@@ -12197,20 +12220,20 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12197
12220
  return self._handleRecordPoolConnectInSpan(spanInfo, originalConnect, callback, this);
12198
12221
  });
12199
12222
  },
12200
- spanKind: import_src$24.SpanKind.CLIENT
12223
+ spanKind: import_src$26.SpanKind.CLIENT
12201
12224
  });
12202
12225
  else return originalConnect.apply(this, [callback]);
12203
12226
  };
12204
12227
  };
12205
12228
  }
12206
- _handleRecordPoolConnectInSpan(spanInfo, originalConnect, callback, context$4) {
12229
+ _handleRecordPoolConnectInSpan(spanInfo, originalConnect, callback, context$6) {
12207
12230
  if (callback) {
12208
12231
  const wrappedCallback = (error, client, done) => {
12209
12232
  if (error) {
12210
12233
  logger.debug(`[PgInstrumentation] PG Pool connect error: ${error.message} (${SpanUtils.getTraceInfo()})`);
12211
12234
  try {
12212
12235
  SpanUtils.endSpan(spanInfo.span, {
12213
- code: import_src$24.SpanStatusCode.ERROR,
12236
+ code: import_src$26.SpanStatusCode.ERROR,
12214
12237
  message: error.message
12215
12238
  });
12216
12239
  } catch (error$1) {
@@ -12223,22 +12246,22 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12223
12246
  connected: true,
12224
12247
  hasClient: !!client
12225
12248
  } });
12226
- SpanUtils.endSpan(spanInfo.span, { code: import_src$24.SpanStatusCode.OK });
12249
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$26.SpanStatusCode.OK });
12227
12250
  } catch (error$1) {
12228
12251
  logger.error(`[PgInstrumentation] error processing pool connect response:`, error$1);
12229
12252
  }
12230
12253
  }
12231
12254
  return callback(error, client, done);
12232
12255
  };
12233
- return originalConnect.call(context$4, wrappedCallback);
12234
- } else return originalConnect.call(context$4).then((client) => {
12256
+ return originalConnect.call(context$6, wrappedCallback);
12257
+ } else return originalConnect.call(context$6).then((client) => {
12235
12258
  logger.debug(`[PgInstrumentation] PG Pool connect completed successfully (${SpanUtils.getTraceInfo()})`);
12236
12259
  try {
12237
12260
  SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: {
12238
12261
  connected: true,
12239
12262
  hasClient: !!client
12240
12263
  } });
12241
- SpanUtils.endSpan(spanInfo.span, { code: import_src$24.SpanStatusCode.OK });
12264
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$26.SpanStatusCode.OK });
12242
12265
  } catch (error) {
12243
12266
  logger.error(`[PgInstrumentation] error processing pool connect response:`, error);
12244
12267
  }
@@ -12247,7 +12270,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12247
12270
  logger.debug(`[PgInstrumentation] PG Pool connect error: ${error.message} (${SpanUtils.getTraceInfo()})`);
12248
12271
  try {
12249
12272
  SpanUtils.endSpan(spanInfo.span, {
12250
- code: import_src$24.SpanStatusCode.ERROR,
12273
+ code: import_src$26.SpanStatusCode.ERROR,
12251
12274
  message: error.message
12252
12275
  });
12253
12276
  } catch (error$1) {
@@ -12272,17 +12295,12 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12272
12295
  //#endregion
12273
12296
  //#region src/instrumentation/libraries/postgres/types.ts
12274
12297
  function isPostgresOutputValueType(value) {
12275
- return value !== null && value !== void 0 && typeof value === "object" && "_tdOriginalFormat" in value && Object.values(PostgresReturnType).includes(value._tdOriginalFormat);
12298
+ return value !== null && value !== void 0 && typeof value === "object";
12276
12299
  }
12277
- let PostgresReturnType = /* @__PURE__ */ function(PostgresReturnType$1) {
12278
- PostgresReturnType$1["ARRAY"] = "array";
12279
- PostgresReturnType$1["OBJECT"] = "object";
12280
- return PostgresReturnType$1;
12281
- }({});
12282
12300
 
12283
12301
  //#endregion
12284
12302
  //#region src/instrumentation/libraries/postgres/Instrumentation.ts
12285
- var import_src$23 = /* @__PURE__ */ __toESM(require_src$7(), 1);
12303
+ var import_src$25 = /* @__PURE__ */ __toESM(require_src$7(), 1);
12286
12304
  var PostgresInstrumentation = class extends TdInstrumentationBase {
12287
12305
  constructor(config = {}) {
12288
12306
  super("postgres", config);
@@ -12346,13 +12364,17 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12346
12364
  };
12347
12365
  if (this.mode === TuskDriftMode.REPLAY) return handleReplayMode({
12348
12366
  noOpRequestHandler: () => {
12349
- try {
12350
- const sqlInstance = originalFunction(...args);
12351
- return this._wrapSqlInstance(sqlInstance);
12352
- } catch (error) {
12353
- logger.debug(`[PostgresInstrumentation] Postgres connection error in replay: ${error.message}`);
12354
- throw error;
12355
- }
12367
+ const mockSql = () => Promise.resolve(Object.assign([], {
12368
+ count: 0,
12369
+ command: null
12370
+ }));
12371
+ mockSql.unsafe = () => Promise.resolve(Object.assign([], {
12372
+ count: 0,
12373
+ command: null
12374
+ }));
12375
+ mockSql.begin = () => Promise.resolve();
12376
+ mockSql.end = () => Promise.resolve();
12377
+ return mockSql;
12356
12378
  },
12357
12379
  isServerRequest: false,
12358
12380
  replayModeHandler: () => {
@@ -12361,7 +12383,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12361
12383
  return this._wrapSqlInstance(sqlInstance);
12362
12384
  }, {
12363
12385
  name: "postgres.connect",
12364
- kind: import_src$23.SpanKind.CLIENT,
12386
+ kind: import_src$25.SpanKind.CLIENT,
12365
12387
  submodule: "connect",
12366
12388
  packageType: PackageType.PG,
12367
12389
  packageName: "postgres",
@@ -12384,7 +12406,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12384
12406
  return this._wrapSqlInstance(sqlInstance);
12385
12407
  }, {
12386
12408
  name: "postgres.connect",
12387
- kind: import_src$23.SpanKind.CLIENT,
12409
+ kind: import_src$25.SpanKind.CLIENT,
12388
12410
  submodule: "connect",
12389
12411
  packageType: PackageType.PG,
12390
12412
  packageName: "postgres",
@@ -12395,7 +12417,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12395
12417
  return this._handleRecordConnect(spanInfo, originalFunction, args);
12396
12418
  });
12397
12419
  },
12398
- spanKind: import_src$23.SpanKind.CLIENT
12420
+ spanKind: import_src$25.SpanKind.CLIENT
12399
12421
  });
12400
12422
  else return originalFunction(...args);
12401
12423
  }
@@ -12426,7 +12448,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12426
12448
  try {
12427
12449
  logger.debug(`[PostgresInstrumentation] Postgres connection created successfully (${SpanUtils.getTraceInfo()})`);
12428
12450
  SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: { connected: true } });
12429
- SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
12451
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$25.SpanStatusCode.OK });
12430
12452
  } catch (error) {
12431
12453
  logger.error(`[PostgresInstrumentation] error adding span attributes:`, error);
12432
12454
  }
@@ -12487,121 +12509,189 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12487
12509
  };
12488
12510
  }
12489
12511
  _handleSqlQuery(originalSql, strings, values) {
12490
- let query = "";
12491
- for (let i = 0; i < strings.length; i++) {
12492
- query += strings[i];
12493
- if (i < values.length) query += `$${i + 1}`;
12494
- }
12495
- const inputValue = {
12496
- query: query.trim(),
12497
- parameters: values
12498
- };
12499
- if (this.mode === TuskDriftMode.REPLAY) {
12500
- const stackTrace = captureStackTrace(["PostgresInstrumentation"]);
12501
- return handleReplayMode({
12502
- noOpRequestHandler: () => {},
12503
- isServerRequest: false,
12504
- replayModeHandler: () => {
12505
- return SpanUtils.createAndExecuteSpan(this.mode, () => originalSql.call(this, strings, ...values), {
12506
- name: "postgres.query",
12507
- kind: import_src$23.SpanKind.CLIENT,
12508
- submodule: "query",
12509
- packageType: PackageType.PG,
12510
- packageName: "postgres",
12511
- instrumentationName: this.INSTRUMENTATION_NAME,
12512
- inputValue,
12513
- isPreAppStart: false
12514
- }, (spanInfo) => {
12515
- return this.handleReplaySqlQuery({
12516
- inputValue,
12517
- spanInfo,
12518
- submodule: "query",
12512
+ if (!strings || !Array.isArray(strings.raw)) return originalSql.call(this, strings, ...values);
12513
+ const creationContext = import_src$25.context.active();
12514
+ const query = originalSql.call(this, strings, ...values);
12515
+ const originalThen = query.then.bind(query);
12516
+ const self = this;
12517
+ query.then = function(onFulfilled, onRejected) {
12518
+ let queryString = "";
12519
+ for (let i = 0; i < strings.length; i++) {
12520
+ queryString += strings[i];
12521
+ if (i < values.length) queryString += `$${i + 1}`;
12522
+ }
12523
+ const inputValue = {
12524
+ query: queryString.trim(),
12525
+ parameters: values
12526
+ };
12527
+ return import_src$25.context.with(creationContext, () => {
12528
+ if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
12529
+ originalFunctionCall: () => originalThen(onFulfilled, onRejected),
12530
+ recordModeHandler: ({ isPreAppStart }) => {
12531
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalThen(onFulfilled, onRejected), {
12519
12532
  name: "postgres.query",
12520
- stackTrace
12533
+ kind: import_src$25.SpanKind.CLIENT,
12534
+ submodule: "query",
12535
+ packageType: PackageType.PG,
12536
+ instrumentationName: self.INSTRUMENTATION_NAME,
12537
+ packageName: "postgres",
12538
+ inputValue,
12539
+ isPreAppStart
12540
+ }, (spanInfo) => {
12541
+ const wrappedOnFulfilled = (result) => {
12542
+ try {
12543
+ logger.debug(`[PostgresInstrumentation] Postgres query completed successfully`, result);
12544
+ self._addOutputAttributesToSpan(spanInfo, result);
12545
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$25.SpanStatusCode.OK });
12546
+ } catch (error) {
12547
+ logger.error(`[PostgresInstrumentation] error processing query response:`, error);
12548
+ }
12549
+ return onFulfilled ? onFulfilled(result) : result;
12550
+ };
12551
+ const wrappedOnRejected = (error) => {
12552
+ try {
12553
+ logger.debug(`[PostgresInstrumentation] Postgres query error`, error);
12554
+ SpanUtils.endSpan(spanInfo.span, {
12555
+ code: import_src$25.SpanStatusCode.ERROR,
12556
+ message: error.message
12557
+ });
12558
+ } catch (spanError) {
12559
+ logger.error(`[PostgresInstrumentation] error ending span:`, spanError);
12560
+ }
12561
+ if (onRejected) return onRejected(error);
12562
+ throw error;
12563
+ };
12564
+ return originalThen(wrappedOnFulfilled, wrappedOnRejected);
12521
12565
  });
12566
+ },
12567
+ spanKind: import_src$25.SpanKind.CLIENT
12568
+ });
12569
+ else if (self.mode === TuskDriftMode.REPLAY) {
12570
+ const stackTrace = captureStackTrace(["PostgresInstrumentation"]);
12571
+ return handleReplayMode({
12572
+ noOpRequestHandler: () => Promise.resolve(Object.assign([], {
12573
+ count: 0,
12574
+ command: null
12575
+ })),
12576
+ isServerRequest: false,
12577
+ replayModeHandler: () => {
12578
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalThen(onFulfilled, onRejected), {
12579
+ name: "postgres.query",
12580
+ kind: import_src$25.SpanKind.CLIENT,
12581
+ submodule: "query",
12582
+ packageType: PackageType.PG,
12583
+ packageName: "postgres",
12584
+ instrumentationName: self.INSTRUMENTATION_NAME,
12585
+ inputValue,
12586
+ isPreAppStart: false
12587
+ }, async (spanInfo) => {
12588
+ const mockedResult = await self.handleReplaySqlQuery({
12589
+ inputValue,
12590
+ spanInfo,
12591
+ submodule: "query",
12592
+ name: "postgres.query",
12593
+ stackTrace
12594
+ });
12595
+ return onFulfilled ? onFulfilled(mockedResult) : mockedResult;
12596
+ });
12597
+ }
12522
12598
  });
12523
- }
12599
+ } else return originalThen(onFulfilled, onRejected);
12524
12600
  });
12525
- } else if (this.mode === TuskDriftMode.RECORD) return handleRecordMode({
12526
- originalFunctionCall: () => originalSql.call(this, strings, ...values),
12527
- recordModeHandler: ({ isPreAppStart }) => {
12528
- return SpanUtils.createAndExecuteSpan(this.mode, () => originalSql.call(this, strings, ...values), {
12529
- name: "postgres.query",
12530
- kind: import_src$23.SpanKind.CLIENT,
12531
- submodule: "query",
12532
- packageType: PackageType.PG,
12533
- instrumentationName: this.INSTRUMENTATION_NAME,
12534
- packageName: "postgres",
12535
- inputValue,
12536
- isPreAppStart
12537
- }, (spanInfo) => {
12538
- return this._handleRecordQueryInSpan(spanInfo, originalSql, strings, values);
12539
- });
12540
- },
12541
- spanKind: import_src$23.SpanKind.CLIENT
12542
- });
12543
- else return originalSql.call(this, strings, ...values);
12601
+ };
12602
+ return query;
12544
12603
  }
12545
12604
  _handleUnsafeQuery(sqlInstance, originalUnsafe, query, parameters, queryOptions) {
12546
- const executeUnsafe = () => {
12605
+ const unsafeQuery = (() => {
12547
12606
  if (queryOptions !== void 0) return originalUnsafe.call(sqlInstance, query, parameters, queryOptions);
12548
12607
  else if (parameters !== void 0) return originalUnsafe.call(sqlInstance, query, parameters);
12549
12608
  else return originalUnsafe.call(sqlInstance, query);
12550
- };
12609
+ })();
12610
+ const creationContext = import_src$25.context.active();
12611
+ const originalThen = unsafeQuery.then.bind(unsafeQuery);
12612
+ const self = this;
12551
12613
  const inputValue = {
12552
12614
  query: query.trim(),
12553
12615
  parameters: parameters || [],
12554
12616
  options: queryOptions
12555
12617
  };
12556
- if (this.mode === TuskDriftMode.REPLAY) {
12557
- const stackTrace = captureStackTrace(["PostgresInstrumentation"]);
12558
- return handleReplayMode({
12559
- noOpRequestHandler: () => {
12560
- return Promise.resolve(void 0);
12561
- },
12562
- isServerRequest: false,
12563
- replayModeHandler: () => {
12564
- return this._createPendingQueryWrapper(() => {
12565
- return SpanUtils.createAndExecuteSpan(this.mode, () => executeUnsafe(), {
12618
+ unsafeQuery.then = function(onFulfilled, onRejected) {
12619
+ return import_src$25.context.with(creationContext, () => {
12620
+ if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
12621
+ originalFunctionCall: () => originalThen(onFulfilled, onRejected),
12622
+ recordModeHandler: ({ isPreAppStart }) => {
12623
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalThen(onFulfilled, onRejected), {
12566
12624
  name: "postgres.unsafe",
12567
- kind: import_src$23.SpanKind.CLIENT,
12625
+ kind: import_src$25.SpanKind.CLIENT,
12568
12626
  submodule: "unsafe",
12569
12627
  packageType: PackageType.PG,
12570
12628
  packageName: "postgres",
12571
- instrumentationName: this.INSTRUMENTATION_NAME,
12629
+ instrumentationName: self.INSTRUMENTATION_NAME,
12572
12630
  inputValue,
12573
- isPreAppStart: false
12631
+ isPreAppStart
12574
12632
  }, (spanInfo) => {
12575
- return this.handleReplayUnsafeQuery({
12576
- inputValue,
12577
- spanInfo,
12578
- submodule: "unsafe",
12633
+ const wrappedOnFulfilled = (result) => {
12634
+ try {
12635
+ logger.debug(`[PostgresInstrumentation] Postgres unsafe query completed successfully (${SpanUtils.getTraceInfo()})`);
12636
+ self._addOutputAttributesToSpan(spanInfo, result);
12637
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$25.SpanStatusCode.OK });
12638
+ } catch (error) {
12639
+ logger.error(`[PostgresInstrumentation] error processing unsafe query response:`, error);
12640
+ }
12641
+ return onFulfilled ? onFulfilled(result) : result;
12642
+ };
12643
+ const wrappedOnRejected = (error) => {
12644
+ try {
12645
+ logger.debug(`[PostgresInstrumentation] Postgres unsafe query error: ${error.message}`);
12646
+ SpanUtils.endSpan(spanInfo.span, {
12647
+ code: import_src$25.SpanStatusCode.ERROR,
12648
+ message: error.message
12649
+ });
12650
+ } catch (spanError) {
12651
+ logger.error(`[PostgresInstrumentation] error ending span:`, spanError);
12652
+ }
12653
+ if (onRejected) return onRejected(error);
12654
+ throw error;
12655
+ };
12656
+ return originalThen(wrappedOnFulfilled, wrappedOnRejected);
12657
+ });
12658
+ },
12659
+ spanKind: import_src$25.SpanKind.CLIENT
12660
+ });
12661
+ else if (self.mode === TuskDriftMode.REPLAY) {
12662
+ const stackTrace = captureStackTrace(["PostgresInstrumentation"]);
12663
+ return handleReplayMode({
12664
+ noOpRequestHandler: () => Promise.resolve(Object.assign([], {
12665
+ count: 0,
12666
+ command: null
12667
+ })),
12668
+ isServerRequest: false,
12669
+ replayModeHandler: () => {
12670
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalThen(onFulfilled, onRejected), {
12579
12671
  name: "postgres.unsafe",
12580
- stackTrace
12672
+ kind: import_src$25.SpanKind.CLIENT,
12673
+ submodule: "unsafe",
12674
+ packageType: PackageType.PG,
12675
+ packageName: "postgres",
12676
+ instrumentationName: self.INSTRUMENTATION_NAME,
12677
+ inputValue,
12678
+ isPreAppStart: false
12679
+ }, async (spanInfo) => {
12680
+ const mockedResult = await self.handleReplayUnsafeQuery({
12681
+ inputValue,
12682
+ spanInfo,
12683
+ submodule: "unsafe",
12684
+ name: "postgres.unsafe",
12685
+ stackTrace
12686
+ });
12687
+ return onFulfilled ? onFulfilled(mockedResult) : mockedResult;
12581
12688
  });
12582
- });
12689
+ }
12583
12690
  });
12584
- }
12691
+ } else return originalThen(onFulfilled, onRejected);
12585
12692
  });
12586
- } else if (this.mode === TuskDriftMode.RECORD) return handleRecordMode({
12587
- originalFunctionCall: executeUnsafe,
12588
- recordModeHandler: ({ isPreAppStart }) => {
12589
- return SpanUtils.createAndExecuteSpan(this.mode, executeUnsafe, {
12590
- name: "postgres.unsafe",
12591
- kind: import_src$23.SpanKind.CLIENT,
12592
- submodule: "unsafe",
12593
- packageType: PackageType.PG,
12594
- packageName: "postgres",
12595
- instrumentationName: this.INSTRUMENTATION_NAME,
12596
- inputValue,
12597
- isPreAppStart
12598
- }, (spanInfo) => {
12599
- return this._executeThenAddOutputAttributes(spanInfo, executeUnsafe);
12600
- });
12601
- },
12602
- spanKind: import_src$23.SpanKind.CLIENT
12603
- });
12604
- else return executeUnsafe();
12693
+ };
12694
+ return unsafeQuery;
12605
12695
  }
12606
12696
  _handleBeginTransaction(sqlInstance, originalBegin, options, transactionCallback) {
12607
12697
  const inputValue = {
@@ -12616,12 +12706,12 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12616
12706
  if (this.mode === TuskDriftMode.REPLAY) {
12617
12707
  const stackTrace = captureStackTrace(["PostgresInstrumentation"]);
12618
12708
  return handleReplayMode({
12619
- noOpRequestHandler: () => {},
12709
+ noOpRequestHandler: () => Promise.resolve(),
12620
12710
  isServerRequest: false,
12621
12711
  replayModeHandler: () => {
12622
12712
  return SpanUtils.createAndExecuteSpan(this.mode, () => executeBegin(), {
12623
12713
  name: "postgres.begin",
12624
- kind: import_src$23.SpanKind.CLIENT,
12714
+ kind: import_src$25.SpanKind.CLIENT,
12625
12715
  submodule: "transaction",
12626
12716
  packageType: PackageType.PG,
12627
12717
  packageName: "postgres",
@@ -12638,7 +12728,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12638
12728
  recordModeHandler: ({ isPreAppStart }) => {
12639
12729
  return SpanUtils.createAndExecuteSpan(this.mode, executeBegin, {
12640
12730
  name: "postgres.begin",
12641
- kind: import_src$23.SpanKind.CLIENT,
12731
+ kind: import_src$25.SpanKind.CLIENT,
12642
12732
  submodule: "transaction",
12643
12733
  packageType: PackageType.PG,
12644
12734
  packageName: "postgres",
@@ -12649,52 +12739,10 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12649
12739
  return this._handleRecordBeginTransaction(spanInfo, executeBegin);
12650
12740
  });
12651
12741
  },
12652
- spanKind: import_src$23.SpanKind.CLIENT
12742
+ spanKind: import_src$25.SpanKind.CLIENT
12653
12743
  });
12654
12744
  else return executeBegin();
12655
12745
  }
12656
- /**
12657
- * Execute postgres.js unsafe query and create span afterwards.
12658
- *
12659
- * postgres.js has sophisticated internal session and connection management
12660
- * that is extremely sensitive to async context changes. Unlike the regular 'pg' library,
12661
- * postgres.js maintains internal state using promise identity and async context tracking.
12662
- *
12663
- * The issue: promise chain modification breaks postgres.js.
12664
- * Calling .then()/.catch() creates new promise objects, breaking postgres.js's internal tracking
12665
- *
12666
- * Solution: We must execute the postgres.js query in its completely unmodified context:
12667
- * - Return the original promise object unchanged
12668
- * - Use promise.finally() to track completion without creating a new promise chain
12669
- *
12670
- * This preserves postgres.js's internal session management while still providing tracing.
12671
- * The 'pg' library doesn't have this issue because it has simpler internal state management.
12672
- */
12673
- _executeThenAddOutputAttributes(spanInfo, executeUnsafe) {
12674
- const promise = executeUnsafe();
12675
- promise.finally(() => {
12676
- promise.then((result) => {
12677
- logger.debug(`[PostgresInstrumentation] Postgres unsafe query completed successfully`);
12678
- try {
12679
- this._addOutputAttributesToSpan(spanInfo, result);
12680
- SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
12681
- } catch (error) {
12682
- logger.error(`[PostgresInstrumentation] error processing unsafe query response:`, error);
12683
- }
12684
- }).catch((error) => {
12685
- logger.debug(`[PostgresInstrumentation] Postgres unsafe query error: ${error.message}`);
12686
- try {
12687
- SpanUtils.endSpan(spanInfo.span, {
12688
- code: import_src$23.SpanStatusCode.ERROR,
12689
- message: error.message
12690
- });
12691
- } catch (error$1) {
12692
- logger.error(`[PostgresInstrumentation] error ending span:`, error$1);
12693
- }
12694
- });
12695
- });
12696
- return promise;
12697
- }
12698
12746
  _handleRecordBeginTransaction(spanInfo, executeBegin) {
12699
12747
  const promise = executeBegin();
12700
12748
  promise.finally(() => {
@@ -12705,7 +12753,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12705
12753
  status: "committed",
12706
12754
  result
12707
12755
  } });
12708
- SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
12756
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$25.SpanStatusCode.OK });
12709
12757
  } catch (error) {
12710
12758
  logger.error(`[PostgresInstrumentation] error processing transaction response:`, error);
12711
12759
  }
@@ -12717,7 +12765,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12717
12765
  error: error.message
12718
12766
  } });
12719
12767
  SpanUtils.endSpan(spanInfo.span, {
12720
- code: import_src$23.SpanStatusCode.ERROR,
12768
+ code: import_src$25.SpanStatusCode.ERROR,
12721
12769
  message: error.message
12722
12770
  });
12723
12771
  } catch (spanError) {
@@ -12727,187 +12775,1712 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12727
12775
  });
12728
12776
  return promise;
12729
12777
  }
12730
- async _handleReplayBeginTransaction(spanInfo, options, stackTrace) {
12731
- logger.debug(`[PostgresInstrumentation] Replaying Postgres transaction`);
12732
- const mockData = await findMockResponseAsync({
12733
- mockRequestData: {
12734
- traceId: spanInfo.traceId,
12735
- spanId: spanInfo.spanId,
12736
- name: "postgres.begin",
12737
- inputValue: {
12738
- query: "BEGIN",
12739
- options: options ? { transactionOptions: options } : void 0
12740
- },
12741
- packageName: "postgres",
12742
- instrumentationName: this.INSTRUMENTATION_NAME,
12743
- submoduleName: "transaction",
12744
- kind: import_src$23.SpanKind.CLIENT,
12745
- stackTrace
12746
- },
12747
- tuskDrift: this.tuskDrift
12748
- });
12749
- if (!mockData) {
12750
- logger.warn(`[PostgresInstrumentation] No mock data found for transaction BEGIN`);
12751
- throw new Error(`[PostgresInstrumentation] No matching mock found for transaction BEGIN`);
12752
- }
12753
- logger.debug(`[PostgresInstrumentation] Found mock data for transaction: ${JSON.stringify(mockData)}`);
12754
- const transactionResult = mockData.result;
12755
- if (transactionResult && typeof transactionResult === "object" && "status" in transactionResult && transactionResult.status === "committed") return transactionResult.result;
12756
- else {
12757
- const errorMessage = transactionResult && typeof transactionResult === "object" && "error" in transactionResult && transactionResult.error ? transactionResult.error : "Transaction rolled back";
12758
- throw new Error(errorMessage);
12759
- }
12778
+ async _handleReplayBeginTransaction(spanInfo, options, stackTrace) {
12779
+ logger.debug(`[PostgresInstrumentation] Replaying Postgres transaction`);
12780
+ const mockData = await findMockResponseAsync({
12781
+ mockRequestData: {
12782
+ traceId: spanInfo.traceId,
12783
+ spanId: spanInfo.spanId,
12784
+ name: "postgres.begin",
12785
+ inputValue: createMockInputValue({
12786
+ query: "BEGIN",
12787
+ options: options ? { transactionOptions: options } : void 0
12788
+ }),
12789
+ packageName: "postgres",
12790
+ instrumentationName: this.INSTRUMENTATION_NAME,
12791
+ submoduleName: "transaction",
12792
+ kind: import_src$25.SpanKind.CLIENT,
12793
+ stackTrace
12794
+ },
12795
+ tuskDrift: this.tuskDrift
12796
+ });
12797
+ if (!mockData) {
12798
+ logger.warn(`[PostgresInstrumentation] No mock data found for transaction BEGIN`);
12799
+ throw new Error(`[PostgresInstrumentation] No matching mock found for transaction BEGIN`);
12800
+ }
12801
+ logger.debug(`[PostgresInstrumentation] Found mock data for transaction: ${JSON.stringify(mockData)}`);
12802
+ const transactionResult = mockData.result;
12803
+ if (transactionResult && typeof transactionResult === "object" && "status" in transactionResult && transactionResult.status === "committed") return transactionResult.result;
12804
+ else {
12805
+ const errorMessage = transactionResult && typeof transactionResult === "object" && "error" in transactionResult && transactionResult.error ? transactionResult.error : "Transaction rolled back";
12806
+ throw new Error(errorMessage);
12807
+ }
12808
+ }
12809
+ async handleReplaySqlQuery({ inputValue, spanInfo, submodule, name, stackTrace }) {
12810
+ logger.debug(`[PostgresInstrumentation] Replaying Postgres sql query`);
12811
+ const mockData = await findMockResponseAsync({
12812
+ mockRequestData: {
12813
+ traceId: spanInfo.traceId,
12814
+ spanId: spanInfo.spanId,
12815
+ name,
12816
+ inputValue: createMockInputValue(inputValue),
12817
+ packageName: "postgres",
12818
+ instrumentationName: this.INSTRUMENTATION_NAME,
12819
+ submoduleName: submodule,
12820
+ kind: import_src$25.SpanKind.CLIENT,
12821
+ stackTrace
12822
+ },
12823
+ tuskDrift: this.tuskDrift
12824
+ });
12825
+ if (!mockData) {
12826
+ const queryText = inputValue.query || "UNKNOWN_QUERY";
12827
+ logger.warn(`[PostgresInstrumentation] No mock data found for Postgres sql query: ${queryText}`);
12828
+ throw new Error(`[PostgresInstrumentation] No matching mock found for Postgres sql query: ${queryText}`);
12829
+ }
12830
+ logger.debug(`[PostgresInstrumentation] Found mock data for Postgres sql query: ${JSON.stringify(mockData)}`);
12831
+ const processedResult = this.convertPostgresTypes(mockData.result);
12832
+ logger.debug(`[PostgresInstrumentation] Sql query processed result: ${JSON.stringify(processedResult)}`);
12833
+ return processedResult;
12834
+ }
12835
+ async handleReplayUnsafeQuery({ inputValue, spanInfo, submodule, name, stackTrace }) {
12836
+ logger.debug(`[PostgresInstrumentation] Replaying Postgres unsafe query`);
12837
+ const mockData = await findMockResponseAsync({
12838
+ mockRequestData: {
12839
+ traceId: spanInfo.traceId,
12840
+ spanId: spanInfo.spanId,
12841
+ name,
12842
+ inputValue: createMockInputValue(inputValue),
12843
+ packageName: "postgres",
12844
+ instrumentationName: this.INSTRUMENTATION_NAME,
12845
+ submoduleName: submodule,
12846
+ kind: import_src$25.SpanKind.CLIENT,
12847
+ stackTrace
12848
+ },
12849
+ tuskDrift: this.tuskDrift
12850
+ });
12851
+ if (!mockData) {
12852
+ const queryText = inputValue.query || "UNKNOWN_QUERY";
12853
+ logger.warn(`[PostgresInstrumentation] No mock data found for Postgres unsafe query: ${queryText}`);
12854
+ throw new Error(`[PostgresInstrumentation] No matching mock found for Postgres unsafe query: ${queryText}`);
12855
+ }
12856
+ logger.debug(`[PostgresInstrumentation] Found mock data for Postgres unsafe query: ${JSON.stringify(mockData)}`);
12857
+ const processedResult = this.convertPostgresTypes(mockData.result);
12858
+ logger.debug(`[PostgresInstrumentation] Unsafe query processed result: ${JSON.stringify(processedResult)}`);
12859
+ return processedResult;
12860
+ }
12861
+ convertPostgresTypes(result) {
12862
+ if (!isPostgresOutputValueType(result)) {
12863
+ logger.error(`[PostgresInstrumentation] output value is not of type PostgresOutputValueType`, result);
12864
+ return;
12865
+ }
12866
+ const { rows, count, command } = result;
12867
+ const resultArray = Array.from(rows || []);
12868
+ Object.defineProperties(resultArray, {
12869
+ count: {
12870
+ value: count !== void 0 ? count : null,
12871
+ writable: true,
12872
+ enumerable: false
12873
+ },
12874
+ command: {
12875
+ value: command || null,
12876
+ writable: true,
12877
+ enumerable: false
12878
+ }
12879
+ });
12880
+ return resultArray;
12881
+ }
12882
+ _addOutputAttributesToSpan(spanInfo, result) {
12883
+ if (!result) return;
12884
+ const isArray$1 = Array.isArray(result);
12885
+ logger.debug(`[PostgresInstrumentation] Adding output attributes to span for ${isArray$1 ? "array" : "object"} result`);
12886
+ const outputValue = {
12887
+ rows: isArray$1 ? Array.from(result) : result.rows || [],
12888
+ count: result.count !== void 0 && result.count !== null ? result.count : void 0,
12889
+ command: result.command || void 0
12890
+ };
12891
+ SpanUtils.addSpanAttributes(spanInfo.span, { outputValue });
12892
+ }
12893
+ _wrap(target, propertyName, wrapper) {
12894
+ wrap(target, propertyName, wrapper);
12895
+ }
12896
+ };
12897
+
12898
+ //#endregion
12899
+ //#region src/instrumentation/libraries/mysql/types.ts
12900
+ /**
12901
+ * Helper to check if a result is an OkPacket
12902
+ */
12903
+ function isMysqlOkPacket(result) {
12904
+ return result && typeof result === "object" && "affectedRows" in result && "insertId" in result && "fieldCount" in result;
12905
+ }
12906
+
12907
+ //#endregion
12908
+ //#region src/instrumentation/libraries/mysql/mocks/TdMysqlConnectionMock.ts
12909
+ /**
12910
+ * Mock MySQL connection/pool connection for replay mode
12911
+ * Extends EventEmitter to properly handle all connection methods and events
12912
+ */
12913
+ var TdMysqlConnectionMock = class extends events.EventEmitter {
12914
+ constructor(mysqlInstrumentation, clientType = "poolConnection", spanInfo) {
12915
+ super();
12916
+ this.threadId = null;
12917
+ this.config = {
12918
+ host: "localhost",
12919
+ port: 3306,
12920
+ database: "mock",
12921
+ user: "mock"
12922
+ };
12923
+ this.mysqlInstrumentation = mysqlInstrumentation;
12924
+ this.spanInfo = spanInfo;
12925
+ this.clientType = clientType;
12926
+ this.threadId = 1;
12927
+ }
12928
+ query(...args) {
12929
+ logger.debug(`[TdMysqlConnectionMock] Mock connection query intercepted in REPLAY mode`);
12930
+ let sql;
12931
+ let values;
12932
+ let callback;
12933
+ let options = {};
12934
+ if (typeof args[0] === "string") {
12935
+ sql = args[0];
12936
+ if (typeof args[1] === "function") callback = args[1];
12937
+ else if (Array.isArray(args[1])) {
12938
+ values = args[1];
12939
+ callback = args[2];
12940
+ }
12941
+ } else if (typeof args[0] === "object") {
12942
+ options = args[0];
12943
+ sql = options.sql;
12944
+ values = options.values;
12945
+ if (typeof args[1] === "function") callback = args[1];
12946
+ else if (Array.isArray(args[1])) {
12947
+ values = args[1];
12948
+ callback = args[2];
12949
+ }
12950
+ } else {
12951
+ logger.debug(`[TdMysqlConnectionMock] Could not parse mock connection query, returning empty result`);
12952
+ const emptyResult = {
12953
+ rows: [],
12954
+ fields: []
12955
+ };
12956
+ if (callback) {
12957
+ process.nextTick(() => callback(null, emptyResult.rows, emptyResult.fields));
12958
+ return;
12959
+ }
12960
+ return new events.EventEmitter();
12961
+ }
12962
+ const inputValue = {
12963
+ sql,
12964
+ values,
12965
+ options: options.nestTables ? { nestTables: options.nestTables } : void 0
12966
+ };
12967
+ if (this.spanInfo) return this.mysqlInstrumentation.handleReplayQueryFromMock(this.spanInfo, inputValue, callback);
12968
+ else {
12969
+ const emptyResult = {
12970
+ rows: [],
12971
+ fields: []
12972
+ };
12973
+ if (callback) {
12974
+ process.nextTick(() => callback(null, emptyResult.rows, emptyResult.fields));
12975
+ return;
12976
+ }
12977
+ const emitter = new events.EventEmitter();
12978
+ setImmediate(() => {
12979
+ emitter.emit("fields", [], 0);
12980
+ emitter.emit("end");
12981
+ });
12982
+ return emitter;
12983
+ }
12984
+ }
12985
+ release() {
12986
+ this.emit("end");
12987
+ }
12988
+ destroy() {
12989
+ this.emit("end");
12990
+ }
12991
+ end(callback) {
12992
+ this.emit("end");
12993
+ if (callback) {
12994
+ process.nextTick(() => callback(null));
12995
+ return;
12996
+ }
12997
+ }
12998
+ connect(callback) {
12999
+ if (callback) {
13000
+ process.nextTick(() => callback(null));
13001
+ return;
13002
+ }
13003
+ }
13004
+ ping(callback) {
13005
+ if (callback) {
13006
+ process.nextTick(() => callback(null));
13007
+ return;
13008
+ }
13009
+ }
13010
+ beginTransaction(callback) {
13011
+ if (callback) {
13012
+ process.nextTick(() => callback(null));
13013
+ return;
13014
+ }
13015
+ }
13016
+ commit(callback) {
13017
+ if (callback) {
13018
+ process.nextTick(() => callback(null));
13019
+ return;
13020
+ }
13021
+ }
13022
+ rollback(callback) {
13023
+ if (callback) {
13024
+ process.nextTick(() => callback(null));
13025
+ return;
13026
+ }
13027
+ }
13028
+ changeUser(options, callback) {
13029
+ if (callback) {
13030
+ process.nextTick(() => callback(null));
13031
+ return;
13032
+ }
13033
+ }
13034
+ pause() {}
13035
+ resume() {}
13036
+ escape(value) {
13037
+ if (value === null || value === void 0) return "NULL";
13038
+ if (typeof value === "string") return `'${value.replace(/'/g, "''")}'`;
13039
+ if (typeof value === "number") return value.toString();
13040
+ if (typeof value === "boolean") return value ? "1" : "0";
13041
+ if (value instanceof Date) return `'${value.toISOString()}'`;
13042
+ return `'${String(value)}'`;
13043
+ }
13044
+ escapeId(identifier) {
13045
+ return `\`${identifier.replace(/`/g, "``")}\``;
13046
+ }
13047
+ format(sql, values) {
13048
+ if (!values || values.length === 0) return sql;
13049
+ let index = 0;
13050
+ return sql.replace(/\?/g, () => {
13051
+ if (index >= values.length) return "?";
13052
+ return this.escape(values[index++]);
13053
+ });
13054
+ }
13055
+ };
13056
+
13057
+ //#endregion
13058
+ //#region src/instrumentation/libraries/mysql/mocks/TdMysqlQueryMock.ts
13059
+ var import_src$24 = /* @__PURE__ */ __toESM(require_src$7(), 1);
13060
+ /**
13061
+ * Handles replay mode for MySQL query operations
13062
+ * Returns EventEmitters synchronously to support both callback and streaming modes
13063
+ */
13064
+ var TdMysqlQueryMock = class {
13065
+ constructor() {
13066
+ this.INSTRUMENTATION_NAME = "MysqlInstrumentation";
13067
+ this.tuskDrift = TuskDriftCore.getInstance();
13068
+ }
13069
+ /**
13070
+ * Handle replay of a MySQL query
13071
+ * Always returns an EventEmitter (like mysql does)
13072
+ */
13073
+ handleReplayQuery(queryConfig, inputValue, spanInfo, stackTrace) {
13074
+ logger.debug(`[MysqlInstrumentation] Replaying MySQL query`);
13075
+ return this._handleQuery(queryConfig, inputValue, spanInfo, stackTrace);
13076
+ }
13077
+ /**
13078
+ * Handle background query requests (outside of trace context)
13079
+ * Returns an EventEmitter that immediately completes with empty results
13080
+ */
13081
+ handleNoOpReplayQuery(queryConfig) {
13082
+ logger.debug(`[MysqlInstrumentation] Background query detected, returning empty result`);
13083
+ const emitter = new events.EventEmitter();
13084
+ emitter.then = function(onResolve, onReject) {
13085
+ return new Promise((resolve) => {
13086
+ emitter.once("end", () => {
13087
+ resolve([[], []]);
13088
+ });
13089
+ }).then(onResolve, onReject);
13090
+ };
13091
+ process.nextTick(() => {
13092
+ const callback = queryConfig.callback;
13093
+ if (callback) callback(null, [], []);
13094
+ emitter.emit("fields", [], 0);
13095
+ emitter.emit("end");
13096
+ });
13097
+ return emitter;
13098
+ }
13099
+ /**
13100
+ * Handle query - always returns an EventEmitter (like mysql does)
13101
+ * This handles both callback and streaming modes
13102
+ * The EventEmitter is also thenable (has a .then() method) to support await/Promise usage
13103
+ */
13104
+ _handleQuery(queryConfig, inputValue, spanInfo, stackTrace) {
13105
+ const emitter = new events.EventEmitter();
13106
+ let storedResults = null;
13107
+ let storedFields = null;
13108
+ emitter.then = function(onResolve, onReject) {
13109
+ return new Promise((resolve, reject) => {
13110
+ emitter.once("end", () => {
13111
+ resolve([storedResults, storedFields]);
13112
+ });
13113
+ emitter.once("error", (error) => {
13114
+ reject(error);
13115
+ });
13116
+ }).then(onResolve, onReject);
13117
+ };
13118
+ (async () => {
13119
+ try {
13120
+ const mockData = await this._fetchMockData(inputValue, spanInfo, stackTrace);
13121
+ if (!mockData) {
13122
+ const sql = inputValue.sql || "UNKNOWN_QUERY";
13123
+ logger.warn(`[MysqlInstrumentation] No mock data found for MySQL query: ${sql}`);
13124
+ throw new Error(`[MysqlInstrumentation] No matching mock found for query: ${sql}`);
13125
+ }
13126
+ const outputValue = mockData.result;
13127
+ const results = outputValue.results;
13128
+ const fields = outputValue.fields;
13129
+ const queryCount = outputValue.queryCount || 1;
13130
+ const isMultiStatement = queryCount > 1;
13131
+ storedResults = results;
13132
+ storedFields = fields;
13133
+ process.nextTick(() => {
13134
+ try {
13135
+ if (isMultiStatement) for (let i = 0; i < queryCount; i++) {
13136
+ const resultSet = Array.isArray(results) ? results[i] : results;
13137
+ const fieldSet = Array.isArray(fields) ? fields[i] : fields;
13138
+ if (fieldSet) emitter.emit("fields", fieldSet, i);
13139
+ if (Array.isArray(resultSet)) resultSet.forEach((row) => {
13140
+ emitter.emit("result", row, i);
13141
+ });
13142
+ else emitter.emit("result", resultSet, i);
13143
+ }
13144
+ else {
13145
+ if (fields) emitter.emit("fields", fields, 0);
13146
+ if (Array.isArray(results)) results.forEach((row) => {
13147
+ emitter.emit("result", row, 0);
13148
+ });
13149
+ else emitter.emit("result", results, 0);
13150
+ }
13151
+ if (queryConfig.callback) queryConfig.callback(null, results, fields);
13152
+ emitter.emit("end");
13153
+ } catch (emitError) {
13154
+ logger.error(`[MysqlInstrumentation] Error emitting events: ${emitError}`);
13155
+ emitter.emit("error", emitError);
13156
+ }
13157
+ });
13158
+ } catch (error) {
13159
+ process.nextTick(() => {
13160
+ if (queryConfig.callback) queryConfig.callback(error);
13161
+ emitter.emit("error", error);
13162
+ });
13163
+ }
13164
+ })();
13165
+ return emitter;
13166
+ }
13167
+ /**
13168
+ * Fetch mock data from CLI
13169
+ */
13170
+ async _fetchMockData(inputValue, spanInfo, stackTrace) {
13171
+ return await findMockResponseAsync({
13172
+ mockRequestData: {
13173
+ traceId: spanInfo.traceId,
13174
+ spanId: spanInfo.spanId,
13175
+ name: "mysql.query",
13176
+ inputValue,
13177
+ packageName: "mysql",
13178
+ instrumentationName: this.INSTRUMENTATION_NAME,
13179
+ submoduleName: "query",
13180
+ kind: import_src$24.SpanKind.CLIENT,
13181
+ stackTrace
13182
+ },
13183
+ tuskDrift: this.tuskDrift
13184
+ });
13185
+ }
13186
+ };
13187
+
13188
+ //#endregion
13189
+ //#region src/instrumentation/libraries/mysql/Instrumentation.ts
13190
+ var import_src$23 = /* @__PURE__ */ __toESM(require_src$7(), 1);
13191
+ var MysqlInstrumentation = class extends TdInstrumentationBase {
13192
+ constructor(config = {}) {
13193
+ super("mysql", config);
13194
+ this.INSTRUMENTATION_NAME = "MysqlInstrumentation";
13195
+ this.createQuery = null;
13196
+ this.mode = config.mode || TuskDriftMode.DISABLED;
13197
+ this.queryMock = new TdMysqlQueryMock();
13198
+ }
13199
+ init() {
13200
+ return [new TdInstrumentationNodeModule({
13201
+ name: "mysql",
13202
+ supportedVersions: ["2.*"],
13203
+ files: [
13204
+ new TdInstrumentationNodeModuleFile({
13205
+ name: "mysql/lib/protocol/sequences/Query.js",
13206
+ supportedVersions: ["2.*"],
13207
+ patch: (moduleExports) => this._patchQueryFile(moduleExports)
13208
+ }),
13209
+ new TdInstrumentationNodeModuleFile({
13210
+ name: "mysql/lib/Connection.js",
13211
+ supportedVersions: ["2.*"],
13212
+ patch: (moduleExports) => this._patchConnectionFile(moduleExports)
13213
+ }),
13214
+ new TdInstrumentationNodeModuleFile({
13215
+ name: "mysql/lib/Pool.js",
13216
+ supportedVersions: ["2.*"],
13217
+ patch: (moduleExports) => this._patchPoolFile(moduleExports)
13218
+ })
13219
+ ]
13220
+ })];
13221
+ }
13222
+ /**
13223
+ * Patch Query.prototype.stream method for streaming query support
13224
+ */
13225
+ _patchQueryFile(QueryClass) {
13226
+ logger.debug(`[MysqlInstrumentation] Patching Query class (file-based)`);
13227
+ if (this.isModulePatched(QueryClass)) {
13228
+ logger.debug(`[MysqlInstrumentation] Query class already patched, skipping`);
13229
+ return QueryClass;
13230
+ }
13231
+ if (QueryClass.prototype && QueryClass.prototype.stream) {
13232
+ if (!isWrapped$1(QueryClass.prototype.stream)) {
13233
+ this._wrap(QueryClass.prototype, "stream", this._getStreamPatchFn());
13234
+ logger.debug(`[MysqlInstrumentation] Wrapped Query.prototype.stream`);
13235
+ }
13236
+ }
13237
+ this.markModuleAsPatched(QueryClass);
13238
+ logger.debug(`[MysqlInstrumentation] Query class patching complete`);
13239
+ return QueryClass;
13240
+ }
13241
+ /**
13242
+ * Patch Connection.prototype methods at the file level
13243
+ * This ensures ALL connection instances have patched methods
13244
+ */
13245
+ _patchConnectionFile(ConnectionClass) {
13246
+ logger.debug(`[MysqlInstrumentation] Patching Connection class (file-based)`);
13247
+ if (this.isModulePatched(ConnectionClass)) {
13248
+ logger.debug(`[MysqlInstrumentation] Connection class already patched, skipping`);
13249
+ return ConnectionClass;
13250
+ }
13251
+ if (ConnectionClass.createQuery) {
13252
+ this.createQuery = ConnectionClass.createQuery;
13253
+ logger.debug(`[MysqlInstrumentation] Stored Connection.createQuery method`);
13254
+ }
13255
+ if (ConnectionClass.prototype && ConnectionClass.prototype.query) {
13256
+ if (!isWrapped$1(ConnectionClass.prototype.query)) {
13257
+ this._wrap(ConnectionClass.prototype, "query", this._getQueryPatchFn());
13258
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.query`);
13259
+ }
13260
+ }
13261
+ if (ConnectionClass.prototype && ConnectionClass.prototype.connect) {
13262
+ if (!isWrapped$1(ConnectionClass.prototype.connect)) {
13263
+ this._wrap(ConnectionClass.prototype, "connect", this._getConnectPatchFn());
13264
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.connect`);
13265
+ }
13266
+ }
13267
+ if (ConnectionClass.prototype && ConnectionClass.prototype.beginTransaction) {
13268
+ if (!isWrapped$1(ConnectionClass.prototype.beginTransaction)) {
13269
+ this._wrap(ConnectionClass.prototype, "beginTransaction", this._getBeginTransactionPatchFn());
13270
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.beginTransaction`);
13271
+ }
13272
+ }
13273
+ if (ConnectionClass.prototype && ConnectionClass.prototype.commit) {
13274
+ if (!isWrapped$1(ConnectionClass.prototype.commit)) {
13275
+ this._wrap(ConnectionClass.prototype, "commit", this._getCommitPatchFn());
13276
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.commit`);
13277
+ }
13278
+ }
13279
+ if (ConnectionClass.prototype && ConnectionClass.prototype.rollback) {
13280
+ if (!isWrapped$1(ConnectionClass.prototype.rollback)) {
13281
+ this._wrap(ConnectionClass.prototype, "rollback", this._getRollbackPatchFn());
13282
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.rollback`);
13283
+ }
13284
+ }
13285
+ if (ConnectionClass.prototype && ConnectionClass.prototype.ping) {
13286
+ if (!isWrapped$1(ConnectionClass.prototype.ping)) {
13287
+ this._wrap(ConnectionClass.prototype, "ping", this._getPingPatchFn());
13288
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.ping`);
13289
+ }
13290
+ }
13291
+ if (ConnectionClass.prototype && ConnectionClass.prototype.end) {
13292
+ if (!isWrapped$1(ConnectionClass.prototype.end)) {
13293
+ this._wrap(ConnectionClass.prototype, "end", this._getEndPatchFn());
13294
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.end`);
13295
+ }
13296
+ }
13297
+ if (ConnectionClass.prototype && ConnectionClass.prototype.changeUser) {
13298
+ if (!isWrapped$1(ConnectionClass.prototype.changeUser)) {
13299
+ this._wrap(ConnectionClass.prototype, "changeUser", this._getChangeUserPatchFn());
13300
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.changeUser`);
13301
+ }
13302
+ }
13303
+ if (ConnectionClass.prototype && ConnectionClass.prototype.pause) {
13304
+ if (!isWrapped$1(ConnectionClass.prototype.pause)) {
13305
+ this._wrap(ConnectionClass.prototype, "pause", this._getPausePatchFn());
13306
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.pause`);
13307
+ }
13308
+ }
13309
+ if (ConnectionClass.prototype && ConnectionClass.prototype.resume) {
13310
+ if (!isWrapped$1(ConnectionClass.prototype.resume)) {
13311
+ this._wrap(ConnectionClass.prototype, "resume", this._getResumePatchFn());
13312
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.resume`);
13313
+ }
13314
+ }
13315
+ if (ConnectionClass.prototype && ConnectionClass.prototype.destroy) {
13316
+ if (!isWrapped$1(ConnectionClass.prototype.destroy)) {
13317
+ this._wrap(ConnectionClass.prototype, "destroy", this._getDestroyPatchFn());
13318
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.destroy`);
13319
+ }
13320
+ }
13321
+ this.markModuleAsPatched(ConnectionClass);
13322
+ logger.debug(`[MysqlInstrumentation] Connection class patching complete`);
13323
+ return ConnectionClass;
13324
+ }
13325
+ /**
13326
+ * Patch Pool.prototype methods at the file level
13327
+ */
13328
+ _patchPoolFile(PoolClass) {
13329
+ logger.debug(`[MysqlInstrumentation] Patching Pool class (file-based)`);
13330
+ if (this.isModulePatched(PoolClass)) {
13331
+ logger.debug(`[MysqlInstrumentation] Pool class already patched, skipping`);
13332
+ return PoolClass;
13333
+ }
13334
+ if (PoolClass.prototype && PoolClass.prototype.query) {
13335
+ if (!isWrapped$1(PoolClass.prototype.query)) {
13336
+ this._wrap(PoolClass.prototype, "query", this._getQueryPatchFn());
13337
+ logger.debug(`[MysqlInstrumentation] Wrapped Pool.prototype.query`);
13338
+ }
13339
+ }
13340
+ if (PoolClass.prototype && PoolClass.prototype.getConnection) {
13341
+ if (!isWrapped$1(PoolClass.prototype.getConnection)) {
13342
+ this._wrap(PoolClass.prototype, "getConnection", this._getPoolGetConnectionPatchFn());
13343
+ logger.debug(`[MysqlInstrumentation] Wrapped Pool.prototype.getConnection`);
13344
+ }
13345
+ }
13346
+ if (PoolClass.prototype && PoolClass.prototype.end) {
13347
+ if (!isWrapped$1(PoolClass.prototype.end)) {
13348
+ this._wrap(PoolClass.prototype, "end", this._getPoolEndPatchFn());
13349
+ logger.debug(`[MysqlInstrumentation] Wrapped Pool.prototype.end`);
13350
+ }
13351
+ }
13352
+ this.markModuleAsPatched(PoolClass);
13353
+ logger.debug(`[MysqlInstrumentation] Pool class patching complete`);
13354
+ return PoolClass;
13355
+ }
13356
+ /**
13357
+ * Get wrapper function for query method (prototype-level patching)
13358
+ */
13359
+ _getQueryPatchFn() {
13360
+ const self = this;
13361
+ return (originalQuery) => {
13362
+ return function query(...args) {
13363
+ let sql;
13364
+ let values;
13365
+ let callback;
13366
+ let options = {};
13367
+ if (self.createQuery) try {
13368
+ const queryObj = self.createQuery(...args);
13369
+ sql = queryObj.sql;
13370
+ values = queryObj.values;
13371
+ options = { nestTables: queryObj.nestTables };
13372
+ callback = args.find((arg) => typeof arg === "function");
13373
+ } catch (error) {
13374
+ logger.debug(`[MysqlInstrumentation] Error using createQuery, falling back to manual parsing:`, error);
13375
+ ({sql, values, callback, options} = self._parseQueryArgs(args));
13376
+ }
13377
+ else ({sql, values, callback, options} = self._parseQueryArgs(args));
13378
+ const inputValue = {
13379
+ sql,
13380
+ values,
13381
+ options: options.nestTables ? { nestTables: options.nestTables } : void 0
13382
+ };
13383
+ const isEventEmitterMode = !callback;
13384
+ if (self.mode === TuskDriftMode.REPLAY) {
13385
+ const stackTrace = captureStackTrace(["MysqlInstrumentation"]);
13386
+ return handleReplayMode({
13387
+ noOpRequestHandler: () => {
13388
+ if (isEventEmitterMode) return self.queryMock.handleNoOpReplayQuery({
13389
+ sql,
13390
+ values,
13391
+ callback,
13392
+ options
13393
+ });
13394
+ },
13395
+ isServerRequest: false,
13396
+ replayModeHandler: () => {
13397
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(this, args), {
13398
+ name: "mysql.query",
13399
+ kind: import_src$23.SpanKind.CLIENT,
13400
+ submodule: "query",
13401
+ packageType: PackageType.MYSQL,
13402
+ packageName: "mysql",
13403
+ instrumentationName: self.INSTRUMENTATION_NAME,
13404
+ inputValue,
13405
+ isPreAppStart: false
13406
+ }, (spanInfo) => {
13407
+ const queryEmitter = self.queryMock.handleReplayQuery({
13408
+ sql,
13409
+ values,
13410
+ callback,
13411
+ options
13412
+ }, inputValue, spanInfo, stackTrace);
13413
+ if (queryEmitter && typeof queryEmitter === "object") queryEmitter.stream = function(streamOptions) {
13414
+ return self._createReplayStreamForQuery(inputValue, spanInfo, stackTrace, queryEmitter, streamOptions);
13415
+ };
13416
+ return queryEmitter;
13417
+ });
13418
+ }
13419
+ });
13420
+ } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13421
+ originalFunctionCall: () => originalQuery.apply(this, args),
13422
+ recordModeHandler: ({ isPreAppStart }) => {
13423
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(this, args), {
13424
+ name: "mysql.query",
13425
+ kind: import_src$23.SpanKind.CLIENT,
13426
+ submodule: "query",
13427
+ packageType: PackageType.MYSQL,
13428
+ packageName: "mysql",
13429
+ instrumentationName: self.INSTRUMENTATION_NAME,
13430
+ inputValue,
13431
+ isPreAppStart
13432
+ }, (spanInfo) => {
13433
+ return self._handleRecordQuery(spanInfo, originalQuery, this, args, callback, isEventEmitterMode);
13434
+ });
13435
+ },
13436
+ spanKind: import_src$23.SpanKind.CLIENT
13437
+ });
13438
+ else return originalQuery.apply(this, args);
13439
+ };
13440
+ };
13441
+ }
13442
+ /**
13443
+ * Get wrapper function for connect method
13444
+ */
13445
+ _getConnectPatchFn() {
13446
+ const self = this;
13447
+ return (originalConnect) => {
13448
+ return function connect(callback) {
13449
+ if (self.mode === TuskDriftMode.REPLAY) {
13450
+ const connectionContext = this;
13451
+ return handleReplayMode({
13452
+ noOpRequestHandler: () => {
13453
+ if (callback) setImmediate(() => callback(null));
13454
+ setImmediate(() => connectionContext.emit("connect"));
13455
+ },
13456
+ isServerRequest: false,
13457
+ replayModeHandler: () => {
13458
+ if (callback) setImmediate(() => callback(null));
13459
+ setImmediate(() => connectionContext.emit("connect"));
13460
+ }
13461
+ });
13462
+ } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13463
+ originalFunctionCall: () => originalConnect.apply(this, arguments),
13464
+ recordModeHandler: ({ isPreAppStart }) => {
13465
+ return originalConnect.apply(this, arguments);
13466
+ },
13467
+ spanKind: import_src$23.SpanKind.CLIENT
13468
+ });
13469
+ else return originalConnect.apply(this, arguments);
13470
+ };
13471
+ };
13472
+ }
13473
+ /**
13474
+ * Get wrapper function for beginTransaction method
13475
+ */
13476
+ _getBeginTransactionPatchFn() {
13477
+ const self = this;
13478
+ return (originalBeginTransaction) => {
13479
+ return function beginTransaction(callback) {
13480
+ const inputValue = { query: "BEGIN" };
13481
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13482
+ noOpRequestHandler: () => {
13483
+ if (callback) setImmediate(() => callback(null));
13484
+ },
13485
+ isServerRequest: false,
13486
+ replayModeHandler: () => {
13487
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalBeginTransaction.apply(this, arguments), {
13488
+ name: "mysql.beginTransaction",
13489
+ kind: import_src$23.SpanKind.CLIENT,
13490
+ submodule: "transaction",
13491
+ packageType: PackageType.MYSQL,
13492
+ packageName: "mysql",
13493
+ instrumentationName: self.INSTRUMENTATION_NAME,
13494
+ inputValue,
13495
+ isPreAppStart: false
13496
+ }, (spanInfo) => {
13497
+ return self._handleReplayTransaction(inputValue, callback);
13498
+ });
13499
+ }
13500
+ });
13501
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13502
+ originalFunctionCall: () => originalBeginTransaction.apply(this, arguments),
13503
+ recordModeHandler: ({ isPreAppStart }) => {
13504
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalBeginTransaction.apply(this, arguments), {
13505
+ name: "mysql.beginTransaction",
13506
+ kind: import_src$23.SpanKind.CLIENT,
13507
+ submodule: "transaction",
13508
+ packageType: PackageType.MYSQL,
13509
+ packageName: "mysql",
13510
+ instrumentationName: self.INSTRUMENTATION_NAME,
13511
+ inputValue,
13512
+ isPreAppStart
13513
+ }, (spanInfo) => {
13514
+ return self._handleRecordTransaction(spanInfo, originalBeginTransaction, this, arguments, callback);
13515
+ });
13516
+ },
13517
+ spanKind: import_src$23.SpanKind.CLIENT
13518
+ });
13519
+ else return originalBeginTransaction.apply(this, arguments);
13520
+ };
13521
+ };
13522
+ }
13523
+ /**
13524
+ * Get wrapper function for commit method
13525
+ */
13526
+ _getCommitPatchFn() {
13527
+ const self = this;
13528
+ return (originalCommit) => {
13529
+ return function commit(callback) {
13530
+ const inputValue = { query: "COMMIT" };
13531
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13532
+ noOpRequestHandler: () => {
13533
+ if (callback) setImmediate(() => callback(null));
13534
+ },
13535
+ isServerRequest: false,
13536
+ replayModeHandler: () => {
13537
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalCommit.apply(this, arguments), {
13538
+ name: "mysql.commit",
13539
+ kind: import_src$23.SpanKind.CLIENT,
13540
+ submodule: "transaction",
13541
+ packageType: PackageType.MYSQL,
13542
+ packageName: "mysql",
13543
+ instrumentationName: self.INSTRUMENTATION_NAME,
13544
+ inputValue,
13545
+ isPreAppStart: false
13546
+ }, (spanInfo) => {
13547
+ return self._handleReplayTransaction(inputValue, callback);
13548
+ });
13549
+ }
13550
+ });
13551
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13552
+ originalFunctionCall: () => originalCommit.apply(this, arguments),
13553
+ recordModeHandler: ({ isPreAppStart }) => {
13554
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalCommit.apply(this, arguments), {
13555
+ name: "mysql.commit",
13556
+ kind: import_src$23.SpanKind.CLIENT,
13557
+ submodule: "transaction",
13558
+ packageType: PackageType.MYSQL,
13559
+ packageName: "mysql",
13560
+ instrumentationName: self.INSTRUMENTATION_NAME,
13561
+ inputValue,
13562
+ isPreAppStart
13563
+ }, (spanInfo) => {
13564
+ return self._handleRecordTransaction(spanInfo, originalCommit, this, arguments, callback);
13565
+ });
13566
+ },
13567
+ spanKind: import_src$23.SpanKind.CLIENT
13568
+ });
13569
+ else return originalCommit.apply(this, arguments);
13570
+ };
13571
+ };
13572
+ }
13573
+ /**
13574
+ * Get wrapper function for rollback method
13575
+ */
13576
+ _getRollbackPatchFn() {
13577
+ const self = this;
13578
+ return (originalRollback) => {
13579
+ return function rollback(callback) {
13580
+ const inputValue = { query: "ROLLBACK" };
13581
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13582
+ noOpRequestHandler: () => {
13583
+ if (callback) setImmediate(() => callback(null));
13584
+ },
13585
+ isServerRequest: false,
13586
+ replayModeHandler: () => {
13587
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalRollback.apply(this, arguments), {
13588
+ name: "mysql.rollback",
13589
+ kind: import_src$23.SpanKind.CLIENT,
13590
+ submodule: "transaction",
13591
+ packageType: PackageType.MYSQL,
13592
+ packageName: "mysql",
13593
+ instrumentationName: self.INSTRUMENTATION_NAME,
13594
+ inputValue,
13595
+ isPreAppStart: false
13596
+ }, (spanInfo) => {
13597
+ return self._handleReplayTransaction(inputValue, callback);
13598
+ });
13599
+ }
13600
+ });
13601
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13602
+ originalFunctionCall: () => originalRollback.apply(this, arguments),
13603
+ recordModeHandler: ({ isPreAppStart }) => {
13604
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalRollback.apply(this, arguments), {
13605
+ name: "mysql.rollback",
13606
+ kind: import_src$23.SpanKind.CLIENT,
13607
+ submodule: "transaction",
13608
+ packageType: PackageType.MYSQL,
13609
+ packageName: "mysql",
13610
+ instrumentationName: self.INSTRUMENTATION_NAME,
13611
+ inputValue,
13612
+ isPreAppStart
13613
+ }, (spanInfo) => {
13614
+ return self._handleRecordTransaction(spanInfo, originalRollback, this, arguments, callback);
13615
+ });
13616
+ },
13617
+ spanKind: import_src$23.SpanKind.CLIENT
13618
+ });
13619
+ else return originalRollback.apply(this, arguments);
13620
+ };
13621
+ };
13622
+ }
13623
+ /**
13624
+ * Get wrapper function for ping method
13625
+ */
13626
+ _getPingPatchFn() {
13627
+ const self = this;
13628
+ return (originalPing) => {
13629
+ return function ping(callback) {
13630
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13631
+ noOpRequestHandler: () => {
13632
+ if (callback) setImmediate(() => callback(null));
13633
+ },
13634
+ isServerRequest: false,
13635
+ replayModeHandler: () => {
13636
+ if (callback) setImmediate(() => callback(null));
13637
+ }
13638
+ });
13639
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13640
+ originalFunctionCall: () => originalPing.apply(this, arguments),
13641
+ recordModeHandler: ({ isPreAppStart }) => {
13642
+ return originalPing.apply(this, arguments);
13643
+ },
13644
+ spanKind: import_src$23.SpanKind.CLIENT
13645
+ });
13646
+ else return originalPing.apply(this, arguments);
13647
+ };
13648
+ };
13649
+ }
13650
+ /**
13651
+ * Get wrapper function for end method
13652
+ */
13653
+ _getEndPatchFn() {
13654
+ const self = this;
13655
+ return (originalEnd) => {
13656
+ return function end(callback) {
13657
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13658
+ noOpRequestHandler: () => {
13659
+ if (callback) setImmediate(() => callback(null));
13660
+ setImmediate(() => this.emit("end"));
13661
+ },
13662
+ isServerRequest: false,
13663
+ replayModeHandler: () => {
13664
+ if (callback) setImmediate(() => callback(null));
13665
+ setImmediate(() => this.emit("end"));
13666
+ }
13667
+ });
13668
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13669
+ originalFunctionCall: () => originalEnd.apply(this, arguments),
13670
+ recordModeHandler: ({ isPreAppStart }) => {
13671
+ return originalEnd.apply(this, arguments);
13672
+ },
13673
+ spanKind: import_src$23.SpanKind.CLIENT
13674
+ });
13675
+ else return originalEnd.apply(this, arguments);
13676
+ };
13677
+ };
13678
+ }
13679
+ /**
13680
+ * Get wrapper function for changeUser method
13681
+ */
13682
+ _getChangeUserPatchFn() {
13683
+ const self = this;
13684
+ return (originalChangeUser) => {
13685
+ return function changeUser(options, callback) {
13686
+ let userCallback = callback;
13687
+ if (typeof options === "function") userCallback = options;
13688
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13689
+ noOpRequestHandler: () => {
13690
+ if (userCallback) setImmediate(() => userCallback(null));
13691
+ },
13692
+ isServerRequest: false,
13693
+ replayModeHandler: () => {
13694
+ if (userCallback) setImmediate(() => userCallback(null));
13695
+ }
13696
+ });
13697
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13698
+ originalFunctionCall: () => originalChangeUser.apply(this, arguments),
13699
+ recordModeHandler: ({ isPreAppStart }) => {
13700
+ return originalChangeUser.apply(this, arguments);
13701
+ },
13702
+ spanKind: import_src$23.SpanKind.CLIENT
13703
+ });
13704
+ else return originalChangeUser.apply(this, arguments);
13705
+ };
13706
+ };
13707
+ }
13708
+ /**
13709
+ * Get wrapper function for pause method
13710
+ */
13711
+ _getPausePatchFn() {
13712
+ const self = this;
13713
+ return (originalPause) => {
13714
+ return function pause() {
13715
+ if (self.mode === TuskDriftMode.REPLAY) return;
13716
+ else if (self.mode === TuskDriftMode.RECORD) return originalPause.apply(this, arguments);
13717
+ else return originalPause.apply(this, arguments);
13718
+ };
13719
+ };
13720
+ }
13721
+ /**
13722
+ * Get wrapper function for resume method
13723
+ */
13724
+ _getResumePatchFn() {
13725
+ const self = this;
13726
+ return (originalResume) => {
13727
+ return function resume() {
13728
+ if (self.mode === TuskDriftMode.REPLAY) return;
13729
+ else if (self.mode === TuskDriftMode.RECORD) return originalResume.apply(this, arguments);
13730
+ else return originalResume.apply(this, arguments);
13731
+ };
13732
+ };
13733
+ }
13734
+ /**
13735
+ * Get wrapper function for destroy method
13736
+ */
13737
+ _getDestroyPatchFn() {
13738
+ const self = this;
13739
+ return (originalDestroy) => {
13740
+ return function destroy() {
13741
+ if (self.mode === TuskDriftMode.REPLAY) return;
13742
+ else if (self.mode === TuskDriftMode.RECORD) return originalDestroy.apply(this, arguments);
13743
+ else return originalDestroy.apply(this, arguments);
13744
+ };
13745
+ };
13746
+ }
13747
+ /**
13748
+ * Get wrapper function for Pool.end method
13749
+ */
13750
+ _getPoolEndPatchFn() {
13751
+ const self = this;
13752
+ return (originalEnd) => {
13753
+ return function end(callback) {
13754
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13755
+ noOpRequestHandler: () => {
13756
+ if (callback) setImmediate(() => callback(null));
13757
+ },
13758
+ isServerRequest: false,
13759
+ replayModeHandler: () => {
13760
+ if (callback) setImmediate(() => callback(null));
13761
+ }
13762
+ });
13763
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13764
+ originalFunctionCall: () => originalEnd.apply(this, arguments),
13765
+ recordModeHandler: ({ isPreAppStart }) => {
13766
+ return originalEnd.apply(this, arguments);
13767
+ },
13768
+ spanKind: import_src$23.SpanKind.CLIENT
13769
+ });
13770
+ else return originalEnd.apply(this, arguments);
13771
+ };
13772
+ };
13773
+ }
13774
+ /**
13775
+ * Get wrapper function for Pool.getConnection method
13776
+ */
13777
+ _getPoolGetConnectionPatchFn() {
13778
+ const self = this;
13779
+ return (originalGetConnection) => {
13780
+ return function getConnection(callback) {
13781
+ const inputValue = { clientType: "pool" };
13782
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13783
+ noOpRequestHandler: () => {
13784
+ return self._handleNoOpReplayGetConnection(callback);
13785
+ },
13786
+ isServerRequest: false,
13787
+ replayModeHandler: () => {
13788
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalGetConnection.apply(this, [callback]), {
13789
+ name: `mysql.pool.getConnection`,
13790
+ kind: import_src$23.SpanKind.CLIENT,
13791
+ submodule: "getConnection",
13792
+ packageName: "mysql",
13793
+ packageType: PackageType.MYSQL,
13794
+ instrumentationName: self.INSTRUMENTATION_NAME,
13795
+ inputValue,
13796
+ isPreAppStart: false
13797
+ }, (spanInfo) => {
13798
+ return self._handleReplayPoolGetConnection(spanInfo, callback);
13799
+ });
13800
+ }
13801
+ });
13802
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13803
+ originalFunctionCall: () => originalGetConnection.apply(this, [callback]),
13804
+ recordModeHandler: ({ isPreAppStart }) => {
13805
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalGetConnection.apply(this, [callback]), {
13806
+ name: `mysql.pool.getConnection`,
13807
+ kind: import_src$23.SpanKind.CLIENT,
13808
+ submodule: "getConnection",
13809
+ packageName: "mysql",
13810
+ packageType: PackageType.MYSQL,
13811
+ instrumentationName: self.INSTRUMENTATION_NAME,
13812
+ inputValue,
13813
+ isPreAppStart
13814
+ }, (spanInfo) => {
13815
+ return self._handleRecordPoolGetConnectionInSpan(spanInfo, originalGetConnection, callback, this);
13816
+ });
13817
+ },
13818
+ spanKind: import_src$23.SpanKind.CLIENT
13819
+ });
13820
+ else return originalGetConnection.apply(this, [callback]);
13821
+ };
13822
+ };
13823
+ }
13824
+ _patchQueryMethod(connection) {
13825
+ const self = this;
13826
+ return (originalQuery) => {
13827
+ return function query(...args) {
13828
+ let sql;
13829
+ let values;
13830
+ let callback;
13831
+ let options = {};
13832
+ if (self.createQuery) try {
13833
+ const queryObj = self.createQuery(...args);
13834
+ sql = queryObj.sql;
13835
+ values = queryObj.values;
13836
+ options = { nestTables: queryObj.nestTables };
13837
+ callback = args.find((arg) => typeof arg === "function");
13838
+ } catch (error) {
13839
+ logger.debug(`[MysqlInstrumentation] Error using createQuery, falling back to manual parsing:`, error);
13840
+ ({sql, values, callback, options} = self._parseQueryArgs(args));
13841
+ }
13842
+ else ({sql, values, callback, options} = self._parseQueryArgs(args));
13843
+ const inputValue = {
13844
+ sql,
13845
+ values,
13846
+ options: options.nestTables ? { nestTables: options.nestTables } : void 0
13847
+ };
13848
+ const isEventEmitterMode = !callback;
13849
+ if (self.mode === TuskDriftMode.REPLAY) {
13850
+ const stackTrace = captureStackTrace(["MysqlInstrumentation"]);
13851
+ return handleReplayMode({
13852
+ noOpRequestHandler: () => {
13853
+ if (isEventEmitterMode) return new events.EventEmitter();
13854
+ },
13855
+ isServerRequest: false,
13856
+ replayModeHandler: () => {
13857
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(connection, args), {
13858
+ name: "mysql.query",
13859
+ kind: import_src$23.SpanKind.CLIENT,
13860
+ submodule: "query",
13861
+ packageType: PackageType.MYSQL,
13862
+ packageName: "mysql",
13863
+ instrumentationName: self.INSTRUMENTATION_NAME,
13864
+ inputValue,
13865
+ isPreAppStart: false
13866
+ }, (spanInfo) => {
13867
+ const queryEmitter = self.queryMock.handleReplayQuery({
13868
+ sql: inputValue.sql,
13869
+ values: inputValue.values,
13870
+ callback,
13871
+ options: inputValue.options
13872
+ }, inputValue, spanInfo, stackTrace);
13873
+ if (queryEmitter && typeof queryEmitter === "object") queryEmitter.stream = function(streamOptions) {
13874
+ return self._createReplayStreamForQuery(inputValue, spanInfo, stackTrace, queryEmitter, streamOptions);
13875
+ };
13876
+ return queryEmitter;
13877
+ });
13878
+ }
13879
+ });
13880
+ } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13881
+ originalFunctionCall: () => originalQuery.apply(connection, args),
13882
+ recordModeHandler: ({ isPreAppStart }) => {
13883
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(connection, args), {
13884
+ name: "mysql.query",
13885
+ kind: import_src$23.SpanKind.CLIENT,
13886
+ submodule: "query",
13887
+ packageType: PackageType.MYSQL,
13888
+ packageName: "mysql",
13889
+ instrumentationName: self.INSTRUMENTATION_NAME,
13890
+ inputValue,
13891
+ isPreAppStart
13892
+ }, (spanInfo) => {
13893
+ return self._handleRecordQuery(spanInfo, originalQuery, connection, args, callback, isEventEmitterMode);
13894
+ });
13895
+ },
13896
+ spanKind: import_src$23.SpanKind.CLIENT
13897
+ });
13898
+ else return originalQuery.apply(connection, args);
13899
+ };
13900
+ };
13901
+ }
13902
+ _handleRecordQuery(spanInfo, originalQuery, connection, args, callback, isEventEmitterMode) {
13903
+ if (isEventEmitterMode) {
13904
+ const queryEmitter = originalQuery.apply(connection, args);
13905
+ const results = [];
13906
+ const fields = [];
13907
+ let error = null;
13908
+ let queryIndex = 0;
13909
+ queryEmitter.on("error", (err) => {
13910
+ error = err;
13911
+ queryIndex = queryEmitter._index || queryIndex;
13912
+ logger.debug(`[MysqlInstrumentation] Query error: ${err.message}`);
13913
+ }).on("fields", (fieldPackets, index) => {
13914
+ fields[index] = fieldPackets;
13915
+ }).on("result", (row, index) => {
13916
+ queryIndex = index;
13917
+ if (!results[index]) if (isMysqlOkPacket(row)) results[index] = row;
13918
+ else results[index] = [];
13919
+ if (Array.isArray(results[index])) results[index].push(row);
13920
+ }).on("end", () => {
13921
+ const finalQueryCount = this._getQueryCount(queryEmitter) || queryIndex + 1;
13922
+ const outputValue = finalQueryCount > 1 ? {
13923
+ results,
13924
+ fields,
13925
+ queryCount: finalQueryCount,
13926
+ errQueryIndex: error ? queryIndex : void 0
13927
+ } : {
13928
+ results: results[0],
13929
+ fields: fields[0],
13930
+ queryCount: finalQueryCount
13931
+ };
13932
+ if (error) try {
13933
+ SpanUtils.endSpan(spanInfo.span, {
13934
+ code: import_src$23.SpanStatusCode.ERROR,
13935
+ message: error.message
13936
+ });
13937
+ } catch (error$1) {
13938
+ logger.error(`[MysqlInstrumentation] error ending span:`, error$1);
13939
+ }
13940
+ else try {
13941
+ SpanUtils.addSpanAttributes(spanInfo.span, { outputValue });
13942
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
13943
+ } catch (error$1) {
13944
+ logger.error(`[MysqlInstrumentation] error ending span:`, error$1);
13945
+ }
13946
+ logger.debug(`[MysqlInstrumentation] Query completed`);
13947
+ });
13948
+ return queryEmitter;
13949
+ } else {
13950
+ const originalCallback = callback;
13951
+ const callbackIndex = args.findIndex((arg) => typeof arg === "function");
13952
+ args[callbackIndex] = function(err, results, fields) {
13953
+ if (err) try {
13954
+ SpanUtils.endSpan(spanInfo.span, {
13955
+ code: import_src$23.SpanStatusCode.ERROR,
13956
+ message: err.message
13957
+ });
13958
+ } catch (error) {
13959
+ logger.error(`[MysqlInstrumentation] error ending span:`, error);
13960
+ }
13961
+ else try {
13962
+ const outputValue = {
13963
+ results,
13964
+ fields
13965
+ };
13966
+ SpanUtils.addSpanAttributes(spanInfo.span, { outputValue });
13967
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
13968
+ } catch (error) {
13969
+ logger.error(`[MysqlInstrumentation] error ending span:`, error);
13970
+ }
13971
+ logger.debug(`[MysqlInstrumentation] Query completed`);
13972
+ return originalCallback.apply(this, arguments);
13973
+ };
13974
+ return originalQuery.apply(connection, args);
13975
+ }
13976
+ }
13977
+ _patchConnect(connection) {
13978
+ const self = this;
13979
+ return (originalConnect) => {
13980
+ return function connect(callback) {
13981
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13982
+ noOpRequestHandler: () => {
13983
+ if (callback) setImmediate(() => callback(null));
13984
+ },
13985
+ isServerRequest: false,
13986
+ replayModeHandler: () => {
13987
+ if (callback) setImmediate(() => callback(null));
13988
+ }
13989
+ });
13990
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13991
+ originalFunctionCall: () => originalConnect.apply(connection, arguments),
13992
+ recordModeHandler: ({ isPreAppStart }) => {
13993
+ return originalConnect.apply(connection, arguments);
13994
+ },
13995
+ spanKind: import_src$23.SpanKind.CLIENT
13996
+ });
13997
+ else return originalConnect.apply(connection, arguments);
13998
+ };
13999
+ };
14000
+ }
14001
+ _patchBeginTransaction(connection) {
14002
+ const self = this;
14003
+ return (originalBeginTransaction) => {
14004
+ return function beginTransaction(callback) {
14005
+ const inputValue = { query: "BEGIN" };
14006
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
14007
+ noOpRequestHandler: () => {
14008
+ if (callback) setImmediate(() => callback(null));
14009
+ },
14010
+ isServerRequest: false,
14011
+ replayModeHandler: () => {
14012
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalBeginTransaction.apply(connection, arguments), {
14013
+ name: "mysql.beginTransaction",
14014
+ kind: import_src$23.SpanKind.CLIENT,
14015
+ submodule: "transaction",
14016
+ packageType: PackageType.MYSQL,
14017
+ packageName: "mysql",
14018
+ instrumentationName: self.INSTRUMENTATION_NAME,
14019
+ inputValue,
14020
+ isPreAppStart: false
14021
+ }, (spanInfo) => {
14022
+ return self._handleReplayTransaction(inputValue, callback);
14023
+ });
14024
+ }
14025
+ });
14026
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
14027
+ originalFunctionCall: () => originalBeginTransaction.apply(connection, arguments),
14028
+ recordModeHandler: ({ isPreAppStart }) => {
14029
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalBeginTransaction.apply(connection, arguments), {
14030
+ name: "mysql.beginTransaction",
14031
+ kind: import_src$23.SpanKind.CLIENT,
14032
+ submodule: "transaction",
14033
+ packageType: PackageType.MYSQL,
14034
+ packageName: "mysql",
14035
+ instrumentationName: self.INSTRUMENTATION_NAME,
14036
+ inputValue,
14037
+ isPreAppStart
14038
+ }, (spanInfo) => {
14039
+ return self._handleRecordTransaction(spanInfo, originalBeginTransaction, connection, arguments, callback);
14040
+ });
14041
+ },
14042
+ spanKind: import_src$23.SpanKind.CLIENT
14043
+ });
14044
+ else return originalBeginTransaction.apply(connection, arguments);
14045
+ };
14046
+ };
14047
+ }
14048
+ _patchCommit(connection) {
14049
+ const self = this;
14050
+ return (originalCommit) => {
14051
+ return function commit(callback) {
14052
+ const inputValue = { query: "COMMIT" };
14053
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
14054
+ noOpRequestHandler: () => {
14055
+ if (callback) setImmediate(() => callback(null));
14056
+ },
14057
+ isServerRequest: false,
14058
+ replayModeHandler: () => {
14059
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalCommit.apply(connection, arguments), {
14060
+ name: "mysql.commit",
14061
+ kind: import_src$23.SpanKind.CLIENT,
14062
+ submodule: "transaction",
14063
+ packageType: PackageType.MYSQL,
14064
+ packageName: "mysql",
14065
+ instrumentationName: self.INSTRUMENTATION_NAME,
14066
+ inputValue,
14067
+ isPreAppStart: false
14068
+ }, (spanInfo) => {
14069
+ return self._handleReplayTransaction(inputValue, callback);
14070
+ });
14071
+ }
14072
+ });
14073
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
14074
+ originalFunctionCall: () => originalCommit.apply(connection, arguments),
14075
+ recordModeHandler: ({ isPreAppStart }) => {
14076
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalCommit.apply(connection, arguments), {
14077
+ name: "mysql.commit",
14078
+ kind: import_src$23.SpanKind.CLIENT,
14079
+ submodule: "transaction",
14080
+ packageType: PackageType.MYSQL,
14081
+ packageName: "mysql",
14082
+ instrumentationName: self.INSTRUMENTATION_NAME,
14083
+ inputValue,
14084
+ isPreAppStart
14085
+ }, (spanInfo) => {
14086
+ return self._handleRecordTransaction(spanInfo, originalCommit, connection, arguments, callback);
14087
+ });
14088
+ },
14089
+ spanKind: import_src$23.SpanKind.CLIENT
14090
+ });
14091
+ else return originalCommit.apply(connection, arguments);
14092
+ };
14093
+ };
14094
+ }
14095
+ _patchRollback(connection) {
14096
+ const self = this;
14097
+ return (originalRollback) => {
14098
+ return function rollback(callback) {
14099
+ const inputValue = { query: "ROLLBACK" };
14100
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
14101
+ noOpRequestHandler: () => {
14102
+ if (callback) setImmediate(() => callback(null));
14103
+ },
14104
+ isServerRequest: false,
14105
+ replayModeHandler: () => {
14106
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalRollback.apply(connection, arguments), {
14107
+ name: "mysql.rollback",
14108
+ kind: import_src$23.SpanKind.CLIENT,
14109
+ submodule: "transaction",
14110
+ packageType: PackageType.MYSQL,
14111
+ packageName: "mysql",
14112
+ instrumentationName: self.INSTRUMENTATION_NAME,
14113
+ inputValue,
14114
+ isPreAppStart: false
14115
+ }, (spanInfo) => {
14116
+ return self._handleReplayTransaction(inputValue, callback);
14117
+ });
14118
+ }
14119
+ });
14120
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
14121
+ originalFunctionCall: () => originalRollback.apply(connection, arguments),
14122
+ recordModeHandler: ({ isPreAppStart }) => {
14123
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalRollback.apply(connection, arguments), {
14124
+ name: "mysql.rollback",
14125
+ kind: import_src$23.SpanKind.CLIENT,
14126
+ submodule: "transaction",
14127
+ packageType: PackageType.MYSQL,
14128
+ packageName: "mysql",
14129
+ instrumentationName: self.INSTRUMENTATION_NAME,
14130
+ inputValue,
14131
+ isPreAppStart
14132
+ }, (spanInfo) => {
14133
+ return self._handleRecordTransaction(spanInfo, originalRollback, connection, arguments, callback);
14134
+ });
14135
+ },
14136
+ spanKind: import_src$23.SpanKind.CLIENT
14137
+ });
14138
+ else return originalRollback.apply(connection, arguments);
14139
+ };
14140
+ };
12760
14141
  }
12761
- async _handleRecordQueryInSpan(spanInfo, originalSql, strings, values) {
12762
- try {
12763
- const result = await originalSql.call(this, strings, ...values);
14142
+ _handleRecordTransaction(spanInfo, originalFunction, connection, args, callback) {
14143
+ if (!callback) try {
14144
+ const result = originalFunction.apply(connection, args);
12764
14145
  try {
12765
- logger.debug(`[PostgresInstrumentation] Postgres query completed successfully (${SpanUtils.getTraceInfo()})`);
12766
- this._addOutputAttributesToSpan(spanInfo, result);
14146
+ SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: { status: "success" } });
12767
14147
  SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
12768
14148
  } catch (error) {
12769
- logger.error(`[PostgresInstrumentation] error processing query response:`, error);
14149
+ logger.error(`[MysqlInstrumentation] error adding span attributes:`, error);
12770
14150
  }
12771
14151
  return result;
12772
14152
  } catch (error) {
12773
14153
  try {
12774
- logger.debug(`[PostgresInstrumentation] Postgres query error: ${error.message} (${SpanUtils.getTraceInfo()})`);
12775
14154
  SpanUtils.endSpan(spanInfo.span, {
12776
14155
  code: import_src$23.SpanStatusCode.ERROR,
12777
14156
  message: error.message
12778
14157
  });
12779
- } catch (spanError) {
12780
- logger.error(`[PostgresInstrumentation] error ending span:`, spanError);
14158
+ } catch (error$1) {
14159
+ logger.error(`[MysqlInstrumentation] error ending span:`, error$1);
12781
14160
  }
12782
14161
  throw error;
12783
14162
  }
12784
- }
12785
- async handleReplaySqlQuery({ inputValue, spanInfo, submodule, name, stackTrace }) {
12786
- logger.debug(`[PostgresInstrumentation] Replaying Postgres sql query`);
12787
- const mockData = await findMockResponseAsync({
12788
- mockRequestData: {
12789
- traceId: spanInfo.traceId,
12790
- spanId: spanInfo.spanId,
12791
- name,
12792
- inputValue,
12793
- packageName: "postgres",
12794
- instrumentationName: this.INSTRUMENTATION_NAME,
12795
- submoduleName: submodule,
12796
- kind: import_src$23.SpanKind.CLIENT,
12797
- stackTrace
12798
- },
12799
- tuskDrift: this.tuskDrift
12800
- });
12801
- if (!mockData) {
12802
- const queryText = inputValue.query || "UNKNOWN_QUERY";
12803
- logger.warn(`[PostgresInstrumentation] No mock data found for Postgres sql query: ${queryText}`);
12804
- throw new Error(`[PostgresInstrumentation] No matching mock found for Postgres sql query: ${queryText}`);
14163
+ const argsArray = Array.from(args);
14164
+ const callbackIndex = argsArray.findIndex((arg) => typeof arg === "function");
14165
+ if (callbackIndex !== -1) {
14166
+ const originalCallback = callback;
14167
+ argsArray[callbackIndex] = function(err) {
14168
+ if (err) try {
14169
+ SpanUtils.endSpan(spanInfo.span, {
14170
+ code: import_src$23.SpanStatusCode.ERROR,
14171
+ message: err.message
14172
+ });
14173
+ } catch (error) {
14174
+ logger.error(`[MysqlInstrumentation] error ending span:`, error);
14175
+ }
14176
+ else try {
14177
+ SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: { status: "success" } });
14178
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
14179
+ } catch (error) {
14180
+ logger.error(`[MysqlInstrumentation] error ending span:`, error);
14181
+ }
14182
+ logger.debug(`[MysqlInstrumentation] Transaction completed`);
14183
+ return originalCallback.apply(this, arguments);
14184
+ };
14185
+ argsArray[callbackIndex] = import_src$23.context.bind(spanInfo.context, argsArray[callbackIndex]);
12805
14186
  }
12806
- logger.debug(`[PostgresInstrumentation] Found mock data for Postgres sql query: ${JSON.stringify(mockData)}`);
12807
- const processedResult = this.convertPostgresTypes(mockData.result);
12808
- logger.debug(`[PostgresInstrumentation] Sql query processed result: ${JSON.stringify(processedResult)}`);
12809
- const isResultObject = processedResult && typeof processedResult === "object" && "rows" in processedResult;
12810
- const rows = isResultObject ? processedResult.rows || [] : processedResult || [];
12811
- return Object.assign(rows, {
12812
- command: isResultObject ? processedResult.command : void 0,
12813
- count: isResultObject ? processedResult.count : void 0
12814
- });
14187
+ return originalFunction.apply(connection, argsArray);
12815
14188
  }
12816
- async handleReplayUnsafeQuery({ inputValue, spanInfo, submodule, name, stackTrace }) {
12817
- logger.debug(`[PostgresInstrumentation] Replaying Postgres unsafe query`);
12818
- const mockData = await findMockResponseAsync({
12819
- mockRequestData: {
12820
- traceId: spanInfo.traceId,
12821
- spanId: spanInfo.spanId,
12822
- name,
12823
- inputValue,
12824
- packageName: "postgres",
12825
- instrumentationName: this.INSTRUMENTATION_NAME,
12826
- submoduleName: submodule,
12827
- kind: import_src$23.SpanKind.CLIENT,
12828
- stackTrace
12829
- },
12830
- tuskDrift: this.tuskDrift
14189
+ async _handleReplayTransaction(inputValue, callback) {
14190
+ logger.debug(`[MysqlInstrumentation] Replaying MySQL transaction: ${inputValue.query}`);
14191
+ if (callback) setImmediate(() => {
14192
+ callback(null);
12831
14193
  });
12832
- if (!mockData) {
12833
- const queryText = inputValue.query || "UNKNOWN_QUERY";
12834
- logger.warn(`[PostgresInstrumentation] No mock data found for Postgres unsafe query: ${queryText}`);
12835
- throw new Error(`[PostgresInstrumentation] No matching mock found for Postgres unsafe query: ${queryText}`);
12836
- }
12837
- logger.debug(`[PostgresInstrumentation] Found mock data for Postgres unsafe query: ${JSON.stringify(mockData)}`);
12838
- const processedResult = this.convertPostgresTypes(mockData.result);
12839
- logger.debug(`[PostgresInstrumentation] Unsafe query processed result: ${JSON.stringify(processedResult)}`);
12840
- return processedResult;
12841
14194
  }
12842
- /**
12843
- * Create a postgres.js-compatible PendingQuery wrapper.
12844
- * This creates a thenable object with .values(), .raw(), etc. methods
12845
- * that matches the postgres.js PendingQuery interface.
12846
- *
12847
- * NOTE: This wrapper is ONLY needed for unsafe() queries, not template string queries.
12848
- * - unsafe() returns a PendingQuery with .values() method that Drizzle calls
12849
- * - Template strings return a plain Promise/array and don't need the wrapper
12850
- *
12851
- * Also NOTE: unsafe expects a PendingQuery in return. This includes most common ones, but not all.
12852
- * There is a possiblity we need to add the rest of the methods to the PendingQuery interface from "postgres" library.
12853
- */
12854
- _createPendingQueryWrapper(queryPromiseFactory) {
12855
- const mainPromise = queryPromiseFactory();
12856
- return Object.assign(mainPromise, { values: () => {
12857
- return mainPromise.then((result) => {
12858
- if (!result) return [];
12859
- const isResultObject = typeof result === "object" && "rows" in result;
12860
- const valueArrays = (isResultObject ? result.rows || [] : Array.isArray(result) ? result : []).map((row) => {
12861
- if (Array.isArray(row)) return row;
12862
- return Object.values(row);
12863
- });
12864
- return Object.assign(valueArrays, {
12865
- command: isResultObject ? result.command : void 0,
12866
- count: isResultObject ? result.count : void 0
12867
- });
14195
+ _handleRecordPoolGetConnectionInSpan(spanInfo, originalGetConnection, callback, context$6) {
14196
+ const self = this;
14197
+ if (callback) {
14198
+ const wrappedCallback = (error, connection) => {
14199
+ if (error) {
14200
+ logger.debug(`[MysqlInstrumentation] MySQL Pool getConnection error: ${error.message} (${SpanUtils.getTraceInfo()})`);
14201
+ SpanUtils.endSpan(spanInfo.span, {
14202
+ code: import_src$23.SpanStatusCode.ERROR,
14203
+ message: error.message
14204
+ });
14205
+ } else {
14206
+ logger.debug(`[MysqlInstrumentation] MySQL Pool getConnection completed successfully (${SpanUtils.getTraceInfo()})`);
14207
+ if (connection) {
14208
+ self._wrap(connection, "query", self._patchQueryMethod(connection));
14209
+ self._wrap(connection, "connect", self._patchConnect(connection));
14210
+ self._wrap(connection, "beginTransaction", self._patchBeginTransaction(connection));
14211
+ self._wrap(connection, "commit", self._patchCommit(connection));
14212
+ self._wrap(connection, "rollback", self._patchRollback(connection));
14213
+ }
14214
+ SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: {
14215
+ connected: true,
14216
+ hasConnection: !!connection
14217
+ } });
14218
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
14219
+ }
14220
+ return callback(error, connection);
14221
+ };
14222
+ return originalGetConnection.call(context$6, wrappedCallback);
14223
+ } else try {
14224
+ const result = originalGetConnection.call(context$6);
14225
+ SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: {
14226
+ connected: true,
14227
+ hasConnection: true
14228
+ } });
14229
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
14230
+ return result;
14231
+ } catch (error) {
14232
+ SpanUtils.endSpan(spanInfo.span, {
14233
+ code: import_src$23.SpanStatusCode.ERROR,
14234
+ message: error.message
12868
14235
  });
12869
- } });
14236
+ throw error;
14237
+ }
12870
14238
  }
12871
- /**
12872
- * Convert PostgreSQL string values back to appropriate JavaScript types
12873
- * based on common PostgreSQL data patterns.
12874
- */
12875
- convertPostgresTypes(result) {
12876
- if (!isPostgresOutputValueType(result)) {
12877
- logger.error(`[PostgresInstrumentation] output value is not of type PostgresOutputValueType: ${JSON.stringify(result)}`);
14239
+ _handleNoOpReplayGetConnection(callback) {
14240
+ logger.debug(`[MysqlInstrumentation] Background getConnection detected, returning mock connection`);
14241
+ const mockConnection = new TdMysqlConnectionMock(this, "pool");
14242
+ if (callback) {
14243
+ process.nextTick(() => callback(null, mockConnection));
12878
14244
  return;
12879
14245
  }
12880
- if (!result) return;
12881
- const { _tdOriginalFormat: originalFormat,...convertedResult } = result;
12882
- if (originalFormat === PostgresReturnType.OBJECT) return convertedResult;
12883
- else if (originalFormat === PostgresReturnType.ARRAY) return convertedResult.rows || [];
12884
- else {
12885
- logger.error(`[PostgresInstrumentation] Invalid result format: ${JSON.stringify(result)}`);
14246
+ return mockConnection;
14247
+ }
14248
+ _handleReplayPoolGetConnection(spanInfo, callback) {
14249
+ logger.debug(`[MysqlInstrumentation] Replaying MySQL Pool getConnection`);
14250
+ const mockConnection = new TdMysqlConnectionMock(this, "pool", spanInfo);
14251
+ if (callback) {
14252
+ process.nextTick(() => callback(null, mockConnection));
12886
14253
  return;
12887
14254
  }
14255
+ return mockConnection;
12888
14256
  }
12889
- _addOutputAttributesToSpan(spanInfo, result) {
12890
- if (!result) return;
12891
- let outputValue;
12892
- if (Array.isArray(result)) {
12893
- logger.debug(`[PostgresInstrumentation] Adding output attributes to span for array result: ${JSON.stringify(result)}`);
12894
- outputValue = {
12895
- _tdOriginalFormat: PostgresReturnType.ARRAY,
12896
- rows: result
12897
- };
12898
- } else if (typeof result === "object") {
12899
- logger.debug(`[PostgresInstrumentation] Adding output attributes to span for object result: ${JSON.stringify(result)}`);
12900
- outputValue = {
12901
- _tdOriginalFormat: PostgresReturnType.OBJECT,
12902
- count: result.count,
12903
- rows: result.rows,
12904
- command: result.command
14257
+ /**
14258
+ * Handle replay of a query from a mock connection (used by TdMysqlConnectionMock)
14259
+ * Returns an EventEmitter synchronously for streaming support
14260
+ */
14261
+ handleReplayQueryFromMock(spanInfo, inputValue, callback) {
14262
+ const stackTrace = captureStackTrace(["TdMysqlConnectionMock"]);
14263
+ return this.queryMock.handleReplayQuery({
14264
+ sql: inputValue.sql,
14265
+ values: inputValue.values,
14266
+ callback,
14267
+ options: inputValue.options
14268
+ }, inputValue, spanInfo, stackTrace);
14269
+ }
14270
+ /**
14271
+ * Get wrapper function for Query.stream method
14272
+ */
14273
+ _getStreamPatchFn() {
14274
+ const self = this;
14275
+ return (originalStream) => {
14276
+ return function stream$1(streamOptions) {
14277
+ const queryInstance = this;
14278
+ const sql = queryInstance.sql;
14279
+ const values = queryInstance.values;
14280
+ const nestTables = queryInstance.nestTables;
14281
+ const inputValue = {
14282
+ sql,
14283
+ values,
14284
+ streamOptions,
14285
+ options: nestTables ? { nestTables } : void 0
14286
+ };
14287
+ if (self.mode === TuskDriftMode.REPLAY) {
14288
+ const stackTrace = captureStackTrace(["MysqlInstrumentation"]);
14289
+ return handleReplayMode({
14290
+ noOpRequestHandler: () => {
14291
+ return new stream.Readable({
14292
+ objectMode: true,
14293
+ read() {
14294
+ this.push(null);
14295
+ }
14296
+ });
14297
+ },
14298
+ isServerRequest: false,
14299
+ replayModeHandler: () => {
14300
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalStream.apply(queryInstance, arguments), {
14301
+ name: "mysql.stream",
14302
+ kind: import_src$23.SpanKind.CLIENT,
14303
+ submodule: "stream",
14304
+ packageType: PackageType.MYSQL,
14305
+ packageName: "mysql",
14306
+ instrumentationName: self.INSTRUMENTATION_NAME,
14307
+ inputValue,
14308
+ isPreAppStart: false
14309
+ }, (spanInfo) => {
14310
+ return self._handleReplayStream(inputValue, spanInfo, stackTrace, queryInstance);
14311
+ });
14312
+ }
14313
+ });
14314
+ } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
14315
+ originalFunctionCall: () => originalStream.apply(queryInstance, arguments),
14316
+ recordModeHandler: ({ isPreAppStart }) => {
14317
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalStream.apply(queryInstance, arguments), {
14318
+ name: "mysql.stream",
14319
+ kind: import_src$23.SpanKind.CLIENT,
14320
+ submodule: "stream",
14321
+ packageType: PackageType.MYSQL,
14322
+ packageName: "mysql",
14323
+ instrumentationName: self.INSTRUMENTATION_NAME,
14324
+ inputValue,
14325
+ isPreAppStart
14326
+ }, (spanInfo) => {
14327
+ return self._handleRecordStream(spanInfo, originalStream, queryInstance, streamOptions);
14328
+ });
14329
+ },
14330
+ spanKind: import_src$23.SpanKind.CLIENT
14331
+ });
14332
+ else return originalStream.apply(queryInstance, arguments);
12905
14333
  };
14334
+ };
14335
+ }
14336
+ /**
14337
+ * Helper to get query count from Query instance
14338
+ */
14339
+ _getQueryCount(queryInstance) {
14340
+ return queryInstance?._index || 0;
14341
+ }
14342
+ /**
14343
+ * Parse query arguments manually (fallback when createQuery is not available)
14344
+ */
14345
+ _parseQueryArgs(args) {
14346
+ let sql;
14347
+ let values;
14348
+ let callback;
14349
+ let options = {};
14350
+ if (typeof args[0] === "string") {
14351
+ sql = args[0];
14352
+ if (typeof args[1] === "function") callback = args[1];
14353
+ else if (Array.isArray(args[1])) {
14354
+ values = args[1];
14355
+ callback = args[2];
14356
+ }
14357
+ } else if (typeof args[0] === "object") {
14358
+ options = args[0];
14359
+ sql = options.sql;
14360
+ values = options.values;
14361
+ if (typeof args[1] === "function") callback = args[1];
14362
+ else if (Array.isArray(args[1])) {
14363
+ values = args[1];
14364
+ callback = args[2];
14365
+ }
12906
14366
  } else {
12907
- logger.error(`[PostgresInstrumentation] Invalid result format: ${JSON.stringify(result)}`);
12908
- return;
14367
+ sql = "";
14368
+ logger.debug(`[MysqlInstrumentation] Unknown query signature:`, args);
12909
14369
  }
12910
- SpanUtils.addSpanAttributes(spanInfo.span, { outputValue });
14370
+ return {
14371
+ sql,
14372
+ values,
14373
+ callback,
14374
+ options
14375
+ };
14376
+ }
14377
+ /**
14378
+ * Handle record mode for stream operations
14379
+ */
14380
+ _handleRecordStream(spanInfo, originalStream, queryInstance, streamOptions) {
14381
+ const streamInstance = originalStream.apply(queryInstance, [streamOptions]);
14382
+ const results = [];
14383
+ const fields = [];
14384
+ let error = null;
14385
+ let errQueryIndex;
14386
+ queryInstance.on("error", (err) => {
14387
+ error = err;
14388
+ errQueryIndex = queryInstance._index;
14389
+ }).on("fields", (fieldPackets, index) => {
14390
+ fields[index] = fieldPackets;
14391
+ }).on("result", (row, index) => {
14392
+ if (isMysqlOkPacket(row)) {
14393
+ results[index] = row;
14394
+ return;
14395
+ }
14396
+ if (!results[index]) results[index] = [];
14397
+ if (Array.isArray(results[index])) results[index].push(row);
14398
+ }).on("end", () => {
14399
+ const queryCount = this._getQueryCount(queryInstance);
14400
+ const isMultiStatementQuery = queryCount > 1;
14401
+ if (error) try {
14402
+ SpanUtils.endSpan(spanInfo.span, {
14403
+ code: import_src$23.SpanStatusCode.ERROR,
14404
+ message: error.message
14405
+ });
14406
+ } catch (err) {
14407
+ logger.error(`[MysqlInstrumentation] error ending span:`, err);
14408
+ }
14409
+ else try {
14410
+ const outputValue = isMultiStatementQuery ? {
14411
+ results,
14412
+ fields,
14413
+ queryCount,
14414
+ errQueryIndex
14415
+ } : {
14416
+ results: results[0],
14417
+ fields: fields[0],
14418
+ queryCount
14419
+ };
14420
+ SpanUtils.addSpanAttributes(spanInfo.span, { outputValue });
14421
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
14422
+ } catch (err) {
14423
+ logger.error(`[MysqlInstrumentation] error ending span:`, err);
14424
+ }
14425
+ logger.debug(`[MysqlInstrumentation] Stream query completed`);
14426
+ });
14427
+ return streamInstance;
14428
+ }
14429
+ /**
14430
+ * Create a replay stream for query.stream() calls
14431
+ * This is called when user calls query.stream() on a query object
14432
+ */
14433
+ _createReplayStreamForQuery(inputValue, spanInfo, stackTrace, queryEmitter, streamOptions) {
14434
+ logger.debug(`[MysqlInstrumentation] Creating replay stream for query.stream()`);
14435
+ const readableStream = new stream.Readable({
14436
+ objectMode: true,
14437
+ read() {}
14438
+ });
14439
+ queryEmitter.on("fields", (fields, index) => {
14440
+ logger.debug(`[MysqlInstrumentation] Stream received fields`);
14441
+ });
14442
+ queryEmitter.on("result", (row, index) => {
14443
+ readableStream.push(row);
14444
+ });
14445
+ queryEmitter.on("error", (err) => {
14446
+ readableStream.destroy(err);
14447
+ });
14448
+ queryEmitter.on("end", () => {
14449
+ readableStream.push(null);
14450
+ });
14451
+ return readableStream;
14452
+ }
14453
+ /**
14454
+ * Handle replay mode for stream operations
14455
+ */
14456
+ _handleReplayStream(inputValue, spanInfo, stackTrace, queryInstance) {
14457
+ logger.debug(`[MysqlInstrumentation] Replaying MySQL stream query`);
14458
+ const emitter = this.queryMock.handleReplayQuery({
14459
+ sql: inputValue.sql,
14460
+ values: inputValue.values,
14461
+ callback: void 0,
14462
+ options: inputValue.options
14463
+ }, inputValue, spanInfo, stackTrace);
14464
+ const readableStream = new stream.Readable({
14465
+ objectMode: true,
14466
+ read() {}
14467
+ });
14468
+ emitter.on("fields", (fields, index) => {
14469
+ queryInstance.emit("fields", fields, index);
14470
+ });
14471
+ emitter.on("result", (row, index) => {
14472
+ readableStream.push(row);
14473
+ queryInstance.emit("result", row, index);
14474
+ });
14475
+ emitter.on("error", (err) => {
14476
+ readableStream.destroy(err);
14477
+ queryInstance.emit("error", err);
14478
+ });
14479
+ emitter.on("end", () => {
14480
+ readableStream.push(null);
14481
+ queryInstance.emit("end");
14482
+ });
14483
+ return readableStream;
12911
14484
  }
12912
14485
  _wrap(target, propertyName, wrapper) {
12913
14486
  wrap(target, propertyName, wrapper);
@@ -13775,7 +15348,7 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
13775
15348
  };
13776
15349
  };
13777
15350
  }
13778
- _handleSimpleCallbackMethod(spanInfo, originalMethod, callback, context$4) {
15351
+ _handleSimpleCallbackMethod(spanInfo, originalMethod, callback, context$6) {
13779
15352
  if (callback) {
13780
15353
  const wrappedCallback = (error) => {
13781
15354
  if (error) {
@@ -13799,9 +15372,9 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
13799
15372
  }
13800
15373
  return callback(error);
13801
15374
  };
13802
- return originalMethod.call(context$4, wrappedCallback);
15375
+ return originalMethod.call(context$6, wrappedCallback);
13803
15376
  } else {
13804
- const result = originalMethod.call(context$4);
15377
+ const result = originalMethod.call(context$6);
13805
15378
  if (result && typeof result.then === "function") return result.then(() => {
13806
15379
  logger.debug(`[Mysql2Instrumentation] MySQL2 method completed successfully (${SpanUtils.getTraceInfo()})`);
13807
15380
  try {
@@ -13853,7 +15426,7 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
13853
15426
  };
13854
15427
  return null;
13855
15428
  }
13856
- _handleRecordQueryInSpan(spanInfo, originalQuery, queryConfig, args, context$4) {
15429
+ _handleRecordQueryInSpan(spanInfo, originalQuery, queryConfig, args, context$6) {
13857
15430
  if (!!queryConfig.callback) {
13858
15431
  const originalCallback = queryConfig.callback;
13859
15432
  const wrappedCallback = (error, results, fields) => {
@@ -13891,9 +15464,9 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
13891
15464
  } catch (error) {
13892
15465
  logger.error(`[Mysql2Instrumentation] error replacing callback:`, error, args);
13893
15466
  }
13894
- return originalQuery.apply(context$4, args);
15467
+ return originalQuery.apply(context$6, args);
13895
15468
  } else {
13896
- const result = originalQuery.apply(context$4, args);
15469
+ const result = originalQuery.apply(context$6, args);
13897
15470
  if (result && typeof result.on === "function") {
13898
15471
  const streamResults = [];
13899
15472
  let streamFields = null;
@@ -13930,7 +15503,7 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
13930
15503
  handleNoOpReplayQuery(queryConfig) {
13931
15504
  return this.queryMock.handleNoOpReplayQuery(queryConfig);
13932
15505
  }
13933
- _handleRecordPoolGetConnectionInSpan(spanInfo, originalGetConnection, callback, context$4) {
15506
+ _handleRecordPoolGetConnectionInSpan(spanInfo, originalGetConnection, callback, context$6) {
13934
15507
  if (callback) {
13935
15508
  const wrappedCallback = (error, connection) => {
13936
15509
  if (error) {
@@ -13957,8 +15530,8 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
13957
15530
  }
13958
15531
  return callback(error, connection);
13959
15532
  };
13960
- return originalGetConnection.call(context$4, wrappedCallback);
13961
- } else return originalGetConnection.call(context$4).then((connection) => {
15533
+ return originalGetConnection.call(context$6, wrappedCallback);
15534
+ } else return originalGetConnection.call(context$6).then((connection) => {
13962
15535
  logger.debug(`[Mysql2Instrumentation] MySQL2 Pool getConnection completed successfully (${SpanUtils.getTraceInfo()})`);
13963
15536
  try {
13964
15537
  SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: {
@@ -14438,7 +16011,7 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
14438
16011
  else if (args.length >= 4 && typeof args[2] === "object") config.options = args[2];
14439
16012
  return config;
14440
16013
  }
14441
- _handleRecordVerifyInSpan(spanInfo, originalVerify, verifyConfig, args, context$4) {
16014
+ _handleRecordVerifyInSpan(spanInfo, originalVerify, verifyConfig, args, context$6) {
14442
16015
  if (!!verifyConfig.callback) {
14443
16016
  const originalCallback = verifyConfig.callback;
14444
16017
  const wrappedCallback = (error, decoded) => {
@@ -14467,7 +16040,7 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
14467
16040
  logger.error(`[JsonwebtokenInstrumentation] error replacing callback:`, error, args);
14468
16041
  }
14469
16042
  try {
14470
- return originalVerify.apply(context$4, args);
16043
+ return originalVerify.apply(context$6, args);
14471
16044
  } catch (error) {
14472
16045
  try {
14473
16046
  logger.debug(`[JsonwebtokenInstrumentation] JWT verify sync error: ${error.message} (${SpanUtils.getTraceInfo()})`);
@@ -14482,7 +16055,7 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
14482
16055
  throw error;
14483
16056
  }
14484
16057
  } else try {
14485
- const result = originalVerify.apply(context$4, args);
16058
+ const result = originalVerify.apply(context$6, args);
14486
16059
  try {
14487
16060
  logger.debug(`[JsonwebtokenInstrumentation] JWT verify completed successfully (${SpanUtils.getTraceInfo()})`);
14488
16061
  this._addOutputAttributesToSpan(spanInfo, result);
@@ -14505,7 +16078,7 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
14505
16078
  throw error;
14506
16079
  }
14507
16080
  }
14508
- _handleRecordSignInSpan(spanInfo, originalSign, signConfig, args, context$4) {
16081
+ _handleRecordSignInSpan(spanInfo, originalSign, signConfig, args, context$6) {
14509
16082
  if (!!signConfig.callback) {
14510
16083
  const originalCallback = signConfig.callback;
14511
16084
  const wrappedCallback = (error, token) => {
@@ -14533,9 +16106,9 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
14533
16106
  } catch (error) {
14534
16107
  logger.error(`[JsonwebtokenInstrumentation] error replacing callback:`, error, args);
14535
16108
  }
14536
- return originalSign.apply(context$4, args);
16109
+ return originalSign.apply(context$6, args);
14537
16110
  } else try {
14538
- const result = originalSign.apply(context$4, args);
16111
+ const result = originalSign.apply(context$6, args);
14539
16112
  try {
14540
16113
  logger.debug(`[JsonwebtokenInstrumentation] JWT sign completed successfully (${SpanUtils.getTraceInfo()})`);
14541
16114
  this._addOutputAttributesToSpan(spanInfo, result);
@@ -16590,7 +18163,7 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
16590
18163
  options
16591
18164
  };
16592
18165
  }
16593
- _handleRecordUnaryRequest(spanInfo, original, context$4, parsedParams, callback) {
18166
+ _handleRecordUnaryRequest(spanInfo, original, context$6, parsedParams, callback) {
16594
18167
  let isResponseReceived = false;
16595
18168
  let isStatusEmitted = false;
16596
18169
  let hasErrorOccurred = false;
@@ -16661,7 +18234,7 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
16661
18234
  parsedParams.options,
16662
18235
  patchedCallback
16663
18236
  ];
16664
- const result = original.apply(context$4, inputArgs);
18237
+ const result = original.apply(context$6, inputArgs);
16665
18238
  result.on("metadata", (initialMetadata) => {
16666
18239
  responseMetadataInitial = serializeGrpcMetadata(initialMetadata);
16667
18240
  });
@@ -16755,7 +18328,7 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
16755
18328
  });
16756
18329
  return emitter;
16757
18330
  }
16758
- _handleRecordServerStreamRequest(spanInfo, original, context$4, parsedParams) {
18331
+ _handleRecordServerStreamRequest(spanInfo, original, context$6, parsedParams) {
16759
18332
  let hasErrorOccurred = false;
16760
18333
  let isSpanCompleted = false;
16761
18334
  let streamResponses = [];
@@ -16783,7 +18356,7 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
16783
18356
  parsedParams.metadata,
16784
18357
  parsedParams.options
16785
18358
  ];
16786
- const stream$1 = original.apply(context$4, inputArgs);
18359
+ const stream$1 = original.apply(context$6, inputArgs);
16787
18360
  stream$1.on("data", (data) => {
16788
18361
  try {
16789
18362
  const { readableBody, bufferMap, jsonableStringMap } = serializeGrpcPayload(data);
@@ -17272,8 +18845,8 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
17272
18845
  };
17273
18846
  };
17274
18847
  }
17275
- async _handleRecordDocumentGet(spanInfo, originalGet, context$4) {
17276
- const snapshot = await originalGet.call(context$4);
18848
+ async _handleRecordDocumentGet(spanInfo, originalGet, context$6) {
18849
+ const snapshot = await originalGet.call(context$6);
17277
18850
  const documentResult = {
17278
18851
  id: snapshot.id,
17279
18852
  path: snapshot.ref.path,
@@ -17551,8 +19124,8 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
17551
19124
  };
17552
19125
  };
17553
19126
  }
17554
- async _handleRecordDocumentWrite(spanInfo, originalWrite, context$4, ...args) {
17555
- const writeResult = await originalWrite.apply(context$4, args);
19127
+ async _handleRecordDocumentWrite(spanInfo, originalWrite, context$6, ...args) {
19128
+ const writeResult = await originalWrite.apply(context$6, args);
17556
19129
  const result = { writeTime: writeResult.writeTime ? {
17557
19130
  seconds: writeResult.writeTime.seconds,
17558
19131
  nanoseconds: writeResult.writeTime.nanoseconds
@@ -17644,8 +19217,8 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
17644
19217
  };
17645
19218
  };
17646
19219
  }
17647
- async _handleRecordCollectionAdd(spanInfo, originalAdd, context$4, data) {
17648
- const docRef = await originalAdd.call(context$4, data);
19220
+ async _handleRecordCollectionAdd(spanInfo, originalAdd, context$6, data) {
19221
+ const docRef = await originalAdd.call(context$6, data);
17649
19222
  const result = {
17650
19223
  id: docRef.id,
17651
19224
  path: docRef.path
@@ -17826,8 +19399,8 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
17826
19399
  };
17827
19400
  };
17828
19401
  }
17829
- async _handleRecordQueryGet(spanInfo, originalGet, context$4) {
17830
- const querySnapshot = await originalGet.call(context$4);
19402
+ async _handleRecordQueryGet(spanInfo, originalGet, context$6) {
19403
+ const querySnapshot = await originalGet.call(context$6);
17831
19404
  const queryResult = {
17832
19405
  docs: querySnapshot.docs.map((doc) => ({
17833
19406
  id: doc.id,
@@ -18532,16 +20105,16 @@ var require_suppress_tracing = /* @__PURE__ */ __commonJS({ "node_modules/@opent
18532
20105
  Object.defineProperty(exports, "__esModule", { value: true });
18533
20106
  exports.isTracingSuppressed = exports.unsuppressTracing = exports.suppressTracing = void 0;
18534
20107
  const SUPPRESS_TRACING_KEY = (0, require_src$7().createContextKey)("OpenTelemetry SDK Context Key SUPPRESS_TRACING");
18535
- function suppressTracing(context$4) {
18536
- return context$4.setValue(SUPPRESS_TRACING_KEY, true);
20108
+ function suppressTracing(context$6) {
20109
+ return context$6.setValue(SUPPRESS_TRACING_KEY, true);
18537
20110
  }
18538
20111
  exports.suppressTracing = suppressTracing;
18539
- function unsuppressTracing(context$4) {
18540
- return context$4.deleteValue(SUPPRESS_TRACING_KEY);
20112
+ function unsuppressTracing(context$6) {
20113
+ return context$6.deleteValue(SUPPRESS_TRACING_KEY);
18541
20114
  }
18542
20115
  exports.unsuppressTracing = unsuppressTracing;
18543
- function isTracingSuppressed(context$4) {
18544
- return context$4.getValue(SUPPRESS_TRACING_KEY) === true;
20116
+ function isTracingSuppressed(context$6) {
20117
+ return context$6.getValue(SUPPRESS_TRACING_KEY) === true;
18545
20118
  }
18546
20119
  exports.isTracingSuppressed = isTracingSuppressed;
18547
20120
  }) });
@@ -18632,21 +20205,21 @@ var require_W3CBaggagePropagator = /* @__PURE__ */ __commonJS({ "node_modules/@o
18632
20205
  * https://w3c.github.io/baggage/
18633
20206
  */
18634
20207
  var W3CBaggagePropagator = class {
18635
- inject(context$4, carrier, setter) {
18636
- const baggage = api_1$33.propagation.getBaggage(context$4);
18637
- if (!baggage || (0, suppress_tracing_1$3.isTracingSuppressed)(context$4)) return;
20208
+ inject(context$6, carrier, setter) {
20209
+ const baggage = api_1$33.propagation.getBaggage(context$6);
20210
+ if (!baggage || (0, suppress_tracing_1$3.isTracingSuppressed)(context$6)) return;
18638
20211
  const keyPairs = (0, utils_1$4.getKeyPairs)(baggage).filter((pair) => {
18639
20212
  return pair.length <= constants_1$4.BAGGAGE_MAX_PER_NAME_VALUE_PAIRS;
18640
20213
  }).slice(0, constants_1$4.BAGGAGE_MAX_NAME_VALUE_PAIRS);
18641
20214
  const headerValue = (0, utils_1$4.serializeKeyPairs)(keyPairs);
18642
20215
  if (headerValue.length > 0) setter.set(carrier, constants_1$4.BAGGAGE_HEADER, headerValue);
18643
20216
  }
18644
- extract(context$4, carrier, getter) {
20217
+ extract(context$6, carrier, getter) {
18645
20218
  const headerValue = getter.get(carrier, constants_1$4.BAGGAGE_HEADER);
18646
20219
  const baggageString = Array.isArray(headerValue) ? headerValue.join(constants_1$4.BAGGAGE_ITEMS_SEPARATOR) : headerValue;
18647
- if (!baggageString) return context$4;
20220
+ if (!baggageString) return context$6;
18648
20221
  const baggage = {};
18649
- if (baggageString.length === 0) return context$4;
20222
+ if (baggageString.length === 0) return context$6;
18650
20223
  baggageString.split(constants_1$4.BAGGAGE_ITEMS_SEPARATOR).forEach((entry) => {
18651
20224
  const keyPair = (0, utils_1$4.parsePairKeyValue)(entry);
18652
20225
  if (keyPair) {
@@ -18655,8 +20228,8 @@ var require_W3CBaggagePropagator = /* @__PURE__ */ __commonJS({ "node_modules/@o
18655
20228
  baggage[keyPair.key] = baggageEntry;
18656
20229
  }
18657
20230
  });
18658
- if (Object.entries(baggage).length === 0) return context$4;
18659
- return api_1$33.propagation.setBaggage(context$4, api_1$33.propagation.createBaggage(baggage));
20231
+ if (Object.entries(baggage).length === 0) return context$6;
20232
+ return api_1$33.propagation.setBaggage(context$6, api_1$33.propagation.createBaggage(baggage));
18660
20233
  }
18661
20234
  fields() {
18662
20235
  return [constants_1$4.BAGGAGE_HEADER];
@@ -21476,9 +23049,9 @@ var require_composite = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetr
21476
23049
  * @param context Context to inject
21477
23050
  * @param carrier Carrier into which context will be injected
21478
23051
  */
21479
- inject(context$4, carrier, setter) {
23052
+ inject(context$6, carrier, setter) {
21480
23053
  for (const propagator of this._propagators) try {
21481
- propagator.inject(context$4, carrier, setter);
23054
+ propagator.inject(context$6, carrier, setter);
21482
23055
  } catch (err) {
21483
23056
  api_1$29.diag.warn(`Failed to inject with ${propagator.constructor.name}. Err: ${err.message}`);
21484
23057
  }
@@ -21492,7 +23065,7 @@ var require_composite = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetr
21492
23065
  * @param context Context to add values to
21493
23066
  * @param carrier Carrier from which to extract context
21494
23067
  */
21495
- extract(context$4, carrier, getter) {
23068
+ extract(context$6, carrier, getter) {
21496
23069
  return this._propagators.reduce((ctx, propagator) => {
21497
23070
  try {
21498
23071
  return propagator.extract(ctx, carrier, getter);
@@ -21500,7 +23073,7 @@ var require_composite = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetr
21500
23073
  api_1$29.diag.warn(`Failed to extract with ${propagator.constructor.name}. Err: ${err.message}`);
21501
23074
  }
21502
23075
  return ctx;
21503
- }, context$4);
23076
+ }, context$6);
21504
23077
  }
21505
23078
  fields() {
21506
23079
  return this._fields.slice();
@@ -21652,27 +23225,27 @@ var require_W3CTraceContextPropagator = /* @__PURE__ */ __commonJS({ "node_modul
21652
23225
  * https://www.w3.org/TR/trace-context/
21653
23226
  */
21654
23227
  var W3CTraceContextPropagator = class {
21655
- inject(context$4, carrier, setter) {
21656
- const spanContext = api_1$28.trace.getSpanContext(context$4);
21657
- if (!spanContext || (0, suppress_tracing_1$2.isTracingSuppressed)(context$4) || !(0, api_1$28.isSpanContextValid)(spanContext)) return;
23228
+ inject(context$6, carrier, setter) {
23229
+ const spanContext = api_1$28.trace.getSpanContext(context$6);
23230
+ if (!spanContext || (0, suppress_tracing_1$2.isTracingSuppressed)(context$6) || !(0, api_1$28.isSpanContextValid)(spanContext)) return;
21658
23231
  const traceParent = `${VERSION}-${spanContext.traceId}-${spanContext.spanId}-0${Number(spanContext.traceFlags || api_1$28.TraceFlags.NONE).toString(16)}`;
21659
23232
  setter.set(carrier, exports.TRACE_PARENT_HEADER, traceParent);
21660
23233
  if (spanContext.traceState) setter.set(carrier, exports.TRACE_STATE_HEADER, spanContext.traceState.serialize());
21661
23234
  }
21662
- extract(context$4, carrier, getter) {
23235
+ extract(context$6, carrier, getter) {
21663
23236
  const traceParentHeader = getter.get(carrier, exports.TRACE_PARENT_HEADER);
21664
- if (!traceParentHeader) return context$4;
23237
+ if (!traceParentHeader) return context$6;
21665
23238
  const traceParent = Array.isArray(traceParentHeader) ? traceParentHeader[0] : traceParentHeader;
21666
- if (typeof traceParent !== "string") return context$4;
23239
+ if (typeof traceParent !== "string") return context$6;
21667
23240
  const spanContext = parseTraceParent(traceParent);
21668
- if (!spanContext) return context$4;
23241
+ if (!spanContext) return context$6;
21669
23242
  spanContext.isRemote = true;
21670
23243
  const traceStateHeader = getter.get(carrier, exports.TRACE_STATE_HEADER);
21671
23244
  if (traceStateHeader) {
21672
23245
  const state = Array.isArray(traceStateHeader) ? traceStateHeader.join(",") : traceStateHeader;
21673
23246
  spanContext.traceState = new TraceState_1$1.TraceState(typeof state === "string" ? state : void 0);
21674
23247
  }
21675
- return api_1$28.trace.setSpanContext(context$4, spanContext);
23248
+ return api_1$28.trace.setSpanContext(context$6, spanContext);
21676
23249
  }
21677
23250
  fields() {
21678
23251
  return [exports.TRACE_PARENT_HEADER, exports.TRACE_STATE_HEADER];
@@ -21690,16 +23263,16 @@ var require_rpc_metadata = /* @__PURE__ */ __commonJS({ "node_modules/@opentelem
21690
23263
  (function(RPCType) {
21691
23264
  RPCType["HTTP"] = "http";
21692
23265
  })(exports.RPCType || (exports.RPCType = {}));
21693
- function setRPCMetadata(context$4, meta) {
21694
- return context$4.setValue(RPC_METADATA_KEY, meta);
23266
+ function setRPCMetadata(context$6, meta) {
23267
+ return context$6.setValue(RPC_METADATA_KEY, meta);
21695
23268
  }
21696
23269
  exports.setRPCMetadata = setRPCMetadata;
21697
- function deleteRPCMetadata(context$4) {
21698
- return context$4.deleteValue(RPC_METADATA_KEY);
23270
+ function deleteRPCMetadata(context$6) {
23271
+ return context$6.deleteValue(RPC_METADATA_KEY);
21699
23272
  }
21700
23273
  exports.deleteRPCMetadata = deleteRPCMetadata;
21701
- function getRPCMetadata(context$4) {
21702
- return context$4.getValue(RPC_METADATA_KEY);
23274
+ function getRPCMetadata(context$6) {
23275
+ return context$6.getValue(RPC_METADATA_KEY);
21703
23276
  }
21704
23277
  exports.getRPCMetadata = getRPCMetadata;
21705
23278
  }) });
@@ -21773,15 +23346,15 @@ var require_ParentBasedSampler$1 = /* @__PURE__ */ __commonJS({ "node_modules/@o
21773
23346
  this._localParentSampled = (_c = config.localParentSampled) !== null && _c !== void 0 ? _c : new AlwaysOnSampler_1$4.AlwaysOnSampler();
21774
23347
  this._localParentNotSampled = (_d = config.localParentNotSampled) !== null && _d !== void 0 ? _d : new AlwaysOffSampler_1$4.AlwaysOffSampler();
21775
23348
  }
21776
- shouldSample(context$4, traceId, spanName, spanKind, attributes, links) {
21777
- const parentContext = api_1$25.trace.getSpanContext(context$4);
21778
- if (!parentContext || !(0, api_1$25.isSpanContextValid)(parentContext)) return this._root.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
23349
+ shouldSample(context$6, traceId, spanName, spanKind, attributes, links) {
23350
+ const parentContext = api_1$25.trace.getSpanContext(context$6);
23351
+ if (!parentContext || !(0, api_1$25.isSpanContextValid)(parentContext)) return this._root.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
21779
23352
  if (parentContext.isRemote) {
21780
- if (parentContext.traceFlags & api_1$25.TraceFlags.SAMPLED) return this._remoteParentSampled.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
21781
- return this._remoteParentNotSampled.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
23353
+ if (parentContext.traceFlags & api_1$25.TraceFlags.SAMPLED) return this._remoteParentSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
23354
+ return this._remoteParentNotSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
21782
23355
  }
21783
- if (parentContext.traceFlags & api_1$25.TraceFlags.SAMPLED) return this._localParentSampled.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
21784
- return this._localParentNotSampled.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
23356
+ if (parentContext.traceFlags & api_1$25.TraceFlags.SAMPLED) return this._localParentSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
23357
+ return this._localParentNotSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
21785
23358
  }
21786
23359
  toString() {
21787
23360
  return `ParentBased{root=${this._root.toString()}, remoteParentSampled=${this._remoteParentSampled.toString()}, remoteParentNotSampled=${this._remoteParentNotSampled.toString()}, localParentSampled=${this._localParentSampled.toString()}, localParentNotSampled=${this._localParentNotSampled.toString()}}`;
@@ -21806,7 +23379,7 @@ var require_TraceIdRatioBasedSampler$1 = /* @__PURE__ */ __commonJS({ "node_modu
21806
23379
  this._ratio = this._normalize(_ratio);
21807
23380
  this._upperBound = Math.floor(this._ratio * 4294967295);
21808
23381
  }
21809
- shouldSample(context$4, traceId) {
23382
+ shouldSample(context$6, traceId) {
21810
23383
  return { decision: (0, api_1$24.isValidTraceId)(traceId) && this._accumulate(traceId) < this._upperBound ? api_1$24.SamplingDecision.RECORD_AND_SAMPLED : api_1$24.SamplingDecision.NOT_RECORD };
21811
23384
  }
21812
23385
  toString() {
@@ -23392,15 +24965,15 @@ var require_AbstractAsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "nod
23392
24965
  * @param target a function or event emitter. When target or one of its callbacks is called,
23393
24966
  * the provided context will be used as the active context for the duration of the call.
23394
24967
  */
23395
- bind(context$4, target) {
23396
- if (target instanceof events_1.EventEmitter) return this._bindEventEmitter(context$4, target);
23397
- if (typeof target === "function") return this._bindFunction(context$4, target);
24968
+ bind(context$6, target) {
24969
+ if (target instanceof events_1.EventEmitter) return this._bindEventEmitter(context$6, target);
24970
+ if (typeof target === "function") return this._bindFunction(context$6, target);
23398
24971
  return target;
23399
24972
  }
23400
- _bindFunction(context$4, target) {
24973
+ _bindFunction(context$6, target) {
23401
24974
  const manager = this;
23402
24975
  const contextWrapper = function(...args) {
23403
- return manager.with(context$4, () => target.apply(this, args));
24976
+ return manager.with(context$6, () => target.apply(this, args));
23404
24977
  };
23405
24978
  Object.defineProperty(contextWrapper, "length", {
23406
24979
  enumerable: false,
@@ -23421,12 +24994,12 @@ var require_AbstractAsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "nod
23421
24994
  * @param context the context we want to bind
23422
24995
  * @param ee EventEmitter an instance of EventEmitter to patch
23423
24996
  */
23424
- _bindEventEmitter(context$4, ee) {
24997
+ _bindEventEmitter(context$6, ee) {
23425
24998
  if (this._getPatchMap(ee) !== void 0) return ee;
23426
24999
  this._createPatchMap(ee);
23427
25000
  ADD_LISTENER_METHODS.forEach((methodName) => {
23428
25001
  if (ee[methodName] === void 0) return;
23429
- ee[methodName] = this._patchAddListener(ee, ee[methodName], context$4);
25002
+ ee[methodName] = this._patchAddListener(ee, ee[methodName], context$6);
23430
25003
  });
23431
25004
  if (typeof ee.removeListener === "function") ee.removeListener = this._patchRemoveListener(ee, ee.removeListener);
23432
25005
  if (typeof ee.off === "function") ee.off = this._patchRemoveListener(ee, ee.off);
@@ -23473,7 +25046,7 @@ var require_AbstractAsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "nod
23473
25046
  * @param original reference to the patched method
23474
25047
  * @param [context] context to propagate when calling listeners
23475
25048
  */
23476
- _patchAddListener(ee, original, context$4) {
25049
+ _patchAddListener(ee, original, context$6) {
23477
25050
  const contextManager = this;
23478
25051
  return function(event, listener) {
23479
25052
  /**
@@ -23492,7 +25065,7 @@ var require_AbstractAsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "nod
23492
25065
  listeners = /* @__PURE__ */ new WeakMap();
23493
25066
  map[event] = listeners;
23494
25067
  }
23495
- const patchedListener = contextManager.bind(context$4, listener);
25068
+ const patchedListener = contextManager.bind(context$6, listener);
23496
25069
  listeners.set(listener, patchedListener);
23497
25070
  /**
23498
25071
  * See comment at the start of this function for the explanation of this property.
@@ -23542,8 +25115,8 @@ var require_AsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "node_module
23542
25115
  var _a;
23543
25116
  return (_a = this._stack[this._stack.length - 1]) !== null && _a !== void 0 ? _a : api_1$22.ROOT_CONTEXT;
23544
25117
  }
23545
- with(context$4, fn, thisArg, ...args) {
23546
- this._enterContext(context$4);
25118
+ with(context$6, fn, thisArg, ...args) {
25119
+ this._enterContext(context$6);
23547
25120
  try {
23548
25121
  return fn.call(thisArg, ...args);
23549
25122
  } finally {
@@ -23568,8 +25141,8 @@ var require_AsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "node_module
23568
25141
  */
23569
25142
  _init(uid, type) {
23570
25143
  if (type === "TIMERWRAP") return;
23571
- const context$4 = this._stack[this._stack.length - 1];
23572
- if (context$4 !== void 0) this._contexts.set(uid, context$4);
25144
+ const context$6 = this._stack[this._stack.length - 1];
25145
+ if (context$6 !== void 0) this._contexts.set(uid, context$6);
23573
25146
  }
23574
25147
  /**
23575
25148
  * Destroy hook will be called when a given context is no longer used so we can
@@ -23584,8 +25157,8 @@ var require_AsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "node_module
23584
25157
  * @param uid uid of the async context
23585
25158
  */
23586
25159
  _before(uid) {
23587
- const context$4 = this._contexts.get(uid);
23588
- if (context$4 !== void 0) this._enterContext(context$4);
25160
+ const context$6 = this._contexts.get(uid);
25161
+ if (context$6 !== void 0) this._enterContext(context$6);
23589
25162
  }
23590
25163
  /**
23591
25164
  * After hook is called just after completing the execution of a async context.
@@ -23596,8 +25169,8 @@ var require_AsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "node_module
23596
25169
  /**
23597
25170
  * Set the given context as active
23598
25171
  */
23599
- _enterContext(context$4) {
23600
- this._stack.push(context$4);
25172
+ _enterContext(context$6) {
25173
+ this._stack.push(context$6);
23601
25174
  }
23602
25175
  /**
23603
25176
  * Remove the context at the root of the stack
@@ -23626,9 +25199,9 @@ var require_AsyncLocalStorageContextManager = /* @__PURE__ */ __commonJS({ "node
23626
25199
  var _a;
23627
25200
  return (_a = this._asyncLocalStorage.getStore()) !== null && _a !== void 0 ? _a : api_1$21.ROOT_CONTEXT;
23628
25201
  }
23629
- with(context$4, fn, thisArg, ...args) {
25202
+ with(context$6, fn, thisArg, ...args) {
23630
25203
  const cb = thisArg == null ? fn : fn.bind(thisArg);
23631
- return this._asyncLocalStorage.run(context$4, cb, ...args);
25204
+ return this._asyncLocalStorage.run(context$6, cb, ...args);
23632
25205
  }
23633
25206
  enable() {
23634
25207
  return this;
@@ -23741,30 +25314,30 @@ var require_B3MultiPropagator = /* @__PURE__ */ __commonJS({ "node_modules/@open
23741
25314
  * Based on: https://github.com/openzipkin/b3-propagation
23742
25315
  */
23743
25316
  var B3MultiPropagator = class {
23744
- inject(context$4, carrier, setter) {
23745
- const spanContext = api_1$19.trace.getSpanContext(context$4);
23746
- if (!spanContext || !(0, api_1$19.isSpanContextValid)(spanContext) || (0, core_1$16.isTracingSuppressed)(context$4)) return;
23747
- const debug = context$4.getValue(common_1$1.B3_DEBUG_FLAG_KEY);
25317
+ inject(context$6, carrier, setter) {
25318
+ const spanContext = api_1$19.trace.getSpanContext(context$6);
25319
+ if (!spanContext || !(0, api_1$19.isSpanContextValid)(spanContext) || (0, core_1$16.isTracingSuppressed)(context$6)) return;
25320
+ const debug = context$6.getValue(common_1$1.B3_DEBUG_FLAG_KEY);
23748
25321
  setter.set(carrier, constants_1$3.X_B3_TRACE_ID, spanContext.traceId);
23749
25322
  setter.set(carrier, constants_1$3.X_B3_SPAN_ID, spanContext.spanId);
23750
25323
  if (debug === "1") setter.set(carrier, constants_1$3.X_B3_FLAGS, debug);
23751
25324
  else if (spanContext.traceFlags !== void 0) setter.set(carrier, constants_1$3.X_B3_SAMPLED, (api_1$19.TraceFlags.SAMPLED & spanContext.traceFlags) === api_1$19.TraceFlags.SAMPLED ? "1" : "0");
23752
25325
  }
23753
- extract(context$4, carrier, getter) {
25326
+ extract(context$6, carrier, getter) {
23754
25327
  const traceId = getTraceId(carrier, getter);
23755
25328
  const spanId = getSpanId(carrier, getter);
23756
25329
  const traceFlags = getTraceFlags(carrier, getter);
23757
25330
  const debug = getDebug(carrier, getter);
23758
25331
  if ((0, api_1$19.isValidTraceId)(traceId) && (0, api_1$19.isValidSpanId)(spanId) && isValidSampledValue(traceFlags)) {
23759
- context$4 = context$4.setValue(common_1$1.B3_DEBUG_FLAG_KEY, debug);
23760
- return api_1$19.trace.setSpanContext(context$4, {
25332
+ context$6 = context$6.setValue(common_1$1.B3_DEBUG_FLAG_KEY, debug);
25333
+ return api_1$19.trace.setSpanContext(context$6, {
23761
25334
  traceId,
23762
25335
  spanId,
23763
25336
  isRemote: true,
23764
25337
  traceFlags
23765
25338
  });
23766
25339
  }
23767
- return context$4;
25340
+ return context$6;
23768
25341
  }
23769
25342
  fields() {
23770
25343
  return [
@@ -23804,25 +25377,25 @@ var require_B3SinglePropagator = /* @__PURE__ */ __commonJS({ "node_modules/@ope
23804
25377
  * Based on: https://github.com/openzipkin/b3-propagation
23805
25378
  */
23806
25379
  var B3SinglePropagator = class {
23807
- inject(context$4, carrier, setter) {
23808
- const spanContext = api_1$18.trace.getSpanContext(context$4);
23809
- if (!spanContext || !(0, api_1$18.isSpanContextValid)(spanContext) || (0, core_1$15.isTracingSuppressed)(context$4)) return;
23810
- const samplingState = context$4.getValue(common_1.B3_DEBUG_FLAG_KEY) || spanContext.traceFlags & 1;
25380
+ inject(context$6, carrier, setter) {
25381
+ const spanContext = api_1$18.trace.getSpanContext(context$6);
25382
+ if (!spanContext || !(0, api_1$18.isSpanContextValid)(spanContext) || (0, core_1$15.isTracingSuppressed)(context$6)) return;
25383
+ const samplingState = context$6.getValue(common_1.B3_DEBUG_FLAG_KEY) || spanContext.traceFlags & 1;
23811
25384
  const value = `${spanContext.traceId}-${spanContext.spanId}-${samplingState}`;
23812
25385
  setter.set(carrier, constants_1$2.B3_CONTEXT_HEADER, value);
23813
25386
  }
23814
- extract(context$4, carrier, getter) {
25387
+ extract(context$6, carrier, getter) {
23815
25388
  const header = getter.get(carrier, constants_1$2.B3_CONTEXT_HEADER);
23816
25389
  const b3Context = Array.isArray(header) ? header[0] : header;
23817
- if (typeof b3Context !== "string") return context$4;
25390
+ if (typeof b3Context !== "string") return context$6;
23818
25391
  const match = b3Context.match(B3_CONTEXT_REGEX);
23819
- if (!match) return context$4;
25392
+ if (!match) return context$6;
23820
25393
  const [, extractedTraceId, spanId, samplingState] = match;
23821
25394
  const traceId = convertToTraceId128(extractedTraceId);
23822
- if (!(0, api_1$18.isValidTraceId)(traceId) || !(0, api_1$18.isValidSpanId)(spanId)) return context$4;
25395
+ if (!(0, api_1$18.isValidTraceId)(traceId) || !(0, api_1$18.isValidSpanId)(spanId)) return context$6;
23823
25396
  const traceFlags = convertToTraceFlags(samplingState);
23824
- if (samplingState === DEBUG_STATE) context$4 = context$4.setValue(common_1.B3_DEBUG_FLAG_KEY, samplingState);
23825
- return api_1$18.trace.setSpanContext(context$4, {
25397
+ if (samplingState === DEBUG_STATE) context$6 = context$6.setValue(common_1.B3_DEBUG_FLAG_KEY, samplingState);
25398
+ return api_1$18.trace.setSpanContext(context$6, {
23826
25399
  traceId,
23827
25400
  spanId,
23828
25401
  isRemote: true,
@@ -23876,14 +25449,14 @@ var require_B3Propagator = /* @__PURE__ */ __commonJS({ "node_modules/@opentelem
23876
25449
  this._fields = this._b3SinglePropagator.fields();
23877
25450
  }
23878
25451
  }
23879
- inject(context$4, carrier, setter) {
23880
- if ((0, core_1$14.isTracingSuppressed)(context$4)) return;
23881
- this._inject(context$4, carrier, setter);
25452
+ inject(context$6, carrier, setter) {
25453
+ if ((0, core_1$14.isTracingSuppressed)(context$6)) return;
25454
+ this._inject(context$6, carrier, setter);
23882
25455
  }
23883
- extract(context$4, carrier, getter) {
25456
+ extract(context$6, carrier, getter) {
23884
25457
  const header = getter.get(carrier, constants_1$1.B3_CONTEXT_HEADER);
23885
- if (Array.isArray(header) ? header[0] : header) return this._b3SinglePropagator.extract(context$4, carrier, getter);
23886
- else return this._b3MultiPropagator.extract(context$4, carrier, getter);
25458
+ if (Array.isArray(header) ? header[0] : header) return this._b3SinglePropagator.extract(context$6, carrier, getter);
25459
+ else return this._b3MultiPropagator.extract(context$6, carrier, getter);
23887
25460
  }
23888
25461
  fields() {
23889
25462
  return this._fields;
@@ -25945,7 +27518,7 @@ var require_Span = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/sdk
25945
27518
  *
25946
27519
  * @deprecated calling Span constructor directly is not supported. Please use tracer.startSpan.
25947
27520
  * */
25948
- constructor(parentTracer, context$4, spanName, spanContext, kind, parentSpanId, links = [], startTime, _deprecatedClock, attributes) {
27521
+ constructor(parentTracer, context$6, spanName, spanContext, kind, parentSpanId, links = [], startTime, _deprecatedClock, attributes) {
25949
27522
  this.attributes = {};
25950
27523
  this.links = [];
25951
27524
  this.events = [];
@@ -25972,7 +27545,7 @@ var require_Span = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/sdk
25972
27545
  this._attributeValueLengthLimit = this._spanLimits.attributeValueLengthLimit || 0;
25973
27546
  if (attributes != null) this.setAttributes(attributes);
25974
27547
  this._spanProcessor = parentTracer.getActiveSpanProcessor();
25975
- this._spanProcessor.onStart(this, context$4);
27548
+ this._spanProcessor.onStart(this, context$6);
25976
27549
  }
25977
27550
  spanContext() {
25978
27551
  return this._spanContext;
@@ -26227,15 +27800,15 @@ var require_ParentBasedSampler = /* @__PURE__ */ __commonJS({ "node_modules/@ope
26227
27800
  this._localParentSampled = (_c = config.localParentSampled) !== null && _c !== void 0 ? _c : new AlwaysOnSampler_1$2.AlwaysOnSampler();
26228
27801
  this._localParentNotSampled = (_d = config.localParentNotSampled) !== null && _d !== void 0 ? _d : new AlwaysOffSampler_1$2.AlwaysOffSampler();
26229
27802
  }
26230
- shouldSample(context$4, traceId, spanName, spanKind, attributes, links) {
26231
- const parentContext = api_1$16.trace.getSpanContext(context$4);
26232
- if (!parentContext || !(0, api_1$16.isSpanContextValid)(parentContext)) return this._root.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
27803
+ shouldSample(context$6, traceId, spanName, spanKind, attributes, links) {
27804
+ const parentContext = api_1$16.trace.getSpanContext(context$6);
27805
+ if (!parentContext || !(0, api_1$16.isSpanContextValid)(parentContext)) return this._root.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
26233
27806
  if (parentContext.isRemote) {
26234
- if (parentContext.traceFlags & api_1$16.TraceFlags.SAMPLED) return this._remoteParentSampled.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
26235
- return this._remoteParentNotSampled.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
27807
+ if (parentContext.traceFlags & api_1$16.TraceFlags.SAMPLED) return this._remoteParentSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
27808
+ return this._remoteParentNotSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
26236
27809
  }
26237
- if (parentContext.traceFlags & api_1$16.TraceFlags.SAMPLED) return this._localParentSampled.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
26238
- return this._localParentNotSampled.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
27810
+ if (parentContext.traceFlags & api_1$16.TraceFlags.SAMPLED) return this._localParentSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
27811
+ return this._localParentNotSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
26239
27812
  }
26240
27813
  toString() {
26241
27814
  return `ParentBased{root=${this._root.toString()}, remoteParentSampled=${this._remoteParentSampled.toString()}, remoteParentNotSampled=${this._remoteParentNotSampled.toString()}, localParentSampled=${this._localParentSampled.toString()}, localParentNotSampled=${this._localParentNotSampled.toString()}}`;
@@ -26258,7 +27831,7 @@ var require_TraceIdRatioBasedSampler = /* @__PURE__ */ __commonJS({ "node_module
26258
27831
  this._ratio = this._normalize(_ratio);
26259
27832
  this._upperBound = Math.floor(this._ratio * 4294967295);
26260
27833
  }
26261
- shouldSample(context$4, traceId) {
27834
+ shouldSample(context$6, traceId) {
26262
27835
  return { decision: (0, api_1$15.isValidTraceId)(traceId) && this._accumulate(traceId) < this._upperBound ? Sampler_1$1.SamplingDecision.RECORD_AND_SAMPLED : Sampler_1$1.SamplingDecision.NOT_RECORD };
26263
27836
  }
26264
27837
  toString() {
@@ -26660,11 +28233,11 @@ var require_Tracer = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/s
26660
28233
  * Starts a new Span or returns the default NoopSpan based on the sampling
26661
28234
  * decision.
26662
28235
  */
26663
- startSpan(name, options = {}, context$4 = api.context.active()) {
28236
+ startSpan(name, options = {}, context$6 = api.context.active()) {
26664
28237
  var _a, _b, _c;
26665
- if (options.root) context$4 = api.trace.deleteSpan(context$4);
26666
- const parentSpan = api.trace.getSpan(context$4);
26667
- if ((0, core_1$8.isTracingSuppressed)(context$4)) {
28238
+ if (options.root) context$6 = api.trace.deleteSpan(context$6);
28239
+ const parentSpan = api.trace.getSpan(context$6);
28240
+ if ((0, core_1$8.isTracingSuppressed)(context$6)) {
26668
28241
  api.diag.debug("Instrumentation suppressed, returning Noop Span");
26669
28242
  return api.trace.wrapSpanContext(api.INVALID_SPAN_CONTEXT);
26670
28243
  }
@@ -26687,7 +28260,7 @@ var require_Tracer = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/s
26687
28260
  };
26688
28261
  });
26689
28262
  const attributes = (0, core_1$8.sanitizeAttributes)(options.attributes);
26690
- const samplingResult = this._sampler.shouldSample(context$4, traceId, name, spanKind, attributes, links);
28263
+ const samplingResult = this._sampler.shouldSample(context$6, traceId, name, spanKind, attributes, links);
26691
28264
  traceState = (_c = samplingResult.traceState) !== null && _c !== void 0 ? _c : traceState;
26692
28265
  const traceFlags = samplingResult.decision === api.SamplingDecision.RECORD_AND_SAMPLED ? api.TraceFlags.SAMPLED : api.TraceFlags.NONE;
26693
28266
  const spanContext = {
@@ -26701,7 +28274,7 @@ var require_Tracer = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/s
26701
28274
  return api.trace.wrapSpanContext(spanContext);
26702
28275
  }
26703
28276
  const initAttributes = (0, core_1$8.sanitizeAttributes)(Object.assign(attributes, samplingResult.attributes));
26704
- return new Span_1$1.Span(this, context$4, name, spanContext, spanKind, parentSpanId, links, options.startTime, void 0, initAttributes);
28277
+ return new Span_1$1.Span(this, context$6, name, spanContext, spanKind, parentSpanId, links, options.startTime, void 0, initAttributes);
26705
28278
  }
26706
28279
  startActiveSpan(name, arg2, arg3, arg4) {
26707
28280
  let opts;
@@ -29748,8 +31321,8 @@ var require_MultiSpanProcessor = /* @__PURE__ */ __commonJS({ "node_modules/@ope
29748
31321
  });
29749
31322
  });
29750
31323
  }
29751
- onStart(span, context$4) {
29752
- for (const spanProcessor of this._spanProcessors) spanProcessor.onStart(span, context$4);
31324
+ onStart(span, context$6) {
31325
+ for (const spanProcessor of this._spanProcessors) spanProcessor.onStart(span, context$6);
29753
31326
  }
29754
31327
  onEnd(span) {
29755
31328
  for (const spanProcessor of this._spanProcessors) spanProcessor.onEnd(span);
@@ -30255,16 +31828,16 @@ var require_JaegerPropagator = /* @__PURE__ */ __commonJS({ "node_modules/@opent
30255
31828
  this._jaegerBaggageHeaderPrefix = (config === null || config === void 0 ? void 0 : config.customBaggageHeaderPrefix) || exports.UBER_BAGGAGE_HEADER_PREFIX;
30256
31829
  }
30257
31830
  }
30258
- inject(context$4, carrier, setter) {
30259
- const spanContext = api_1.trace.getSpanContext(context$4);
30260
- const baggage = api_1.propagation.getBaggage(context$4);
30261
- if (spanContext && (0, core_1.isTracingSuppressed)(context$4) === false) {
31831
+ inject(context$6, carrier, setter) {
31832
+ const spanContext = api_1.trace.getSpanContext(context$6);
31833
+ const baggage = api_1.propagation.getBaggage(context$6);
31834
+ if (spanContext && (0, core_1.isTracingSuppressed)(context$6) === false) {
30262
31835
  const traceFlags = `0${(spanContext.traceFlags || api_1.TraceFlags.NONE).toString(16)}`;
30263
31836
  setter.set(carrier, this._jaegerTraceHeader, `${spanContext.traceId}:${spanContext.spanId}:0:${traceFlags}`);
30264
31837
  }
30265
31838
  if (baggage) for (const [key, entry] of baggage.getAllEntries()) setter.set(carrier, `${this._jaegerBaggageHeaderPrefix}-${key}`, encodeURIComponent(entry.value));
30266
31839
  }
30267
- extract(context$4, carrier, getter) {
31840
+ extract(context$6, carrier, getter) {
30268
31841
  var _a;
30269
31842
  const uberTraceIdHeader = getter.get(carrier, this._jaegerTraceHeader);
30270
31843
  const uberTraceId = Array.isArray(uberTraceIdHeader) ? uberTraceIdHeader[0] : uberTraceIdHeader;
@@ -30275,13 +31848,13 @@ var require_JaegerPropagator = /* @__PURE__ */ __commonJS({ "node_modules/@opent
30275
31848
  value: Array.isArray(value) ? value[0] : value
30276
31849
  };
30277
31850
  });
30278
- let newContext = context$4;
31851
+ let newContext = context$6;
30279
31852
  if (typeof uberTraceId === "string") {
30280
31853
  const spanContext = deserializeSpanContext(uberTraceId);
30281
31854
  if (spanContext) newContext = api_1.trace.setSpanContext(newContext, spanContext);
30282
31855
  }
30283
31856
  if (baggageValues.length === 0) return newContext;
30284
- let currentBaggage = (_a = api_1.propagation.getBaggage(context$4)) !== null && _a !== void 0 ? _a : api_1.propagation.createBaggage();
31857
+ let currentBaggage = (_a = api_1.propagation.getBaggage(context$6)) !== null && _a !== void 0 ? _a : api_1.propagation.createBaggage();
30285
31858
  for (const baggageEntry of baggageValues) {
30286
31859
  if (baggageEntry.value === void 0) continue;
30287
31860
  currentBaggage = currentBaggage.setEntry(baggageEntry.key, { value: decodeURIComponent(baggageEntry.value) });
@@ -30484,7 +32057,7 @@ var require_src = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/sdk-
30484
32057
  //#endregion
30485
32058
  //#region package.json
30486
32059
  var import_src$1 = /* @__PURE__ */ __toESM(require_src(), 1);
30487
- var version = "0.1.14";
32060
+ var version = "0.1.16";
30488
32061
 
30489
32062
  //#endregion
30490
32063
  //#region src/version.ts
@@ -32333,6 +33906,10 @@ var TuskDriftCore = class TuskDriftCore {
32333
33906
  enabled: true,
32334
33907
  mode: this.mode
32335
33908
  });
33909
+ new MysqlInstrumentation({
33910
+ enabled: true,
33911
+ mode: this.mode
33912
+ });
32336
33913
  }
32337
33914
  initializeTracing({ baseDirectory }) {
32338
33915
  const serviceName = this.config.service?.name || "unknown";