@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.js CHANGED
@@ -13,8 +13,8 @@ import { EventEmitter } from "events";
13
13
  import { IncomingMessage } from "http";
14
14
  import * as crypto from "crypto";
15
15
  import jp from "jsonpath";
16
- import net from "net";
17
16
  import { Readable } from "stream";
17
+ import net from "net";
18
18
  import { execSync } from "child_process";
19
19
 
20
20
  //#region rolldown:runtime
@@ -4340,14 +4340,14 @@ var require_context$1 = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetr
4340
4340
  self._currentContext = parentContext ? new Map(parentContext) : /* @__PURE__ */ new Map();
4341
4341
  self.getValue = (key) => self._currentContext.get(key);
4342
4342
  self.setValue = (key, value) => {
4343
- const context$4 = new BaseContext(self._currentContext);
4344
- context$4._currentContext.set(key, value);
4345
- return context$4;
4343
+ const context$6 = new BaseContext(self._currentContext);
4344
+ context$6._currentContext.set(key, value);
4345
+ return context$6;
4346
4346
  };
4347
4347
  self.deleteValue = (key) => {
4348
- const context$4 = new BaseContext(self._currentContext);
4349
- context$4._currentContext.delete(key);
4350
- return context$4;
4348
+ const context$6 = new BaseContext(self._currentContext);
4349
+ context$6._currentContext.delete(key);
4350
+ return context$6;
4351
4351
  };
4352
4352
  }
4353
4353
  };
@@ -4603,8 +4603,8 @@ var require_context = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/
4603
4603
  * @param thisArg optional receiver to be used for calling fn
4604
4604
  * @param args optional arguments forwarded to fn
4605
4605
  */
4606
- with(context$4, fn, thisArg, ...args) {
4607
- return this._getContextManager().with(context$4, fn, thisArg, ...args);
4606
+ with(context$6, fn, thisArg, ...args) {
4607
+ return this._getContextManager().with(context$6, fn, thisArg, ...args);
4608
4608
  }
4609
4609
  /**
4610
4610
  * Bind a context to a target function or event emitter
@@ -4612,8 +4612,8 @@ var require_context = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/
4612
4612
  * @param context context to bind to the event emitter or function. Defaults to the currently active context
4613
4613
  * @param target function or event emitter to bind
4614
4614
  */
4615
- bind(context$4, target) {
4616
- return this._getContextManager().bind(context$4, target);
4615
+ bind(context$6, target) {
4616
+ return this._getContextManager().bind(context$6, target);
4617
4617
  }
4618
4618
  _getContextManager() {
4619
4619
  return (0, global_utils_1$3.getGlobal)(API_NAME$3) || NOOP_CONTEXT_MANAGER;
@@ -4714,8 +4714,8 @@ var require_context_utils = /* @__PURE__ */ __commonJS({ "node_modules/@opentele
4714
4714
  *
4715
4715
  * @param context context to get span from
4716
4716
  */
4717
- function getSpan(context$4) {
4718
- return context$4.getValue(SPAN_KEY) || void 0;
4717
+ function getSpan(context$6) {
4718
+ return context$6.getValue(SPAN_KEY) || void 0;
4719
4719
  }
4720
4720
  exports.getSpan = getSpan;
4721
4721
  /**
@@ -4731,8 +4731,8 @@ var require_context_utils = /* @__PURE__ */ __commonJS({ "node_modules/@opentele
4731
4731
  * @param context context to use as parent
4732
4732
  * @param span span to set active
4733
4733
  */
4734
- function setSpan(context$4, span) {
4735
- return context$4.setValue(SPAN_KEY, span);
4734
+ function setSpan(context$6, span) {
4735
+ return context$6.setValue(SPAN_KEY, span);
4736
4736
  }
4737
4737
  exports.setSpan = setSpan;
4738
4738
  /**
@@ -4740,8 +4740,8 @@ var require_context_utils = /* @__PURE__ */ __commonJS({ "node_modules/@opentele
4740
4740
  *
4741
4741
  * @param context context to delete span from
4742
4742
  */
4743
- function deleteSpan(context$4) {
4744
- return context$4.deleteValue(SPAN_KEY);
4743
+ function deleteSpan(context$6) {
4744
+ return context$6.deleteValue(SPAN_KEY);
4745
4745
  }
4746
4746
  exports.deleteSpan = deleteSpan;
4747
4747
  /**
@@ -4751,8 +4751,8 @@ var require_context_utils = /* @__PURE__ */ __commonJS({ "node_modules/@opentele
4751
4751
  * @param context context to set active span on
4752
4752
  * @param spanContext span context to be wrapped
4753
4753
  */
4754
- function setSpanContext(context$4, spanContext) {
4755
- return setSpan(context$4, new NonRecordingSpan_1$2.NonRecordingSpan(spanContext));
4754
+ function setSpanContext(context$6, spanContext) {
4755
+ return setSpan(context$6, new NonRecordingSpan_1$2.NonRecordingSpan(spanContext));
4756
4756
  }
4757
4757
  exports.setSpanContext = setSpanContext;
4758
4758
  /**
@@ -4760,9 +4760,9 @@ var require_context_utils = /* @__PURE__ */ __commonJS({ "node_modules/@opentele
4760
4760
  *
4761
4761
  * @param context context to get values from
4762
4762
  */
4763
- function getSpanContext(context$4) {
4763
+ function getSpanContext(context$6) {
4764
4764
  var _a;
4765
- return (_a = getSpan(context$4)) === null || _a === void 0 ? void 0 : _a.spanContext();
4765
+ return (_a = getSpan(context$6)) === null || _a === void 0 ? void 0 : _a.spanContext();
4766
4766
  }
4767
4767
  exports.getSpanContext = getSpanContext;
4768
4768
  }) });
@@ -4818,9 +4818,9 @@ var require_NoopTracer = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemet
4818
4818
  * No-op implementations of {@link Tracer}.
4819
4819
  */
4820
4820
  var NoopTracer = class {
4821
- startSpan(name, options, context$4 = contextApi.active()) {
4821
+ startSpan(name, options, context$6 = contextApi.active()) {
4822
4822
  if (Boolean(options === null || options === void 0 ? void 0 : options.root)) return new NonRecordingSpan_1.NonRecordingSpan();
4823
- const parentFromContext = context$4 && (0, context_utils_1$1.getSpanContext)(context$4);
4823
+ const parentFromContext = context$6 && (0, context_utils_1$1.getSpanContext)(context$6);
4824
4824
  if (isSpanContext(parentFromContext) && (0, spancontext_utils_1$2.isSpanContextValid)(parentFromContext)) return new NonRecordingSpan_1.NonRecordingSpan(parentFromContext);
4825
4825
  else return new NonRecordingSpan_1.NonRecordingSpan();
4826
4826
  }
@@ -4866,8 +4866,8 @@ var require_ProxyTracer = /* @__PURE__ */ __commonJS({ "node_modules/@openteleme
4866
4866
  this.version = version$1;
4867
4867
  this.options = options;
4868
4868
  }
4869
- startSpan(name, options, context$4) {
4870
- return this._getTracer().startSpan(name, options, context$4);
4869
+ startSpan(name, options, context$6) {
4870
+ return this._getTracer().startSpan(name, options, context$6);
4871
4871
  }
4872
4872
  startActiveSpan(_name, _options, _context, _fn) {
4873
4873
  const tracer = this._getTracer();
@@ -4978,31 +4978,31 @@ var require_SamplingResult = /* @__PURE__ */ __commonJS({ "node_modules/@opentel
4978
4978
  var require_span_kind = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/api/build/src/trace/span_kind.js": ((exports) => {
4979
4979
  Object.defineProperty(exports, "__esModule", { value: true });
4980
4980
  exports.SpanKind = void 0;
4981
- (function(SpanKind$22) {
4981
+ (function(SpanKind$24) {
4982
4982
  /** Default value. Indicates that the span is used internally. */
4983
- SpanKind$22[SpanKind$22["INTERNAL"] = 0] = "INTERNAL";
4983
+ SpanKind$24[SpanKind$24["INTERNAL"] = 0] = "INTERNAL";
4984
4984
  /**
4985
4985
  * Indicates that the span covers server-side handling of an RPC or other
4986
4986
  * remote request.
4987
4987
  */
4988
- SpanKind$22[SpanKind$22["SERVER"] = 1] = "SERVER";
4988
+ SpanKind$24[SpanKind$24["SERVER"] = 1] = "SERVER";
4989
4989
  /**
4990
4990
  * Indicates that the span covers the client-side wrapper around an RPC or
4991
4991
  * other remote request.
4992
4992
  */
4993
- SpanKind$22[SpanKind$22["CLIENT"] = 2] = "CLIENT";
4993
+ SpanKind$24[SpanKind$24["CLIENT"] = 2] = "CLIENT";
4994
4994
  /**
4995
4995
  * Indicates that the span describes producer sending a message to a
4996
4996
  * broker. Unlike client and server, there is no direct critical path latency
4997
4997
  * relationship between producer and consumer spans.
4998
4998
  */
4999
- SpanKind$22[SpanKind$22["PRODUCER"] = 3] = "PRODUCER";
4999
+ SpanKind$24[SpanKind$24["PRODUCER"] = 3] = "PRODUCER";
5000
5000
  /**
5001
5001
  * Indicates that the span describes consumer receiving a message from a
5002
5002
  * broker. Unlike client and server, there is no direct critical path latency
5003
5003
  * relationship between producer and consumer spans.
5004
5004
  */
5005
- SpanKind$22[SpanKind$22["CONSUMER"] = 4] = "CONSUMER";
5005
+ SpanKind$24[SpanKind$24["CONSUMER"] = 4] = "CONSUMER";
5006
5006
  })(exports.SpanKind || (exports.SpanKind = {}));
5007
5007
  }) });
5008
5008
 
@@ -5011,20 +5011,20 @@ var require_span_kind = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetr
5011
5011
  var require_status = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/api/build/src/trace/status.js": ((exports) => {
5012
5012
  Object.defineProperty(exports, "__esModule", { value: true });
5013
5013
  exports.SpanStatusCode = void 0;
5014
- (function(SpanStatusCode$12) {
5014
+ (function(SpanStatusCode$13) {
5015
5015
  /**
5016
5016
  * The default status.
5017
5017
  */
5018
- SpanStatusCode$12[SpanStatusCode$12["UNSET"] = 0] = "UNSET";
5018
+ SpanStatusCode$13[SpanStatusCode$13["UNSET"] = 0] = "UNSET";
5019
5019
  /**
5020
5020
  * The operation has been validated by an Application developer or
5021
5021
  * Operator to have completed successfully.
5022
5022
  */
5023
- SpanStatusCode$12[SpanStatusCode$12["OK"] = 1] = "OK";
5023
+ SpanStatusCode$13[SpanStatusCode$13["OK"] = 1] = "OK";
5024
5024
  /**
5025
5025
  * The operation contains an error.
5026
5026
  */
5027
- SpanStatusCode$12[SpanStatusCode$12["ERROR"] = 2] = "ERROR";
5027
+ SpanStatusCode$13[SpanStatusCode$13["ERROR"] = 2] = "ERROR";
5028
5028
  })(exports.SpanStatusCode || (exports.SpanStatusCode = {}));
5029
5029
  }) });
5030
5030
 
@@ -5256,8 +5256,8 @@ var require_NoopTextMapPropagator = /* @__PURE__ */ __commonJS({ "node_modules/@
5256
5256
  /** Noop inject function does nothing */
5257
5257
  inject(_context, _carrier) {}
5258
5258
  /** Noop extract function does nothing and returns the input context */
5259
- extract(context$4, _carrier) {
5260
- return context$4;
5259
+ extract(context$6, _carrier) {
5260
+ return context$6;
5261
5261
  }
5262
5262
  fields() {
5263
5263
  return [];
@@ -5282,8 +5282,8 @@ var require_context_helpers = /* @__PURE__ */ __commonJS({ "node_modules/@opente
5282
5282
  * @param {Context} Context that manage all context values
5283
5283
  * @returns {Baggage} Extracted baggage from the context
5284
5284
  */
5285
- function getBaggage(context$4) {
5286
- return context$4.getValue(BAGGAGE_KEY) || void 0;
5285
+ function getBaggage(context$6) {
5286
+ return context$6.getValue(BAGGAGE_KEY) || void 0;
5287
5287
  }
5288
5288
  exports.getBaggage = getBaggage;
5289
5289
  /**
@@ -5301,8 +5301,8 @@ var require_context_helpers = /* @__PURE__ */ __commonJS({ "node_modules/@opente
5301
5301
  * @param {Context} Context that manage all context values
5302
5302
  * @param {Baggage} baggage that will be set in the actual context
5303
5303
  */
5304
- function setBaggage(context$4, baggage) {
5305
- return context$4.setValue(BAGGAGE_KEY, baggage);
5304
+ function setBaggage(context$6, baggage) {
5305
+ return context$6.setValue(BAGGAGE_KEY, baggage);
5306
5306
  }
5307
5307
  exports.setBaggage = setBaggage;
5308
5308
  /**
@@ -5310,8 +5310,8 @@ var require_context_helpers = /* @__PURE__ */ __commonJS({ "node_modules/@opente
5310
5310
  *
5311
5311
  * @param {Context} Context that manage all context values
5312
5312
  */
5313
- function deleteBaggage(context$4) {
5314
- return context$4.deleteValue(BAGGAGE_KEY);
5313
+ function deleteBaggage(context$6) {
5314
+ return context$6.deleteValue(BAGGAGE_KEY);
5315
5315
  }
5316
5316
  exports.deleteBaggage = deleteBaggage;
5317
5317
  }) });
@@ -5361,8 +5361,8 @@ var require_propagation = /* @__PURE__ */ __commonJS({ "node_modules/@openteleme
5361
5361
  * @param carrier carrier to inject context into
5362
5362
  * @param setter Function used to set values on the carrier
5363
5363
  */
5364
- inject(context$4, carrier, setter = TextMapPropagator_1$1.defaultTextMapSetter) {
5365
- return this._getGlobalPropagator().inject(context$4, carrier, setter);
5364
+ inject(context$6, carrier, setter = TextMapPropagator_1$1.defaultTextMapSetter) {
5365
+ return this._getGlobalPropagator().inject(context$6, carrier, setter);
5366
5366
  }
5367
5367
  /**
5368
5368
  * Extract context from a carrier
@@ -5371,8 +5371,8 @@ var require_propagation = /* @__PURE__ */ __commonJS({ "node_modules/@openteleme
5371
5371
  * @param carrier Carrier to extract context from
5372
5372
  * @param getter Function used to extract keys from a carrier
5373
5373
  */
5374
- extract(context$4, carrier, getter = TextMapPropagator_1$1.defaultTextMapGetter) {
5375
- return this._getGlobalPropagator().extract(context$4, carrier, getter);
5374
+ extract(context$6, carrier, getter = TextMapPropagator_1$1.defaultTextMapGetter) {
5375
+ return this._getGlobalPropagator().extract(context$6, carrier, getter);
5376
5376
  }
5377
5377
  /**
5378
5378
  * Return a list of all fields which may be used by the propagator.
@@ -5673,7 +5673,7 @@ var require_src$7 = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/ap
5673
5673
 
5674
5674
  //#endregion
5675
5675
  //#region node_modules/@use-tusk/drift-schemas/dist/duration-B3fwb4jB.js
5676
- var import_src$32 = /* @__PURE__ */ __toESM(require_src$7(), 1);
5676
+ var import_src$34 = /* @__PURE__ */ __toESM(require_src$7(), 1);
5677
5677
  var import_commonjs$9 = /* @__PURE__ */ __toESM(require_commonjs$2(), 1);
5678
5678
  var Duration$Type = class extends import_commonjs$9.MessageType {
5679
5679
  constructor() {
@@ -6986,11 +6986,11 @@ const Trace = new Trace$Type();
6986
6986
  const toStruct = (obj) => obj ? objectToProtobufStruct(obj) : void 0;
6987
6987
  const mapOtToPb = (k) => {
6988
6988
  switch (k) {
6989
- case import_src$32.SpanKind.INTERNAL: return SpanKind.INTERNAL;
6990
- case import_src$32.SpanKind.SERVER: return SpanKind.SERVER;
6991
- case import_src$32.SpanKind.CLIENT: return SpanKind.CLIENT;
6992
- case import_src$32.SpanKind.PRODUCER: return SpanKind.PRODUCER;
6993
- case import_src$32.SpanKind.CONSUMER: return SpanKind.CONSUMER;
6989
+ case import_src$34.SpanKind.INTERNAL: return SpanKind.INTERNAL;
6990
+ case import_src$34.SpanKind.SERVER: return SpanKind.SERVER;
6991
+ case import_src$34.SpanKind.CLIENT: return SpanKind.CLIENT;
6992
+ case import_src$34.SpanKind.PRODUCER: return SpanKind.PRODUCER;
6993
+ case import_src$34.SpanKind.CONSUMER: return SpanKind.CONSUMER;
6994
6994
  default: return SpanKind.UNSPECIFIED;
6995
6995
  }
6996
6996
  };
@@ -7394,13 +7394,13 @@ var TdInstrumentationNodeModule = class {
7394
7394
 
7395
7395
  //#endregion
7396
7396
  //#region src/core/types.ts
7397
- var import_src$31 = /* @__PURE__ */ __toESM(require_src$7(), 1);
7397
+ var import_src$33 = /* @__PURE__ */ __toESM(require_src$7(), 1);
7398
7398
  const TD_INSTRUMENTATION_LIBRARY_NAME = "tusk-drift-sdk";
7399
- const REPLAY_TRACE_ID_CONTEXT_KEY = (0, import_src$31.createContextKey)("td.replayTraceId");
7400
- const SPAN_KIND_CONTEXT_KEY = (0, import_src$31.createContextKey)("td.spanKind");
7401
- const IS_PRE_APP_START_CONTEXT_KEY = (0, import_src$31.createContextKey)("td.isPreAppStart");
7402
- const STOP_RECORDING_CHILD_SPANS_CONTEXT_KEY = (0, import_src$31.createContextKey)("td.stopRecordingChildSpans");
7403
- const CALLING_LIBRARY_CONTEXT_KEY = (0, import_src$31.createContextKey)("td.callingLibrary");
7399
+ const REPLAY_TRACE_ID_CONTEXT_KEY = (0, import_src$33.createContextKey)("td.replayTraceId");
7400
+ const SPAN_KIND_CONTEXT_KEY = (0, import_src$33.createContextKey)("td.spanKind");
7401
+ const IS_PRE_APP_START_CONTEXT_KEY = (0, import_src$33.createContextKey)("td.isPreAppStart");
7402
+ const STOP_RECORDING_CHILD_SPANS_CONTEXT_KEY = (0, import_src$33.createContextKey)("td.stopRecordingChildSpans");
7403
+ const CALLING_LIBRARY_CONTEXT_KEY = (0, import_src$33.createContextKey)("td.callingLibrary");
7404
7404
  let TdSpanAttributes = /* @__PURE__ */ function(TdSpanAttributes$1) {
7405
7405
  /**
7406
7406
  * Presentational information:
@@ -7512,7 +7512,7 @@ TraceBlockingManager.instance = null;
7512
7512
 
7513
7513
  //#endregion
7514
7514
  //#region src/core/tracing/SpanUtils.ts
7515
- var import_src$30 = /* @__PURE__ */ __toESM(require_src$7(), 1);
7515
+ var import_src$32 = /* @__PURE__ */ __toESM(require_src$7(), 1);
7516
7516
  var SpanUtils = class SpanUtils {
7517
7517
  /**
7518
7518
  * Creates a new span and returns span info including trace ID and span ID
@@ -7520,8 +7520,8 @@ var SpanUtils = class SpanUtils {
7520
7520
  static createSpan(options) {
7521
7521
  try {
7522
7522
  const tracer = TuskDriftCore.getInstance().getTracer();
7523
- const parentContext = options.parentContext || import_src$30.context.active();
7524
- const activeSpan = import_src$30.trace.getSpan(parentContext);
7523
+ const parentContext = options.parentContext || import_src$32.context.active();
7524
+ const activeSpan = import_src$32.trace.getSpan(parentContext);
7525
7525
  if (activeSpan) {
7526
7526
  const parentTraceId = activeSpan.spanContext().traceId;
7527
7527
  if (TraceBlockingManager.getInstance().isTraceBlocked(parentTraceId)) {
@@ -7530,11 +7530,11 @@ var SpanUtils = class SpanUtils {
7530
7530
  }
7531
7531
  }
7532
7532
  const span = tracer.startSpan(options.name, {
7533
- kind: options.kind || import_src$30.SpanKind.CLIENT,
7533
+ kind: options.kind || import_src$32.SpanKind.CLIENT,
7534
7534
  attributes: options.attributes || {}
7535
7535
  }, parentContext);
7536
7536
  const spanContext = span.spanContext();
7537
- 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);
7537
+ 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);
7538
7538
  return {
7539
7539
  traceId: spanContext.traceId,
7540
7540
  spanId: spanContext.spanId,
@@ -7551,7 +7551,7 @@ var SpanUtils = class SpanUtils {
7551
7551
  * Executes a function within a span context
7552
7552
  */
7553
7553
  static withSpan(spanInfo, fn) {
7554
- return import_src$30.context.with(spanInfo.context, fn);
7554
+ return import_src$32.context.with(spanInfo.context, fn);
7555
7555
  }
7556
7556
  /**
7557
7557
  * Execute a function within a properly configured span
@@ -7568,9 +7568,9 @@ var SpanUtils = class SpanUtils {
7568
7568
  * @returns The result of the function execution
7569
7569
  */
7570
7570
  static createAndExecuteSpan(mode, originalFunctionCall, options, fn) {
7571
- const spanContext = import_src$30.trace.getActiveSpan()?.spanContext();
7571
+ const spanContext = import_src$32.trace.getActiveSpan()?.spanContext();
7572
7572
  if (spanContext) {
7573
- if (import_src$30.context.active().getValue(STOP_RECORDING_CHILD_SPANS_CONTEXT_KEY)) {
7573
+ if (import_src$32.context.active().getValue(STOP_RECORDING_CHILD_SPANS_CONTEXT_KEY)) {
7574
7574
  logger.debug(`[SpanUtils] Stopping recording of child spans for span ${spanContext.spanId}, packageName: ${options.packageName}, instrumentationName: ${options.instrumentationName}`);
7575
7575
  return originalFunctionCall();
7576
7576
  }
@@ -7608,15 +7608,15 @@ var SpanUtils = class SpanUtils {
7608
7608
  */
7609
7609
  static getCurrentSpanInfo() {
7610
7610
  try {
7611
- const activeSpan = import_src$30.trace.getActiveSpan();
7611
+ const activeSpan = import_src$32.trace.getActiveSpan();
7612
7612
  if (!activeSpan) return null;
7613
7613
  const spanContext = activeSpan.spanContext();
7614
7614
  return {
7615
7615
  traceId: spanContext.traceId,
7616
7616
  spanId: spanContext.spanId,
7617
7617
  span: activeSpan,
7618
- context: import_src$30.context.active(),
7619
- isPreAppStart: import_src$30.context.active().getValue(IS_PRE_APP_START_CONTEXT_KEY)
7618
+ context: import_src$32.context.active(),
7619
+ isPreAppStart: import_src$32.context.active().getValue(IS_PRE_APP_START_CONTEXT_KEY)
7620
7620
  };
7621
7621
  } catch (error) {
7622
7622
  logger.error("SpanUtils error getting current span info:", error);
@@ -7680,7 +7680,7 @@ var SpanUtils = class SpanUtils {
7680
7680
  }
7681
7681
  static setCurrentReplayTraceId(replayTraceId) {
7682
7682
  try {
7683
- return import_src$30.context.active().setValue(REPLAY_TRACE_ID_CONTEXT_KEY, replayTraceId);
7683
+ return import_src$32.context.active().setValue(REPLAY_TRACE_ID_CONTEXT_KEY, replayTraceId);
7684
7684
  } catch (error) {
7685
7685
  logger.error("SpanUtils error setting current replay trace id:", error);
7686
7686
  return null;
@@ -7691,7 +7691,7 @@ var SpanUtils = class SpanUtils {
7691
7691
  */
7692
7692
  static getCurrentReplayTraceId() {
7693
7693
  try {
7694
- return import_src$30.context.active().getValue(REPLAY_TRACE_ID_CONTEXT_KEY);
7694
+ return import_src$32.context.active().getValue(REPLAY_TRACE_ID_CONTEXT_KEY);
7695
7695
  } catch (error) {
7696
7696
  logger.error("SpanUtils error getting current replay trace id:", error);
7697
7697
  return null;
@@ -8353,7 +8353,7 @@ function findMockResponseSync({ mockRequestData, tuskDrift, inputValueSchemaMerg
8353
8353
 
8354
8354
  //#endregion
8355
8355
  //#region src/instrumentation/libraries/http/mocks/TdMockClientRequest.ts
8356
- var import_src$29 = /* @__PURE__ */ __toESM(require_src$7(), 1);
8356
+ var import_src$31 = /* @__PURE__ */ __toESM(require_src$7(), 1);
8357
8357
  let ClientRequest;
8358
8358
  /**
8359
8359
  * Mock ClientRequest implementation for Tusk Drift HTTP replay
@@ -8524,7 +8524,7 @@ var TdMockClientRequest = class TdMockClientRequest extends EventEmitter {
8524
8524
  instrumentationName: this.INSTRUMENTATION_NAME,
8525
8525
  submoduleName: rawInputValue.method,
8526
8526
  inputValue,
8527
- kind: import_src$29.SpanKind.CLIENT,
8527
+ kind: import_src$31.SpanKind.CLIENT,
8528
8528
  stackTrace: this.stackTrace
8529
8529
  },
8530
8530
  tuskDrift: this.tuskDrift,
@@ -8701,7 +8701,7 @@ var HttpReplayHooks = class {
8701
8701
 
8702
8702
  //#endregion
8703
8703
  //#region src/instrumentation/core/utils/modeUtils.ts
8704
- var import_src$28 = /* @__PURE__ */ __toESM(require_src$7(), 1);
8704
+ var import_src$30 = /* @__PURE__ */ __toESM(require_src$7(), 1);
8705
8705
  /**
8706
8706
  * Utility function that abstracts the common record mode pattern of checking for current span context
8707
8707
  * and deciding whether to execute record mode logic or just call the original function.
@@ -8722,7 +8722,7 @@ function handleRecordMode({ originalFunctionCall, recordModeHandler, spanKind })
8722
8722
  return originalFunctionCall();
8723
8723
  }
8724
8724
  if (!isAppReady) return recordModeHandler({ isPreAppStart: true });
8725
- if (!currentSpanInfo && spanKind !== import_src$28.SpanKind.SERVER || currentSpanInfo?.isPreAppStart) return originalFunctionCall();
8725
+ if (!currentSpanInfo && spanKind !== import_src$30.SpanKind.SERVER || currentSpanInfo?.isPreAppStart) return originalFunctionCall();
8726
8726
  else return recordModeHandler({ isPreAppStart: false });
8727
8727
  }
8728
8728
  /**
@@ -10202,7 +10202,7 @@ function captureStackTrace(excludeClassNames = []) {
10202
10202
 
10203
10203
  //#endregion
10204
10204
  //#region src/instrumentation/libraries/http/HttpTransformEngine.ts
10205
- var import_src$27 = /* @__PURE__ */ __toESM(require_src$7(), 1);
10205
+ var import_src$29 = /* @__PURE__ */ __toESM(require_src$7(), 1);
10206
10206
  /**
10207
10207
  * Creates an empty HttpClientInputValue object for dropped spans
10208
10208
  */
@@ -10255,7 +10255,7 @@ var HttpTransformEngine = class {
10255
10255
  const testSpan = {
10256
10256
  traceId: "",
10257
10257
  spanId: "",
10258
- kind: import_src$27.SpanKind.SERVER,
10258
+ kind: import_src$29.SpanKind.SERVER,
10259
10259
  protocol: "http",
10260
10260
  inputValue: {
10261
10261
  method,
@@ -10278,7 +10278,7 @@ var HttpTransformEngine = class {
10278
10278
  const testSpan = {
10279
10279
  traceId: "",
10280
10280
  spanId: "",
10281
- kind: import_src$27.SpanKind.CLIENT,
10281
+ kind: import_src$29.SpanKind.CLIENT,
10282
10282
  protocol: inputValue.protocol || "http",
10283
10283
  inputValue: clonedInputValue
10284
10284
  };
@@ -10305,8 +10305,8 @@ var HttpTransformEngine = class {
10305
10305
  const matcherFunction = this.compileMatcher(matcher);
10306
10306
  if (action.type === "drop") return (span) => {
10307
10307
  if (!matcherFunction(span)) return;
10308
- if (span.inputValue) span.inputValue = span.kind === import_src$27.SpanKind.CLIENT ? createEmptyClientInputValue(span.protocol) : createEmptyServerInputValue();
10309
- if (span.outputValue) span.outputValue = span.kind === import_src$27.SpanKind.CLIENT ? createEmptyClientOutputValue() : createEmptyServerOutputValue();
10308
+ if (span.inputValue) span.inputValue = span.kind === import_src$29.SpanKind.CLIENT ? createEmptyClientInputValue(span.protocol) : createEmptyServerInputValue();
10309
+ if (span.outputValue) span.outputValue = span.kind === import_src$29.SpanKind.CLIENT ? createEmptyClientOutputValue() : createEmptyServerOutputValue();
10310
10310
  return {
10311
10311
  type: "drop",
10312
10312
  field: "entire_span",
@@ -10336,8 +10336,8 @@ var HttpTransformEngine = class {
10336
10336
  }
10337
10337
  compileMatcher(matcher) {
10338
10338
  const checks = [];
10339
- if (matcher.direction === "outbound") checks.push((span) => span.kind === import_src$27.SpanKind.CLIENT);
10340
- else if (matcher.direction === "inbound") checks.push((span) => span.kind === import_src$27.SpanKind.SERVER);
10339
+ if (matcher.direction === "outbound") checks.push((span) => span.kind === import_src$29.SpanKind.CLIENT);
10340
+ else if (matcher.direction === "inbound") checks.push((span) => span.kind === import_src$29.SpanKind.SERVER);
10341
10341
  if (matcher.method) if (matcher.method.length === 0) {} else {
10342
10342
  const methods = matcher.method.map((method) => method.toUpperCase());
10343
10343
  checks.push((span) => {
@@ -10565,7 +10565,7 @@ var HttpTransformEngine = class {
10565
10565
 
10566
10566
  //#endregion
10567
10567
  //#region src/instrumentation/libraries/http/Instrumentation.ts
10568
- var import_src$26 = /* @__PURE__ */ __toESM(require_src$7(), 1);
10568
+ var import_src$28 = /* @__PURE__ */ __toESM(require_src$7(), 1);
10569
10569
  var HttpInstrumentation = class extends TdInstrumentationBase {
10570
10570
  constructor(config) {
10571
10571
  super("http", config);
@@ -10659,10 +10659,10 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10659
10659
  }
10660
10660
  const ctxWithReplayTraceId = SpanUtils.setCurrentReplayTraceId(replayTraceId);
10661
10661
  if (!ctxWithReplayTraceId) throw new Error("Error setting current replay trace id");
10662
- return import_src$26.context.with(ctxWithReplayTraceId, () => {
10662
+ return import_src$28.context.with(ctxWithReplayTraceId, () => {
10663
10663
  return SpanUtils.createAndExecuteSpan(this.mode, () => originalHandler.call(this), {
10664
10664
  name: `${target}`,
10665
- kind: import_src$26.SpanKind.SERVER,
10665
+ kind: import_src$28.SpanKind.SERVER,
10666
10666
  packageName: spanProtocol,
10667
10667
  submodule: method,
10668
10668
  packageType: PackageType.HTTP,
@@ -10707,7 +10707,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10707
10707
  logger.debug(`[HttpInstrumentation] Http inbound request arriving, inputValue: ${JSON.stringify(inputValue)}`);
10708
10708
  return SpanUtils.createAndExecuteSpan(this.mode, () => originalHandler.call(this), {
10709
10709
  name: `${target}`,
10710
- kind: import_src$26.SpanKind.SERVER,
10710
+ kind: import_src$28.SpanKind.SERVER,
10711
10711
  packageName: spanProtocol,
10712
10712
  packageType: PackageType.HTTP,
10713
10713
  submodule: method,
@@ -10727,7 +10727,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10727
10727
  });
10728
10728
  });
10729
10729
  },
10730
- spanKind: import_src$26.SpanKind.SERVER
10730
+ spanKind: import_src$28.SpanKind.SERVER
10731
10731
  });
10732
10732
  } else return originalHandler.call(this);
10733
10733
  }
@@ -10744,8 +10744,8 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10744
10744
  _handleInboundRequestInSpan({ req, res, originalHandler, spanInfo, inputValue, schemaMerges, protocol }) {
10745
10745
  const self = this;
10746
10746
  const spanProtocol = this._normalizeProtocol(protocol, "http");
10747
- import_src$26.context.bind(spanInfo.context, req);
10748
- import_src$26.context.bind(spanInfo.context, res);
10747
+ import_src$28.context.bind(spanInfo.context, req);
10748
+ import_src$28.context.bind(spanInfo.context, res);
10749
10749
  let completeInputValue = inputValue;
10750
10750
  this._captureServerRequestBody(req, spanInfo, inputValue, schemaMerges, (updatedInputValue) => {
10751
10751
  completeInputValue = updatedInputValue;
@@ -10783,7 +10783,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10783
10783
  const spanData = {
10784
10784
  traceId: spanInfo.traceId,
10785
10785
  spanId: spanInfo.spanId,
10786
- kind: import_src$26.SpanKind.SERVER,
10786
+ kind: import_src$28.SpanKind.SERVER,
10787
10787
  protocol: spanProtocol,
10788
10788
  inputValue: completeInputValue,
10789
10789
  outputValue
@@ -10804,9 +10804,9 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10804
10804
  });
10805
10805
  EnvVarTracker.clearEnvVars(spanInfo.traceId);
10806
10806
  const status = statusCode >= 400 ? {
10807
- code: import_src$26.SpanStatusCode.ERROR,
10807
+ code: import_src$28.SpanStatusCode.ERROR,
10808
10808
  message: `HTTP ${statusCode}`
10809
- } : { code: import_src$26.SpanStatusCode.OK };
10809
+ } : { code: import_src$28.SpanStatusCode.OK };
10810
10810
  SpanUtils.setStatus(spanInfo.span, status);
10811
10811
  const decodedType = getDecodedType(outputValue.headers?.["content-type"] || "");
10812
10812
  if (decodedType && !ACCEPTABLE_CONTENT_TYPES.has(decodedType)) {
@@ -10855,7 +10855,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10855
10855
  outputSchemaHash: JsonSchemaHelper.generateDeterministicHash(outputSchema),
10856
10856
  inputValueHash,
10857
10857
  outputValueHash,
10858
- kind: import_src$26.SpanKind.SERVER,
10858
+ kind: import_src$28.SpanKind.SERVER,
10859
10859
  packageType: PackageType.HTTP,
10860
10860
  status: {
10861
10861
  code: statusCode >= 400 ? StatusCode.ERROR : StatusCode.OK,
@@ -10884,7 +10884,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10884
10884
  try {
10885
10885
  logger.debug(`[HttpInstrumentation] Server request error: ${error.message} (${SpanUtils.getTraceInfo()})`);
10886
10886
  SpanUtils.endSpan(spanInfo.span, {
10887
- code: import_src$26.SpanStatusCode.ERROR,
10887
+ code: import_src$28.SpanStatusCode.ERROR,
10888
10888
  message: error.message
10889
10889
  });
10890
10890
  } catch (error$1) {
@@ -10895,7 +10895,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10895
10895
  try {
10896
10896
  logger.debug(`[HttpInstrumentation] Server response 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) {
@@ -11100,7 +11100,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11100
11100
  inputValue: completeInputValue
11101
11101
  });
11102
11102
  SpanUtils.endSpan(spanInfo.span, {
11103
- code: import_src$26.SpanStatusCode.ERROR,
11103
+ code: import_src$28.SpanStatusCode.ERROR,
11104
11104
  message: error.message
11105
11105
  });
11106
11106
  } catch (error$1) {
@@ -11117,7 +11117,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11117
11117
  const spanData = {
11118
11118
  traceId: spanInfo.traceId,
11119
11119
  spanId: spanInfo.spanId,
11120
- kind: import_src$26.SpanKind.CLIENT,
11120
+ kind: import_src$28.SpanKind.CLIENT,
11121
11121
  protocol: normalizedProtocol,
11122
11122
  inputValue,
11123
11123
  outputValue
@@ -11130,9 +11130,9 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11130
11130
  transformMetadata: spanData.transformMetadata ? spanData.transformMetadata : void 0
11131
11131
  });
11132
11132
  const status = statusCode >= 400 ? {
11133
- code: import_src$26.SpanStatusCode.ERROR,
11133
+ code: import_src$28.SpanStatusCode.ERROR,
11134
11134
  message: `HTTP ${statusCode}`
11135
- } : { code: import_src$26.SpanStatusCode.OK };
11135
+ } : { code: import_src$28.SpanStatusCode.OK };
11136
11136
  SpanUtils.endSpan(spanInfo.span, status);
11137
11137
  }
11138
11138
  _captureHeadersFromRawHeaders(rawHeaders) {
@@ -11186,7 +11186,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11186
11186
  };
11187
11187
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalRequest.apply(this, args), {
11188
11188
  name: requestOptions.path || `${requestProtocol.toUpperCase()} ${method}`,
11189
- kind: import_src$26.SpanKind.CLIENT,
11189
+ kind: import_src$28.SpanKind.CLIENT,
11190
11190
  packageName: requestProtocol,
11191
11191
  packageType: PackageType.HTTP,
11192
11192
  instrumentationName: self.INSTRUMENTATION_NAME,
@@ -11221,7 +11221,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11221
11221
  };
11222
11222
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalRequest.apply(this, args), {
11223
11223
  name: requestOptions.path || `${requestProtocol.toUpperCase()} ${method}`,
11224
- kind: import_src$26.SpanKind.CLIENT,
11224
+ kind: import_src$28.SpanKind.CLIENT,
11225
11225
  packageName: requestProtocol,
11226
11226
  packageType: PackageType.HTTP,
11227
11227
  instrumentationName: self.INSTRUMENTATION_NAME,
@@ -11233,7 +11233,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11233
11233
  return self._handleOutboundRequestInSpan(originalRequest, args, spanInfo, inputValue, { headers: { matchImportance: 0 } });
11234
11234
  });
11235
11235
  },
11236
- spanKind: import_src$26.SpanKind.CLIENT
11236
+ spanKind: import_src$28.SpanKind.CLIENT
11237
11237
  });
11238
11238
  else return originalRequest.apply(this, args);
11239
11239
  };
@@ -11279,7 +11279,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11279
11279
  };
11280
11280
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalGet.apply(this, args), {
11281
11281
  name: requestOptions.path || `${requestProtocol.toUpperCase()} ${method}`,
11282
- kind: import_src$26.SpanKind.CLIENT,
11282
+ kind: import_src$28.SpanKind.CLIENT,
11283
11283
  packageName: requestProtocol,
11284
11284
  packageType: PackageType.HTTP,
11285
11285
  instrumentationName: self.INSTRUMENTATION_NAME,
@@ -11313,7 +11313,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11313
11313
  };
11314
11314
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalGet.apply(this, args), {
11315
11315
  name: requestOptions.path || `${requestProtocol.toUpperCase()} ${method}`,
11316
- kind: import_src$26.SpanKind.CLIENT,
11316
+ kind: import_src$28.SpanKind.CLIENT,
11317
11317
  packageName: requestProtocol,
11318
11318
  packageType: PackageType.HTTP,
11319
11319
  instrumentationName: self.INSTRUMENTATION_NAME,
@@ -11325,7 +11325,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11325
11325
  return self._handleOutboundRequestInSpan(originalGet, args, spanInfo, inputValue, { headers: { matchImportance: 0 } });
11326
11326
  });
11327
11327
  },
11328
- spanKind: import_src$26.SpanKind.CLIENT
11328
+ spanKind: import_src$28.SpanKind.CLIENT
11329
11329
  });
11330
11330
  else return originalGet.apply(this, args);
11331
11331
  };
@@ -11460,7 +11460,7 @@ var EnvInstrumentation = class extends TdInstrumentationBase {
11460
11460
 
11461
11461
  //#endregion
11462
11462
  //#region src/instrumentation/libraries/date/Instrumentation.ts
11463
- var import_src$25 = /* @__PURE__ */ __toESM(require_src$7(), 1);
11463
+ var import_src$27 = /* @__PURE__ */ __toESM(require_src$7(), 1);
11464
11464
  /**
11465
11465
  * Date instrumentation that provides consistent dates in replay mode.
11466
11466
  * In replay mode, new Date() calls return the latest mock response timestamp.
@@ -11499,7 +11499,7 @@ var DateInstrumentation = class DateInstrumentation extends TdInstrumentationBas
11499
11499
  if (this.mode !== TuskDriftMode.REPLAY) return this._callOriginalDate(args, isConstructorCall);
11500
11500
  const currentSpanInfo = SpanUtils.getCurrentSpanInfo();
11501
11501
  if (!currentSpanInfo) return this._callOriginalDate(args, isConstructorCall);
11502
- if (currentSpanInfo.context.getValue(SPAN_KIND_CONTEXT_KEY) !== import_src$25.SpanKind.SERVER) return this._callOriginalDate(args, isConstructorCall);
11502
+ if (currentSpanInfo.context.getValue(SPAN_KIND_CONTEXT_KEY) !== import_src$27.SpanKind.SERVER) return this._callOriginalDate(args, isConstructorCall);
11503
11503
  this.isInPatchedCall = true;
11504
11504
  try {
11505
11505
  return this._handleReplayDate(args, isConstructorCall);
@@ -11619,10 +11619,10 @@ var GraphqlInstrumentation = class extends TdInstrumentationBase {
11619
11619
  /**
11620
11620
  * Handle GraphQL execution - add metadata to parent server span if present
11621
11621
  */
11622
- _handleGraphQLExecution(methodName, originalMethod, args, context$4) {
11622
+ _handleGraphQLExecution(methodName, originalMethod, args, context$6) {
11623
11623
  if (this.tuskDrift.getMode() !== TuskDriftMode.RECORD) {
11624
11624
  logger.debug(`[GraphQLInstrumentation] Not in RECORD mode, skipping instrumentation`);
11625
- return originalMethod.apply(context$4, args);
11625
+ return originalMethod.apply(context$6, args);
11626
11626
  }
11627
11627
  let currentSpanInfo = null;
11628
11628
  try {
@@ -11632,7 +11632,7 @@ var GraphqlInstrumentation = class extends TdInstrumentationBase {
11632
11632
  }
11633
11633
  if (!currentSpanInfo) {
11634
11634
  logger.debug(`[GraphQLInstrumentation] No current span found for ${methodName}, calling original`);
11635
- return originalMethod.apply(context$4, args);
11635
+ return originalMethod.apply(context$6, args);
11636
11636
  }
11637
11637
  try {
11638
11638
  logger.debug(`[GraphQLInstrumentation] Update span attributes with GraphQL info`);
@@ -11640,7 +11640,7 @@ var GraphqlInstrumentation = class extends TdInstrumentationBase {
11640
11640
  } catch (error) {
11641
11641
  logger.warn(`[GraphQLInstrumentation] Failed to update span attributes with GraphQL info:`, error);
11642
11642
  }
11643
- return originalMethod.apply(context$4, args);
11643
+ return originalMethod.apply(context$6, args);
11644
11644
  }
11645
11645
  /**
11646
11646
  * Extract GraphQL metadata from execution args and add to span
@@ -11745,7 +11745,7 @@ var TdPgClientMock = class extends EventEmitter {
11745
11745
 
11746
11746
  //#endregion
11747
11747
  //#region src/instrumentation/libraries/pg/Instrumentation.ts
11748
- var import_src$24 = /* @__PURE__ */ __toESM(require_src$7(), 1);
11748
+ var import_src$26 = /* @__PURE__ */ __toESM(require_src$7(), 1);
11749
11749
  var PgInstrumentation = class extends TdInstrumentationBase {
11750
11750
  constructor(config = {}) {
11751
11751
  super("pg", config);
@@ -11799,6 +11799,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11799
11799
  const inputValue = {
11800
11800
  text: queryConfig.text,
11801
11801
  values: queryConfig.values || [],
11802
+ rowMode: queryConfig.rowMode,
11802
11803
  clientType
11803
11804
  };
11804
11805
  if (self.mode === TuskDriftMode.REPLAY) {
@@ -11813,7 +11814,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11813
11814
  const spanName = inputValue.clientType === "pool" ? "pg-pool.query" : "pg.query";
11814
11815
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(this, args), {
11815
11816
  name: spanName,
11816
- kind: import_src$24.SpanKind.CLIENT,
11817
+ kind: import_src$26.SpanKind.CLIENT,
11817
11818
  submodule: "query",
11818
11819
  packageType: PackageType.PG,
11819
11820
  packageName,
@@ -11832,7 +11833,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11832
11833
  const spanName = inputValue.clientType === "pool" ? "pg-pool.query" : "pg.query";
11833
11834
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(this, args), {
11834
11835
  name: spanName,
11835
- kind: import_src$24.SpanKind.CLIENT,
11836
+ kind: import_src$26.SpanKind.CLIENT,
11836
11837
  submodule: "query",
11837
11838
  packageType: PackageType.PG,
11838
11839
  instrumentationName: self.INSTRUMENTATION_NAME,
@@ -11843,7 +11844,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11843
11844
  return self._handleRecordQueryInSpan(spanInfo, originalQuery, queryConfig, args, this);
11844
11845
  });
11845
11846
  },
11846
- spanKind: import_src$24.SpanKind.CLIENT
11847
+ spanKind: import_src$26.SpanKind.CLIENT
11847
11848
  });
11848
11849
  else return originalQuery.apply(this, args);
11849
11850
  };
@@ -11865,7 +11866,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11865
11866
  replayModeHandler: () => {
11866
11867
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
11867
11868
  name: `pg.connect`,
11868
- kind: import_src$24.SpanKind.CLIENT,
11869
+ kind: import_src$26.SpanKind.CLIENT,
11869
11870
  submodule: "connect",
11870
11871
  packageName: "pg",
11871
11872
  packageType: PackageType.PG,
@@ -11882,7 +11883,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11882
11883
  recordModeHandler: ({ isPreAppStart }) => {
11883
11884
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
11884
11885
  name: `pg.connect`,
11885
- kind: import_src$24.SpanKind.CLIENT,
11886
+ kind: import_src$26.SpanKind.CLIENT,
11886
11887
  submodule: "connect",
11887
11888
  packageName: "pg",
11888
11889
  packageType: PackageType.PG,
@@ -11893,7 +11894,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11893
11894
  return self._handleRecordConnectInSpan(spanInfo, originalConnect, callback, this);
11894
11895
  });
11895
11896
  },
11896
- spanKind: import_src$24.SpanKind.CLIENT
11897
+ spanKind: import_src$26.SpanKind.CLIENT
11897
11898
  });
11898
11899
  else return originalConnect.apply(this, [callback]);
11899
11900
  };
@@ -11913,11 +11914,12 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11913
11914
  if (typeof firstArg === "object" && firstArg.text) return {
11914
11915
  text: firstArg.text,
11915
11916
  values: firstArg.values,
11917
+ rowMode: firstArg.rowMode,
11916
11918
  callback: firstArg.callback || (typeof args[1] === "function" ? args[1] : void 0)
11917
11919
  };
11918
11920
  return null;
11919
11921
  }
11920
- _handleRecordQueryInSpan(spanInfo, originalQuery, queryConfig, args, context$4) {
11922
+ _handleRecordQueryInSpan(spanInfo, originalQuery, queryConfig, args, context$6) {
11921
11923
  if (!!queryConfig.callback) {
11922
11924
  const originalCallback = queryConfig.callback;
11923
11925
  const wrappedCallback = (error, result) => {
@@ -11925,7 +11927,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11925
11927
  logger.debug(`[PgInstrumentation] PG query error (hasCallback): ${error.message} (${SpanUtils.getTraceInfo()})`);
11926
11928
  try {
11927
11929
  SpanUtils.endSpan(spanInfo.span, {
11928
- code: import_src$24.SpanStatusCode.ERROR,
11930
+ code: import_src$26.SpanStatusCode.ERROR,
11929
11931
  message: error.message
11930
11932
  });
11931
11933
  } catch (error$1) {
@@ -11935,7 +11937,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11935
11937
  logger.debug(`[PgInstrumentation] PG query completed successfully (hasCallback) (${SpanUtils.getTraceInfo()})`);
11936
11938
  try {
11937
11939
  this._addOutputAttributesToSpan(spanInfo, result);
11938
- SpanUtils.endSpan(spanInfo.span, { code: import_src$24.SpanStatusCode.OK });
11940
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$26.SpanStatusCode.OK });
11939
11941
  } catch (error$1) {
11940
11942
  logger.error(`[PgInstrumentation] error processing response:`, error$1);
11941
11943
  }
@@ -11957,12 +11959,12 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11957
11959
  } catch (error) {
11958
11960
  logger.error(`[PgInstrumentation] error replacing callback:`, error, args);
11959
11961
  }
11960
- return originalQuery.apply(context$4, args);
11961
- } else return originalQuery.apply(context$4, args).then((result) => {
11962
+ return originalQuery.apply(context$6, args);
11963
+ } else return originalQuery.apply(context$6, args).then((result) => {
11962
11964
  logger.debug(`[PgInstrumentation] PG query completed successfully (${SpanUtils.getTraceInfo()})`);
11963
11965
  try {
11964
11966
  this._addOutputAttributesToSpan(spanInfo, result);
11965
- SpanUtils.endSpan(spanInfo.span, { code: import_src$24.SpanStatusCode.OK });
11967
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$26.SpanStatusCode.OK });
11966
11968
  } catch (error) {
11967
11969
  logger.error(`[PgInstrumentation] error processing response:`, error);
11968
11970
  }
@@ -11971,7 +11973,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11971
11973
  logger.debug(`[PgInstrumentation] PG query error: ${error.message} (${SpanUtils.getTraceInfo()})`);
11972
11974
  try {
11973
11975
  SpanUtils.endSpan(spanInfo.span, {
11974
- code: import_src$24.SpanStatusCode.ERROR,
11976
+ code: import_src$26.SpanStatusCode.ERROR,
11975
11977
  message: error.message
11976
11978
  });
11977
11979
  } catch (error$1) {
@@ -12003,7 +12005,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12003
12005
  packageName,
12004
12006
  instrumentationName: this.INSTRUMENTATION_NAME,
12005
12007
  submoduleName: "query",
12006
- kind: import_src$24.SpanKind.CLIENT,
12008
+ kind: import_src$26.SpanKind.CLIENT,
12007
12009
  stackTrace
12008
12010
  },
12009
12011
  tuskDrift: this.tuskDrift
@@ -12013,7 +12015,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12013
12015
  logger.warn(`[PgInstrumentation] No mock data found for PG query: ${queryText}`);
12014
12016
  throw new Error(`[PgInstrumentation] No mock data found for PG query: ${queryText}`);
12015
12017
  }
12016
- const processedResult = this.convertPostgresTypes(mockData.result);
12018
+ const processedResult = this.convertPostgresTypes(mockData.result, inputValue.rowMode);
12017
12019
  if (queryConfig.callback) {
12018
12020
  process.nextTick(() => {
12019
12021
  queryConfig.callback(null, processedResult);
@@ -12022,35 +12024,56 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12022
12024
  } else return Promise.resolve(processedResult);
12023
12025
  }
12024
12026
  /**
12027
+ * Convert a single value based on its PostgreSQL data type.
12028
+ *
12029
+ * Reference for data type IDs: https://jdbc.postgresql.org/documentation/publicapi/constant-values.html
12030
+ */
12031
+ convertPostgresValue(value, dataTypeID) {
12032
+ if (value === null || value === void 0) return value;
12033
+ switch (dataTypeID) {
12034
+ case 1184:
12035
+ case 1114:
12036
+ case 1082:
12037
+ if (typeof value === "string") return new Date(value);
12038
+ break;
12039
+ case 1083:
12040
+ case 1266: break;
12041
+ default: break;
12042
+ }
12043
+ return value;
12044
+ }
12045
+ /**
12025
12046
  * Convert PostgreSQL string values back to appropriate JavaScript types
12026
12047
  * based on field metadata from the recorded response.
12027
12048
  *
12028
12049
  * Reference for data type IDs: https://jdbc.postgresql.org/documentation/publicapi/constant-values.html
12029
12050
  */
12030
- convertPostgresTypes(result) {
12051
+ convertPostgresTypes(result, rowMode) {
12031
12052
  if (!result || !result.fields || !result.rows) return result;
12053
+ if (rowMode === "array") {
12054
+ const convertedRows$1 = result.rows.map((row) => {
12055
+ if (!Array.isArray(row)) return row;
12056
+ return row.map((value, index) => {
12057
+ const field = result.fields[index];
12058
+ if (!field) return value;
12059
+ return this.convertPostgresValue(value, field.dataTypeID);
12060
+ });
12061
+ });
12062
+ return {
12063
+ ...result,
12064
+ rows: convertedRows$1
12065
+ };
12066
+ }
12032
12067
  const fieldTypeMap = {};
12033
12068
  result.fields.forEach((field) => {
12034
12069
  fieldTypeMap[field.name] = field.dataTypeID;
12035
12070
  });
12036
- const convertedRows = result.rows.map((row, rowIndex) => {
12071
+ const convertedRows = result.rows.map((row) => {
12037
12072
  const convertedRow = { ...row };
12038
12073
  Object.keys(row).forEach((fieldName) => {
12039
12074
  const dataTypeID = fieldTypeMap[fieldName];
12040
12075
  const value = row[fieldName];
12041
- if (value === null || value === void 0) return;
12042
- switch (dataTypeID) {
12043
- case 1184:
12044
- case 1114:
12045
- if (typeof value === "string") convertedRow[fieldName] = new Date(value);
12046
- break;
12047
- case 1082:
12048
- if (typeof value === "string") convertedRow[fieldName] = new Date(value);
12049
- break;
12050
- case 1083:
12051
- case 1266: break;
12052
- default: break;
12053
- }
12076
+ convertedRow[fieldName] = this.convertPostgresValue(value, dataTypeID);
12054
12077
  });
12055
12078
  return convertedRow;
12056
12079
  });
@@ -12059,14 +12082,14 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12059
12082
  rows: convertedRows
12060
12083
  };
12061
12084
  }
12062
- _handleRecordConnectInSpan(spanInfo, originalConnect, callback, context$4) {
12085
+ _handleRecordConnectInSpan(spanInfo, originalConnect, callback, context$6) {
12063
12086
  if (callback) {
12064
12087
  const wrappedCallback = (error) => {
12065
12088
  if (error) {
12066
12089
  logger.debug(`[PgInstrumentation] PG connect error: ${error.message} (${SpanUtils.getTraceInfo()})`);
12067
12090
  try {
12068
12091
  SpanUtils.endSpan(spanInfo.span, {
12069
- code: import_src$24.SpanStatusCode.ERROR,
12092
+ code: import_src$26.SpanStatusCode.ERROR,
12070
12093
  message: error.message
12071
12094
  });
12072
12095
  } catch (error$1) {
@@ -12076,19 +12099,19 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12076
12099
  logger.debug(`[PgInstrumentation] PG connect completed successfully (${SpanUtils.getTraceInfo()})`);
12077
12100
  try {
12078
12101
  SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: { connected: true } });
12079
- SpanUtils.endSpan(spanInfo.span, { code: import_src$24.SpanStatusCode.OK });
12102
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$26.SpanStatusCode.OK });
12080
12103
  } catch (error$1) {
12081
12104
  logger.error(`[PgInstrumentation] error processing connect response:`, error$1);
12082
12105
  }
12083
12106
  }
12084
12107
  return callback(error);
12085
12108
  };
12086
- return originalConnect.call(context$4, wrappedCallback);
12087
- } else return originalConnect.call(context$4).then((result) => {
12109
+ return originalConnect.call(context$6, wrappedCallback);
12110
+ } else return originalConnect.call(context$6).then((result) => {
12088
12111
  logger.debug(`[PgInstrumentation] PG connect completed successfully (${SpanUtils.getTraceInfo()})`);
12089
12112
  try {
12090
12113
  SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: { connected: true } });
12091
- SpanUtils.endSpan(spanInfo.span, { code: import_src$24.SpanStatusCode.OK });
12114
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$26.SpanStatusCode.OK });
12092
12115
  } catch (error) {
12093
12116
  logger.error(`[PgInstrumentation] error processing connect response:`, error);
12094
12117
  }
@@ -12097,7 +12120,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12097
12120
  logger.debug(`[PgInstrumentation] PG connect error: ${error.message} (${SpanUtils.getTraceInfo()})`);
12098
12121
  try {
12099
12122
  SpanUtils.endSpan(spanInfo.span, {
12100
- code: import_src$24.SpanStatusCode.ERROR,
12123
+ code: import_src$26.SpanStatusCode.ERROR,
12101
12124
  message: error.message
12102
12125
  });
12103
12126
  } catch (error$1) {
@@ -12158,7 +12181,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12158
12181
  replayModeHandler: () => {
12159
12182
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
12160
12183
  name: `pg-pool.connect`,
12161
- kind: import_src$24.SpanKind.CLIENT,
12184
+ kind: import_src$26.SpanKind.CLIENT,
12162
12185
  submodule: "connect",
12163
12186
  packageName: "pg-pool",
12164
12187
  packageType: PackageType.PG,
@@ -12175,7 +12198,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12175
12198
  recordModeHandler: ({ isPreAppStart }) => {
12176
12199
  return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
12177
12200
  name: `pg-pool.connect`,
12178
- kind: import_src$24.SpanKind.CLIENT,
12201
+ kind: import_src$26.SpanKind.CLIENT,
12179
12202
  submodule: "connect",
12180
12203
  packageName: "pg-pool",
12181
12204
  packageType: PackageType.PG,
@@ -12186,20 +12209,20 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12186
12209
  return self._handleRecordPoolConnectInSpan(spanInfo, originalConnect, callback, this);
12187
12210
  });
12188
12211
  },
12189
- spanKind: import_src$24.SpanKind.CLIENT
12212
+ spanKind: import_src$26.SpanKind.CLIENT
12190
12213
  });
12191
12214
  else return originalConnect.apply(this, [callback]);
12192
12215
  };
12193
12216
  };
12194
12217
  }
12195
- _handleRecordPoolConnectInSpan(spanInfo, originalConnect, callback, context$4) {
12218
+ _handleRecordPoolConnectInSpan(spanInfo, originalConnect, callback, context$6) {
12196
12219
  if (callback) {
12197
12220
  const wrappedCallback = (error, client, done) => {
12198
12221
  if (error) {
12199
12222
  logger.debug(`[PgInstrumentation] PG Pool connect error: ${error.message} (${SpanUtils.getTraceInfo()})`);
12200
12223
  try {
12201
12224
  SpanUtils.endSpan(spanInfo.span, {
12202
- code: import_src$24.SpanStatusCode.ERROR,
12225
+ code: import_src$26.SpanStatusCode.ERROR,
12203
12226
  message: error.message
12204
12227
  });
12205
12228
  } catch (error$1) {
@@ -12212,22 +12235,22 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12212
12235
  connected: true,
12213
12236
  hasClient: !!client
12214
12237
  } });
12215
- SpanUtils.endSpan(spanInfo.span, { code: import_src$24.SpanStatusCode.OK });
12238
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$26.SpanStatusCode.OK });
12216
12239
  } catch (error$1) {
12217
12240
  logger.error(`[PgInstrumentation] error processing pool connect response:`, error$1);
12218
12241
  }
12219
12242
  }
12220
12243
  return callback(error, client, done);
12221
12244
  };
12222
- return originalConnect.call(context$4, wrappedCallback);
12223
- } else return originalConnect.call(context$4).then((client) => {
12245
+ return originalConnect.call(context$6, wrappedCallback);
12246
+ } else return originalConnect.call(context$6).then((client) => {
12224
12247
  logger.debug(`[PgInstrumentation] PG Pool connect completed successfully (${SpanUtils.getTraceInfo()})`);
12225
12248
  try {
12226
12249
  SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: {
12227
12250
  connected: true,
12228
12251
  hasClient: !!client
12229
12252
  } });
12230
- SpanUtils.endSpan(spanInfo.span, { code: import_src$24.SpanStatusCode.OK });
12253
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$26.SpanStatusCode.OK });
12231
12254
  } catch (error) {
12232
12255
  logger.error(`[PgInstrumentation] error processing pool connect response:`, error);
12233
12256
  }
@@ -12236,7 +12259,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12236
12259
  logger.debug(`[PgInstrumentation] PG Pool connect error: ${error.message} (${SpanUtils.getTraceInfo()})`);
12237
12260
  try {
12238
12261
  SpanUtils.endSpan(spanInfo.span, {
12239
- code: import_src$24.SpanStatusCode.ERROR,
12262
+ code: import_src$26.SpanStatusCode.ERROR,
12240
12263
  message: error.message
12241
12264
  });
12242
12265
  } catch (error$1) {
@@ -12261,17 +12284,12 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12261
12284
  //#endregion
12262
12285
  //#region src/instrumentation/libraries/postgres/types.ts
12263
12286
  function isPostgresOutputValueType(value) {
12264
- return value !== null && value !== void 0 && typeof value === "object" && "_tdOriginalFormat" in value && Object.values(PostgresReturnType).includes(value._tdOriginalFormat);
12287
+ return value !== null && value !== void 0 && typeof value === "object";
12265
12288
  }
12266
- let PostgresReturnType = /* @__PURE__ */ function(PostgresReturnType$1) {
12267
- PostgresReturnType$1["ARRAY"] = "array";
12268
- PostgresReturnType$1["OBJECT"] = "object";
12269
- return PostgresReturnType$1;
12270
- }({});
12271
12289
 
12272
12290
  //#endregion
12273
12291
  //#region src/instrumentation/libraries/postgres/Instrumentation.ts
12274
- var import_src$23 = /* @__PURE__ */ __toESM(require_src$7(), 1);
12292
+ var import_src$25 = /* @__PURE__ */ __toESM(require_src$7(), 1);
12275
12293
  var PostgresInstrumentation = class extends TdInstrumentationBase {
12276
12294
  constructor(config = {}) {
12277
12295
  super("postgres", config);
@@ -12335,13 +12353,17 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12335
12353
  };
12336
12354
  if (this.mode === TuskDriftMode.REPLAY) return handleReplayMode({
12337
12355
  noOpRequestHandler: () => {
12338
- try {
12339
- const sqlInstance = originalFunction(...args);
12340
- return this._wrapSqlInstance(sqlInstance);
12341
- } catch (error) {
12342
- logger.debug(`[PostgresInstrumentation] Postgres connection error in replay: ${error.message}`);
12343
- throw error;
12344
- }
12356
+ const mockSql = () => Promise.resolve(Object.assign([], {
12357
+ count: 0,
12358
+ command: null
12359
+ }));
12360
+ mockSql.unsafe = () => Promise.resolve(Object.assign([], {
12361
+ count: 0,
12362
+ command: null
12363
+ }));
12364
+ mockSql.begin = () => Promise.resolve();
12365
+ mockSql.end = () => Promise.resolve();
12366
+ return mockSql;
12345
12367
  },
12346
12368
  isServerRequest: false,
12347
12369
  replayModeHandler: () => {
@@ -12350,7 +12372,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12350
12372
  return this._wrapSqlInstance(sqlInstance);
12351
12373
  }, {
12352
12374
  name: "postgres.connect",
12353
- kind: import_src$23.SpanKind.CLIENT,
12375
+ kind: import_src$25.SpanKind.CLIENT,
12354
12376
  submodule: "connect",
12355
12377
  packageType: PackageType.PG,
12356
12378
  packageName: "postgres",
@@ -12373,7 +12395,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12373
12395
  return this._wrapSqlInstance(sqlInstance);
12374
12396
  }, {
12375
12397
  name: "postgres.connect",
12376
- kind: import_src$23.SpanKind.CLIENT,
12398
+ kind: import_src$25.SpanKind.CLIENT,
12377
12399
  submodule: "connect",
12378
12400
  packageType: PackageType.PG,
12379
12401
  packageName: "postgres",
@@ -12384,7 +12406,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12384
12406
  return this._handleRecordConnect(spanInfo, originalFunction, args);
12385
12407
  });
12386
12408
  },
12387
- spanKind: import_src$23.SpanKind.CLIENT
12409
+ spanKind: import_src$25.SpanKind.CLIENT
12388
12410
  });
12389
12411
  else return originalFunction(...args);
12390
12412
  }
@@ -12415,7 +12437,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12415
12437
  try {
12416
12438
  logger.debug(`[PostgresInstrumentation] Postgres connection created successfully (${SpanUtils.getTraceInfo()})`);
12417
12439
  SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: { connected: true } });
12418
- SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
12440
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$25.SpanStatusCode.OK });
12419
12441
  } catch (error) {
12420
12442
  logger.error(`[PostgresInstrumentation] error adding span attributes:`, error);
12421
12443
  }
@@ -12476,121 +12498,189 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12476
12498
  };
12477
12499
  }
12478
12500
  _handleSqlQuery(originalSql, strings, values) {
12479
- let query = "";
12480
- for (let i = 0; i < strings.length; i++) {
12481
- query += strings[i];
12482
- if (i < values.length) query += `$${i + 1}`;
12483
- }
12484
- const inputValue = {
12485
- query: query.trim(),
12486
- parameters: values
12487
- };
12488
- if (this.mode === TuskDriftMode.REPLAY) {
12489
- const stackTrace = captureStackTrace(["PostgresInstrumentation"]);
12490
- return handleReplayMode({
12491
- noOpRequestHandler: () => {},
12492
- isServerRequest: false,
12493
- replayModeHandler: () => {
12494
- return SpanUtils.createAndExecuteSpan(this.mode, () => originalSql.call(this, strings, ...values), {
12495
- name: "postgres.query",
12496
- kind: import_src$23.SpanKind.CLIENT,
12497
- submodule: "query",
12498
- packageType: PackageType.PG,
12499
- packageName: "postgres",
12500
- instrumentationName: this.INSTRUMENTATION_NAME,
12501
- inputValue,
12502
- isPreAppStart: false
12503
- }, (spanInfo) => {
12504
- return this.handleReplaySqlQuery({
12505
- inputValue,
12506
- spanInfo,
12507
- submodule: "query",
12501
+ if (!strings || !Array.isArray(strings.raw)) return originalSql.call(this, strings, ...values);
12502
+ const creationContext = import_src$25.context.active();
12503
+ const query = originalSql.call(this, strings, ...values);
12504
+ const originalThen = query.then.bind(query);
12505
+ const self = this;
12506
+ query.then = function(onFulfilled, onRejected) {
12507
+ let queryString = "";
12508
+ for (let i = 0; i < strings.length; i++) {
12509
+ queryString += strings[i];
12510
+ if (i < values.length) queryString += `$${i + 1}`;
12511
+ }
12512
+ const inputValue = {
12513
+ query: queryString.trim(),
12514
+ parameters: values
12515
+ };
12516
+ return import_src$25.context.with(creationContext, () => {
12517
+ if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
12518
+ originalFunctionCall: () => originalThen(onFulfilled, onRejected),
12519
+ recordModeHandler: ({ isPreAppStart }) => {
12520
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalThen(onFulfilled, onRejected), {
12508
12521
  name: "postgres.query",
12509
- stackTrace
12522
+ kind: import_src$25.SpanKind.CLIENT,
12523
+ submodule: "query",
12524
+ packageType: PackageType.PG,
12525
+ instrumentationName: self.INSTRUMENTATION_NAME,
12526
+ packageName: "postgres",
12527
+ inputValue,
12528
+ isPreAppStart
12529
+ }, (spanInfo) => {
12530
+ const wrappedOnFulfilled = (result) => {
12531
+ try {
12532
+ logger.debug(`[PostgresInstrumentation] Postgres query completed successfully`, result);
12533
+ self._addOutputAttributesToSpan(spanInfo, result);
12534
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$25.SpanStatusCode.OK });
12535
+ } catch (error) {
12536
+ logger.error(`[PostgresInstrumentation] error processing query response:`, error);
12537
+ }
12538
+ return onFulfilled ? onFulfilled(result) : result;
12539
+ };
12540
+ const wrappedOnRejected = (error) => {
12541
+ try {
12542
+ logger.debug(`[PostgresInstrumentation] Postgres query error`, error);
12543
+ SpanUtils.endSpan(spanInfo.span, {
12544
+ code: import_src$25.SpanStatusCode.ERROR,
12545
+ message: error.message
12546
+ });
12547
+ } catch (spanError) {
12548
+ logger.error(`[PostgresInstrumentation] error ending span:`, spanError);
12549
+ }
12550
+ if (onRejected) return onRejected(error);
12551
+ throw error;
12552
+ };
12553
+ return originalThen(wrappedOnFulfilled, wrappedOnRejected);
12510
12554
  });
12555
+ },
12556
+ spanKind: import_src$25.SpanKind.CLIENT
12557
+ });
12558
+ else if (self.mode === TuskDriftMode.REPLAY) {
12559
+ const stackTrace = captureStackTrace(["PostgresInstrumentation"]);
12560
+ return handleReplayMode({
12561
+ noOpRequestHandler: () => Promise.resolve(Object.assign([], {
12562
+ count: 0,
12563
+ command: null
12564
+ })),
12565
+ isServerRequest: false,
12566
+ replayModeHandler: () => {
12567
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalThen(onFulfilled, onRejected), {
12568
+ name: "postgres.query",
12569
+ kind: import_src$25.SpanKind.CLIENT,
12570
+ submodule: "query",
12571
+ packageType: PackageType.PG,
12572
+ packageName: "postgres",
12573
+ instrumentationName: self.INSTRUMENTATION_NAME,
12574
+ inputValue,
12575
+ isPreAppStart: false
12576
+ }, async (spanInfo) => {
12577
+ const mockedResult = await self.handleReplaySqlQuery({
12578
+ inputValue,
12579
+ spanInfo,
12580
+ submodule: "query",
12581
+ name: "postgres.query",
12582
+ stackTrace
12583
+ });
12584
+ return onFulfilled ? onFulfilled(mockedResult) : mockedResult;
12585
+ });
12586
+ }
12511
12587
  });
12512
- }
12588
+ } else return originalThen(onFulfilled, onRejected);
12513
12589
  });
12514
- } else if (this.mode === TuskDriftMode.RECORD) return handleRecordMode({
12515
- originalFunctionCall: () => originalSql.call(this, strings, ...values),
12516
- recordModeHandler: ({ isPreAppStart }) => {
12517
- return SpanUtils.createAndExecuteSpan(this.mode, () => originalSql.call(this, strings, ...values), {
12518
- name: "postgres.query",
12519
- kind: import_src$23.SpanKind.CLIENT,
12520
- submodule: "query",
12521
- packageType: PackageType.PG,
12522
- instrumentationName: this.INSTRUMENTATION_NAME,
12523
- packageName: "postgres",
12524
- inputValue,
12525
- isPreAppStart
12526
- }, (spanInfo) => {
12527
- return this._handleRecordQueryInSpan(spanInfo, originalSql, strings, values);
12528
- });
12529
- },
12530
- spanKind: import_src$23.SpanKind.CLIENT
12531
- });
12532
- else return originalSql.call(this, strings, ...values);
12590
+ };
12591
+ return query;
12533
12592
  }
12534
12593
  _handleUnsafeQuery(sqlInstance, originalUnsafe, query, parameters, queryOptions) {
12535
- const executeUnsafe = () => {
12594
+ const unsafeQuery = (() => {
12536
12595
  if (queryOptions !== void 0) return originalUnsafe.call(sqlInstance, query, parameters, queryOptions);
12537
12596
  else if (parameters !== void 0) return originalUnsafe.call(sqlInstance, query, parameters);
12538
12597
  else return originalUnsafe.call(sqlInstance, query);
12539
- };
12598
+ })();
12599
+ const creationContext = import_src$25.context.active();
12600
+ const originalThen = unsafeQuery.then.bind(unsafeQuery);
12601
+ const self = this;
12540
12602
  const inputValue = {
12541
12603
  query: query.trim(),
12542
12604
  parameters: parameters || [],
12543
12605
  options: queryOptions
12544
12606
  };
12545
- if (this.mode === TuskDriftMode.REPLAY) {
12546
- const stackTrace = captureStackTrace(["PostgresInstrumentation"]);
12547
- return handleReplayMode({
12548
- noOpRequestHandler: () => {
12549
- return Promise.resolve(void 0);
12550
- },
12551
- isServerRequest: false,
12552
- replayModeHandler: () => {
12553
- return this._createPendingQueryWrapper(() => {
12554
- return SpanUtils.createAndExecuteSpan(this.mode, () => executeUnsafe(), {
12607
+ unsafeQuery.then = function(onFulfilled, onRejected) {
12608
+ return import_src$25.context.with(creationContext, () => {
12609
+ if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
12610
+ originalFunctionCall: () => originalThen(onFulfilled, onRejected),
12611
+ recordModeHandler: ({ isPreAppStart }) => {
12612
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalThen(onFulfilled, onRejected), {
12555
12613
  name: "postgres.unsafe",
12556
- kind: import_src$23.SpanKind.CLIENT,
12614
+ kind: import_src$25.SpanKind.CLIENT,
12557
12615
  submodule: "unsafe",
12558
12616
  packageType: PackageType.PG,
12559
12617
  packageName: "postgres",
12560
- instrumentationName: this.INSTRUMENTATION_NAME,
12618
+ instrumentationName: self.INSTRUMENTATION_NAME,
12561
12619
  inputValue,
12562
- isPreAppStart: false
12620
+ isPreAppStart
12563
12621
  }, (spanInfo) => {
12564
- return this.handleReplayUnsafeQuery({
12565
- inputValue,
12566
- spanInfo,
12567
- submodule: "unsafe",
12622
+ const wrappedOnFulfilled = (result) => {
12623
+ try {
12624
+ logger.debug(`[PostgresInstrumentation] Postgres unsafe query completed successfully (${SpanUtils.getTraceInfo()})`);
12625
+ self._addOutputAttributesToSpan(spanInfo, result);
12626
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$25.SpanStatusCode.OK });
12627
+ } catch (error) {
12628
+ logger.error(`[PostgresInstrumentation] error processing unsafe query response:`, error);
12629
+ }
12630
+ return onFulfilled ? onFulfilled(result) : result;
12631
+ };
12632
+ const wrappedOnRejected = (error) => {
12633
+ try {
12634
+ logger.debug(`[PostgresInstrumentation] Postgres unsafe query error: ${error.message}`);
12635
+ SpanUtils.endSpan(spanInfo.span, {
12636
+ code: import_src$25.SpanStatusCode.ERROR,
12637
+ message: error.message
12638
+ });
12639
+ } catch (spanError) {
12640
+ logger.error(`[PostgresInstrumentation] error ending span:`, spanError);
12641
+ }
12642
+ if (onRejected) return onRejected(error);
12643
+ throw error;
12644
+ };
12645
+ return originalThen(wrappedOnFulfilled, wrappedOnRejected);
12646
+ });
12647
+ },
12648
+ spanKind: import_src$25.SpanKind.CLIENT
12649
+ });
12650
+ else if (self.mode === TuskDriftMode.REPLAY) {
12651
+ const stackTrace = captureStackTrace(["PostgresInstrumentation"]);
12652
+ return handleReplayMode({
12653
+ noOpRequestHandler: () => Promise.resolve(Object.assign([], {
12654
+ count: 0,
12655
+ command: null
12656
+ })),
12657
+ isServerRequest: false,
12658
+ replayModeHandler: () => {
12659
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalThen(onFulfilled, onRejected), {
12568
12660
  name: "postgres.unsafe",
12569
- stackTrace
12661
+ kind: import_src$25.SpanKind.CLIENT,
12662
+ submodule: "unsafe",
12663
+ packageType: PackageType.PG,
12664
+ packageName: "postgres",
12665
+ instrumentationName: self.INSTRUMENTATION_NAME,
12666
+ inputValue,
12667
+ isPreAppStart: false
12668
+ }, async (spanInfo) => {
12669
+ const mockedResult = await self.handleReplayUnsafeQuery({
12670
+ inputValue,
12671
+ spanInfo,
12672
+ submodule: "unsafe",
12673
+ name: "postgres.unsafe",
12674
+ stackTrace
12675
+ });
12676
+ return onFulfilled ? onFulfilled(mockedResult) : mockedResult;
12570
12677
  });
12571
- });
12678
+ }
12572
12679
  });
12573
- }
12680
+ } else return originalThen(onFulfilled, onRejected);
12574
12681
  });
12575
- } else if (this.mode === TuskDriftMode.RECORD) return handleRecordMode({
12576
- originalFunctionCall: executeUnsafe,
12577
- recordModeHandler: ({ isPreAppStart }) => {
12578
- return SpanUtils.createAndExecuteSpan(this.mode, executeUnsafe, {
12579
- name: "postgres.unsafe",
12580
- kind: import_src$23.SpanKind.CLIENT,
12581
- submodule: "unsafe",
12582
- packageType: PackageType.PG,
12583
- packageName: "postgres",
12584
- instrumentationName: this.INSTRUMENTATION_NAME,
12585
- inputValue,
12586
- isPreAppStart
12587
- }, (spanInfo) => {
12588
- return this._executeThenAddOutputAttributes(spanInfo, executeUnsafe);
12589
- });
12590
- },
12591
- spanKind: import_src$23.SpanKind.CLIENT
12592
- });
12593
- else return executeUnsafe();
12682
+ };
12683
+ return unsafeQuery;
12594
12684
  }
12595
12685
  _handleBeginTransaction(sqlInstance, originalBegin, options, transactionCallback) {
12596
12686
  const inputValue = {
@@ -12605,12 +12695,12 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12605
12695
  if (this.mode === TuskDriftMode.REPLAY) {
12606
12696
  const stackTrace = captureStackTrace(["PostgresInstrumentation"]);
12607
12697
  return handleReplayMode({
12608
- noOpRequestHandler: () => {},
12698
+ noOpRequestHandler: () => Promise.resolve(),
12609
12699
  isServerRequest: false,
12610
12700
  replayModeHandler: () => {
12611
12701
  return SpanUtils.createAndExecuteSpan(this.mode, () => executeBegin(), {
12612
12702
  name: "postgres.begin",
12613
- kind: import_src$23.SpanKind.CLIENT,
12703
+ kind: import_src$25.SpanKind.CLIENT,
12614
12704
  submodule: "transaction",
12615
12705
  packageType: PackageType.PG,
12616
12706
  packageName: "postgres",
@@ -12627,7 +12717,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12627
12717
  recordModeHandler: ({ isPreAppStart }) => {
12628
12718
  return SpanUtils.createAndExecuteSpan(this.mode, executeBegin, {
12629
12719
  name: "postgres.begin",
12630
- kind: import_src$23.SpanKind.CLIENT,
12720
+ kind: import_src$25.SpanKind.CLIENT,
12631
12721
  submodule: "transaction",
12632
12722
  packageType: PackageType.PG,
12633
12723
  packageName: "postgres",
@@ -12638,52 +12728,10 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12638
12728
  return this._handleRecordBeginTransaction(spanInfo, executeBegin);
12639
12729
  });
12640
12730
  },
12641
- spanKind: import_src$23.SpanKind.CLIENT
12731
+ spanKind: import_src$25.SpanKind.CLIENT
12642
12732
  });
12643
12733
  else return executeBegin();
12644
12734
  }
12645
- /**
12646
- * Execute postgres.js unsafe query and create span afterwards.
12647
- *
12648
- * postgres.js has sophisticated internal session and connection management
12649
- * that is extremely sensitive to async context changes. Unlike the regular 'pg' library,
12650
- * postgres.js maintains internal state using promise identity and async context tracking.
12651
- *
12652
- * The issue: promise chain modification breaks postgres.js.
12653
- * Calling .then()/.catch() creates new promise objects, breaking postgres.js's internal tracking
12654
- *
12655
- * Solution: We must execute the postgres.js query in its completely unmodified context:
12656
- * - Return the original promise object unchanged
12657
- * - Use promise.finally() to track completion without creating a new promise chain
12658
- *
12659
- * This preserves postgres.js's internal session management while still providing tracing.
12660
- * The 'pg' library doesn't have this issue because it has simpler internal state management.
12661
- */
12662
- _executeThenAddOutputAttributes(spanInfo, executeUnsafe) {
12663
- const promise = executeUnsafe();
12664
- promise.finally(() => {
12665
- promise.then((result) => {
12666
- logger.debug(`[PostgresInstrumentation] Postgres unsafe query completed successfully`);
12667
- try {
12668
- this._addOutputAttributesToSpan(spanInfo, result);
12669
- SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
12670
- } catch (error) {
12671
- logger.error(`[PostgresInstrumentation] error processing unsafe query response:`, error);
12672
- }
12673
- }).catch((error) => {
12674
- logger.debug(`[PostgresInstrumentation] Postgres unsafe query error: ${error.message}`);
12675
- try {
12676
- SpanUtils.endSpan(spanInfo.span, {
12677
- code: import_src$23.SpanStatusCode.ERROR,
12678
- message: error.message
12679
- });
12680
- } catch (error$1) {
12681
- logger.error(`[PostgresInstrumentation] error ending span:`, error$1);
12682
- }
12683
- });
12684
- });
12685
- return promise;
12686
- }
12687
12735
  _handleRecordBeginTransaction(spanInfo, executeBegin) {
12688
12736
  const promise = executeBegin();
12689
12737
  promise.finally(() => {
@@ -12694,7 +12742,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12694
12742
  status: "committed",
12695
12743
  result
12696
12744
  } });
12697
- SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
12745
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$25.SpanStatusCode.OK });
12698
12746
  } catch (error) {
12699
12747
  logger.error(`[PostgresInstrumentation] error processing transaction response:`, error);
12700
12748
  }
@@ -12706,7 +12754,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12706
12754
  error: error.message
12707
12755
  } });
12708
12756
  SpanUtils.endSpan(spanInfo.span, {
12709
- code: import_src$23.SpanStatusCode.ERROR,
12757
+ code: import_src$25.SpanStatusCode.ERROR,
12710
12758
  message: error.message
12711
12759
  });
12712
12760
  } catch (spanError) {
@@ -12716,187 +12764,1712 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
12716
12764
  });
12717
12765
  return promise;
12718
12766
  }
12719
- async _handleReplayBeginTransaction(spanInfo, options, stackTrace) {
12720
- logger.debug(`[PostgresInstrumentation] Replaying Postgres transaction`);
12721
- const mockData = await findMockResponseAsync({
12722
- mockRequestData: {
12723
- traceId: spanInfo.traceId,
12724
- spanId: spanInfo.spanId,
12725
- name: "postgres.begin",
12726
- inputValue: {
12727
- query: "BEGIN",
12728
- options: options ? { transactionOptions: options } : void 0
12729
- },
12730
- packageName: "postgres",
12731
- instrumentationName: this.INSTRUMENTATION_NAME,
12732
- submoduleName: "transaction",
12733
- kind: import_src$23.SpanKind.CLIENT,
12734
- stackTrace
12735
- },
12736
- tuskDrift: this.tuskDrift
12737
- });
12738
- if (!mockData) {
12739
- logger.warn(`[PostgresInstrumentation] No mock data found for transaction BEGIN`);
12740
- throw new Error(`[PostgresInstrumentation] No matching mock found for transaction BEGIN`);
12741
- }
12742
- logger.debug(`[PostgresInstrumentation] Found mock data for transaction: ${JSON.stringify(mockData)}`);
12743
- const transactionResult = mockData.result;
12744
- if (transactionResult && typeof transactionResult === "object" && "status" in transactionResult && transactionResult.status === "committed") return transactionResult.result;
12745
- else {
12746
- const errorMessage = transactionResult && typeof transactionResult === "object" && "error" in transactionResult && transactionResult.error ? transactionResult.error : "Transaction rolled back";
12747
- throw new Error(errorMessage);
12748
- }
12767
+ async _handleReplayBeginTransaction(spanInfo, options, stackTrace) {
12768
+ logger.debug(`[PostgresInstrumentation] Replaying Postgres transaction`);
12769
+ const mockData = await findMockResponseAsync({
12770
+ mockRequestData: {
12771
+ traceId: spanInfo.traceId,
12772
+ spanId: spanInfo.spanId,
12773
+ name: "postgres.begin",
12774
+ inputValue: createMockInputValue({
12775
+ query: "BEGIN",
12776
+ options: options ? { transactionOptions: options } : void 0
12777
+ }),
12778
+ packageName: "postgres",
12779
+ instrumentationName: this.INSTRUMENTATION_NAME,
12780
+ submoduleName: "transaction",
12781
+ kind: import_src$25.SpanKind.CLIENT,
12782
+ stackTrace
12783
+ },
12784
+ tuskDrift: this.tuskDrift
12785
+ });
12786
+ if (!mockData) {
12787
+ logger.warn(`[PostgresInstrumentation] No mock data found for transaction BEGIN`);
12788
+ throw new Error(`[PostgresInstrumentation] No matching mock found for transaction BEGIN`);
12789
+ }
12790
+ logger.debug(`[PostgresInstrumentation] Found mock data for transaction: ${JSON.stringify(mockData)}`);
12791
+ const transactionResult = mockData.result;
12792
+ if (transactionResult && typeof transactionResult === "object" && "status" in transactionResult && transactionResult.status === "committed") return transactionResult.result;
12793
+ else {
12794
+ const errorMessage = transactionResult && typeof transactionResult === "object" && "error" in transactionResult && transactionResult.error ? transactionResult.error : "Transaction rolled back";
12795
+ throw new Error(errorMessage);
12796
+ }
12797
+ }
12798
+ async handleReplaySqlQuery({ inputValue, spanInfo, submodule, name, stackTrace }) {
12799
+ logger.debug(`[PostgresInstrumentation] Replaying Postgres sql query`);
12800
+ const mockData = await findMockResponseAsync({
12801
+ mockRequestData: {
12802
+ traceId: spanInfo.traceId,
12803
+ spanId: spanInfo.spanId,
12804
+ name,
12805
+ inputValue: createMockInputValue(inputValue),
12806
+ packageName: "postgres",
12807
+ instrumentationName: this.INSTRUMENTATION_NAME,
12808
+ submoduleName: submodule,
12809
+ kind: import_src$25.SpanKind.CLIENT,
12810
+ stackTrace
12811
+ },
12812
+ tuskDrift: this.tuskDrift
12813
+ });
12814
+ if (!mockData) {
12815
+ const queryText = inputValue.query || "UNKNOWN_QUERY";
12816
+ logger.warn(`[PostgresInstrumentation] No mock data found for Postgres sql query: ${queryText}`);
12817
+ throw new Error(`[PostgresInstrumentation] No matching mock found for Postgres sql query: ${queryText}`);
12818
+ }
12819
+ logger.debug(`[PostgresInstrumentation] Found mock data for Postgres sql query: ${JSON.stringify(mockData)}`);
12820
+ const processedResult = this.convertPostgresTypes(mockData.result);
12821
+ logger.debug(`[PostgresInstrumentation] Sql query processed result: ${JSON.stringify(processedResult)}`);
12822
+ return processedResult;
12823
+ }
12824
+ async handleReplayUnsafeQuery({ inputValue, spanInfo, submodule, name, stackTrace }) {
12825
+ logger.debug(`[PostgresInstrumentation] Replaying Postgres unsafe query`);
12826
+ const mockData = await findMockResponseAsync({
12827
+ mockRequestData: {
12828
+ traceId: spanInfo.traceId,
12829
+ spanId: spanInfo.spanId,
12830
+ name,
12831
+ inputValue: createMockInputValue(inputValue),
12832
+ packageName: "postgres",
12833
+ instrumentationName: this.INSTRUMENTATION_NAME,
12834
+ submoduleName: submodule,
12835
+ kind: import_src$25.SpanKind.CLIENT,
12836
+ stackTrace
12837
+ },
12838
+ tuskDrift: this.tuskDrift
12839
+ });
12840
+ if (!mockData) {
12841
+ const queryText = inputValue.query || "UNKNOWN_QUERY";
12842
+ logger.warn(`[PostgresInstrumentation] No mock data found for Postgres unsafe query: ${queryText}`);
12843
+ throw new Error(`[PostgresInstrumentation] No matching mock found for Postgres unsafe query: ${queryText}`);
12844
+ }
12845
+ logger.debug(`[PostgresInstrumentation] Found mock data for Postgres unsafe query: ${JSON.stringify(mockData)}`);
12846
+ const processedResult = this.convertPostgresTypes(mockData.result);
12847
+ logger.debug(`[PostgresInstrumentation] Unsafe query processed result: ${JSON.stringify(processedResult)}`);
12848
+ return processedResult;
12849
+ }
12850
+ convertPostgresTypes(result) {
12851
+ if (!isPostgresOutputValueType(result)) {
12852
+ logger.error(`[PostgresInstrumentation] output value is not of type PostgresOutputValueType`, result);
12853
+ return;
12854
+ }
12855
+ const { rows, count, command } = result;
12856
+ const resultArray = Array.from(rows || []);
12857
+ Object.defineProperties(resultArray, {
12858
+ count: {
12859
+ value: count !== void 0 ? count : null,
12860
+ writable: true,
12861
+ enumerable: false
12862
+ },
12863
+ command: {
12864
+ value: command || null,
12865
+ writable: true,
12866
+ enumerable: false
12867
+ }
12868
+ });
12869
+ return resultArray;
12870
+ }
12871
+ _addOutputAttributesToSpan(spanInfo, result) {
12872
+ if (!result) return;
12873
+ const isArray$1 = Array.isArray(result);
12874
+ logger.debug(`[PostgresInstrumentation] Adding output attributes to span for ${isArray$1 ? "array" : "object"} result`);
12875
+ const outputValue = {
12876
+ rows: isArray$1 ? Array.from(result) : result.rows || [],
12877
+ count: result.count !== void 0 && result.count !== null ? result.count : void 0,
12878
+ command: result.command || void 0
12879
+ };
12880
+ SpanUtils.addSpanAttributes(spanInfo.span, { outputValue });
12881
+ }
12882
+ _wrap(target, propertyName, wrapper) {
12883
+ wrap(target, propertyName, wrapper);
12884
+ }
12885
+ };
12886
+
12887
+ //#endregion
12888
+ //#region src/instrumentation/libraries/mysql/types.ts
12889
+ /**
12890
+ * Helper to check if a result is an OkPacket
12891
+ */
12892
+ function isMysqlOkPacket(result) {
12893
+ return result && typeof result === "object" && "affectedRows" in result && "insertId" in result && "fieldCount" in result;
12894
+ }
12895
+
12896
+ //#endregion
12897
+ //#region src/instrumentation/libraries/mysql/mocks/TdMysqlConnectionMock.ts
12898
+ /**
12899
+ * Mock MySQL connection/pool connection for replay mode
12900
+ * Extends EventEmitter to properly handle all connection methods and events
12901
+ */
12902
+ var TdMysqlConnectionMock = class extends EventEmitter {
12903
+ constructor(mysqlInstrumentation, clientType = "poolConnection", spanInfo) {
12904
+ super();
12905
+ this.threadId = null;
12906
+ this.config = {
12907
+ host: "localhost",
12908
+ port: 3306,
12909
+ database: "mock",
12910
+ user: "mock"
12911
+ };
12912
+ this.mysqlInstrumentation = mysqlInstrumentation;
12913
+ this.spanInfo = spanInfo;
12914
+ this.clientType = clientType;
12915
+ this.threadId = 1;
12916
+ }
12917
+ query(...args) {
12918
+ logger.debug(`[TdMysqlConnectionMock] Mock connection query intercepted in REPLAY mode`);
12919
+ let sql;
12920
+ let values;
12921
+ let callback;
12922
+ let options = {};
12923
+ if (typeof args[0] === "string") {
12924
+ sql = args[0];
12925
+ if (typeof args[1] === "function") callback = args[1];
12926
+ else if (Array.isArray(args[1])) {
12927
+ values = args[1];
12928
+ callback = args[2];
12929
+ }
12930
+ } else if (typeof args[0] === "object") {
12931
+ options = args[0];
12932
+ sql = options.sql;
12933
+ values = options.values;
12934
+ if (typeof args[1] === "function") callback = args[1];
12935
+ else if (Array.isArray(args[1])) {
12936
+ values = args[1];
12937
+ callback = args[2];
12938
+ }
12939
+ } else {
12940
+ logger.debug(`[TdMysqlConnectionMock] Could not parse mock connection query, returning empty result`);
12941
+ const emptyResult = {
12942
+ rows: [],
12943
+ fields: []
12944
+ };
12945
+ if (callback) {
12946
+ process.nextTick(() => callback(null, emptyResult.rows, emptyResult.fields));
12947
+ return;
12948
+ }
12949
+ return new EventEmitter();
12950
+ }
12951
+ const inputValue = {
12952
+ sql,
12953
+ values,
12954
+ options: options.nestTables ? { nestTables: options.nestTables } : void 0
12955
+ };
12956
+ if (this.spanInfo) return this.mysqlInstrumentation.handleReplayQueryFromMock(this.spanInfo, inputValue, callback);
12957
+ else {
12958
+ const emptyResult = {
12959
+ rows: [],
12960
+ fields: []
12961
+ };
12962
+ if (callback) {
12963
+ process.nextTick(() => callback(null, emptyResult.rows, emptyResult.fields));
12964
+ return;
12965
+ }
12966
+ const emitter = new EventEmitter();
12967
+ setImmediate(() => {
12968
+ emitter.emit("fields", [], 0);
12969
+ emitter.emit("end");
12970
+ });
12971
+ return emitter;
12972
+ }
12973
+ }
12974
+ release() {
12975
+ this.emit("end");
12976
+ }
12977
+ destroy() {
12978
+ this.emit("end");
12979
+ }
12980
+ end(callback) {
12981
+ this.emit("end");
12982
+ if (callback) {
12983
+ process.nextTick(() => callback(null));
12984
+ return;
12985
+ }
12986
+ }
12987
+ connect(callback) {
12988
+ if (callback) {
12989
+ process.nextTick(() => callback(null));
12990
+ return;
12991
+ }
12992
+ }
12993
+ ping(callback) {
12994
+ if (callback) {
12995
+ process.nextTick(() => callback(null));
12996
+ return;
12997
+ }
12998
+ }
12999
+ beginTransaction(callback) {
13000
+ if (callback) {
13001
+ process.nextTick(() => callback(null));
13002
+ return;
13003
+ }
13004
+ }
13005
+ commit(callback) {
13006
+ if (callback) {
13007
+ process.nextTick(() => callback(null));
13008
+ return;
13009
+ }
13010
+ }
13011
+ rollback(callback) {
13012
+ if (callback) {
13013
+ process.nextTick(() => callback(null));
13014
+ return;
13015
+ }
13016
+ }
13017
+ changeUser(options, callback) {
13018
+ if (callback) {
13019
+ process.nextTick(() => callback(null));
13020
+ return;
13021
+ }
13022
+ }
13023
+ pause() {}
13024
+ resume() {}
13025
+ escape(value) {
13026
+ if (value === null || value === void 0) return "NULL";
13027
+ if (typeof value === "string") return `'${value.replace(/'/g, "''")}'`;
13028
+ if (typeof value === "number") return value.toString();
13029
+ if (typeof value === "boolean") return value ? "1" : "0";
13030
+ if (value instanceof Date) return `'${value.toISOString()}'`;
13031
+ return `'${String(value)}'`;
13032
+ }
13033
+ escapeId(identifier) {
13034
+ return `\`${identifier.replace(/`/g, "``")}\``;
13035
+ }
13036
+ format(sql, values) {
13037
+ if (!values || values.length === 0) return sql;
13038
+ let index = 0;
13039
+ return sql.replace(/\?/g, () => {
13040
+ if (index >= values.length) return "?";
13041
+ return this.escape(values[index++]);
13042
+ });
13043
+ }
13044
+ };
13045
+
13046
+ //#endregion
13047
+ //#region src/instrumentation/libraries/mysql/mocks/TdMysqlQueryMock.ts
13048
+ var import_src$24 = /* @__PURE__ */ __toESM(require_src$7(), 1);
13049
+ /**
13050
+ * Handles replay mode for MySQL query operations
13051
+ * Returns EventEmitters synchronously to support both callback and streaming modes
13052
+ */
13053
+ var TdMysqlQueryMock = class {
13054
+ constructor() {
13055
+ this.INSTRUMENTATION_NAME = "MysqlInstrumentation";
13056
+ this.tuskDrift = TuskDriftCore.getInstance();
13057
+ }
13058
+ /**
13059
+ * Handle replay of a MySQL query
13060
+ * Always returns an EventEmitter (like mysql does)
13061
+ */
13062
+ handleReplayQuery(queryConfig, inputValue, spanInfo, stackTrace) {
13063
+ logger.debug(`[MysqlInstrumentation] Replaying MySQL query`);
13064
+ return this._handleQuery(queryConfig, inputValue, spanInfo, stackTrace);
13065
+ }
13066
+ /**
13067
+ * Handle background query requests (outside of trace context)
13068
+ * Returns an EventEmitter that immediately completes with empty results
13069
+ */
13070
+ handleNoOpReplayQuery(queryConfig) {
13071
+ logger.debug(`[MysqlInstrumentation] Background query detected, returning empty result`);
13072
+ const emitter = new EventEmitter();
13073
+ emitter.then = function(onResolve, onReject) {
13074
+ return new Promise((resolve) => {
13075
+ emitter.once("end", () => {
13076
+ resolve([[], []]);
13077
+ });
13078
+ }).then(onResolve, onReject);
13079
+ };
13080
+ process.nextTick(() => {
13081
+ const callback = queryConfig.callback;
13082
+ if (callback) callback(null, [], []);
13083
+ emitter.emit("fields", [], 0);
13084
+ emitter.emit("end");
13085
+ });
13086
+ return emitter;
13087
+ }
13088
+ /**
13089
+ * Handle query - always returns an EventEmitter (like mysql does)
13090
+ * This handles both callback and streaming modes
13091
+ * The EventEmitter is also thenable (has a .then() method) to support await/Promise usage
13092
+ */
13093
+ _handleQuery(queryConfig, inputValue, spanInfo, stackTrace) {
13094
+ const emitter = new EventEmitter();
13095
+ let storedResults = null;
13096
+ let storedFields = null;
13097
+ emitter.then = function(onResolve, onReject) {
13098
+ return new Promise((resolve, reject) => {
13099
+ emitter.once("end", () => {
13100
+ resolve([storedResults, storedFields]);
13101
+ });
13102
+ emitter.once("error", (error) => {
13103
+ reject(error);
13104
+ });
13105
+ }).then(onResolve, onReject);
13106
+ };
13107
+ (async () => {
13108
+ try {
13109
+ const mockData = await this._fetchMockData(inputValue, spanInfo, stackTrace);
13110
+ if (!mockData) {
13111
+ const sql = inputValue.sql || "UNKNOWN_QUERY";
13112
+ logger.warn(`[MysqlInstrumentation] No mock data found for MySQL query: ${sql}`);
13113
+ throw new Error(`[MysqlInstrumentation] No matching mock found for query: ${sql}`);
13114
+ }
13115
+ const outputValue = mockData.result;
13116
+ const results = outputValue.results;
13117
+ const fields = outputValue.fields;
13118
+ const queryCount = outputValue.queryCount || 1;
13119
+ const isMultiStatement = queryCount > 1;
13120
+ storedResults = results;
13121
+ storedFields = fields;
13122
+ process.nextTick(() => {
13123
+ try {
13124
+ if (isMultiStatement) for (let i = 0; i < queryCount; i++) {
13125
+ const resultSet = Array.isArray(results) ? results[i] : results;
13126
+ const fieldSet = Array.isArray(fields) ? fields[i] : fields;
13127
+ if (fieldSet) emitter.emit("fields", fieldSet, i);
13128
+ if (Array.isArray(resultSet)) resultSet.forEach((row) => {
13129
+ emitter.emit("result", row, i);
13130
+ });
13131
+ else emitter.emit("result", resultSet, i);
13132
+ }
13133
+ else {
13134
+ if (fields) emitter.emit("fields", fields, 0);
13135
+ if (Array.isArray(results)) results.forEach((row) => {
13136
+ emitter.emit("result", row, 0);
13137
+ });
13138
+ else emitter.emit("result", results, 0);
13139
+ }
13140
+ if (queryConfig.callback) queryConfig.callback(null, results, fields);
13141
+ emitter.emit("end");
13142
+ } catch (emitError) {
13143
+ logger.error(`[MysqlInstrumentation] Error emitting events: ${emitError}`);
13144
+ emitter.emit("error", emitError);
13145
+ }
13146
+ });
13147
+ } catch (error) {
13148
+ process.nextTick(() => {
13149
+ if (queryConfig.callback) queryConfig.callback(error);
13150
+ emitter.emit("error", error);
13151
+ });
13152
+ }
13153
+ })();
13154
+ return emitter;
13155
+ }
13156
+ /**
13157
+ * Fetch mock data from CLI
13158
+ */
13159
+ async _fetchMockData(inputValue, spanInfo, stackTrace) {
13160
+ return await findMockResponseAsync({
13161
+ mockRequestData: {
13162
+ traceId: spanInfo.traceId,
13163
+ spanId: spanInfo.spanId,
13164
+ name: "mysql.query",
13165
+ inputValue,
13166
+ packageName: "mysql",
13167
+ instrumentationName: this.INSTRUMENTATION_NAME,
13168
+ submoduleName: "query",
13169
+ kind: import_src$24.SpanKind.CLIENT,
13170
+ stackTrace
13171
+ },
13172
+ tuskDrift: this.tuskDrift
13173
+ });
13174
+ }
13175
+ };
13176
+
13177
+ //#endregion
13178
+ //#region src/instrumentation/libraries/mysql/Instrumentation.ts
13179
+ var import_src$23 = /* @__PURE__ */ __toESM(require_src$7(), 1);
13180
+ var MysqlInstrumentation = class extends TdInstrumentationBase {
13181
+ constructor(config = {}) {
13182
+ super("mysql", config);
13183
+ this.INSTRUMENTATION_NAME = "MysqlInstrumentation";
13184
+ this.createQuery = null;
13185
+ this.mode = config.mode || TuskDriftMode.DISABLED;
13186
+ this.queryMock = new TdMysqlQueryMock();
13187
+ }
13188
+ init() {
13189
+ return [new TdInstrumentationNodeModule({
13190
+ name: "mysql",
13191
+ supportedVersions: ["2.*"],
13192
+ files: [
13193
+ new TdInstrumentationNodeModuleFile({
13194
+ name: "mysql/lib/protocol/sequences/Query.js",
13195
+ supportedVersions: ["2.*"],
13196
+ patch: (moduleExports) => this._patchQueryFile(moduleExports)
13197
+ }),
13198
+ new TdInstrumentationNodeModuleFile({
13199
+ name: "mysql/lib/Connection.js",
13200
+ supportedVersions: ["2.*"],
13201
+ patch: (moduleExports) => this._patchConnectionFile(moduleExports)
13202
+ }),
13203
+ new TdInstrumentationNodeModuleFile({
13204
+ name: "mysql/lib/Pool.js",
13205
+ supportedVersions: ["2.*"],
13206
+ patch: (moduleExports) => this._patchPoolFile(moduleExports)
13207
+ })
13208
+ ]
13209
+ })];
13210
+ }
13211
+ /**
13212
+ * Patch Query.prototype.stream method for streaming query support
13213
+ */
13214
+ _patchQueryFile(QueryClass) {
13215
+ logger.debug(`[MysqlInstrumentation] Patching Query class (file-based)`);
13216
+ if (this.isModulePatched(QueryClass)) {
13217
+ logger.debug(`[MysqlInstrumentation] Query class already patched, skipping`);
13218
+ return QueryClass;
13219
+ }
13220
+ if (QueryClass.prototype && QueryClass.prototype.stream) {
13221
+ if (!isWrapped$1(QueryClass.prototype.stream)) {
13222
+ this._wrap(QueryClass.prototype, "stream", this._getStreamPatchFn());
13223
+ logger.debug(`[MysqlInstrumentation] Wrapped Query.prototype.stream`);
13224
+ }
13225
+ }
13226
+ this.markModuleAsPatched(QueryClass);
13227
+ logger.debug(`[MysqlInstrumentation] Query class patching complete`);
13228
+ return QueryClass;
13229
+ }
13230
+ /**
13231
+ * Patch Connection.prototype methods at the file level
13232
+ * This ensures ALL connection instances have patched methods
13233
+ */
13234
+ _patchConnectionFile(ConnectionClass) {
13235
+ logger.debug(`[MysqlInstrumentation] Patching Connection class (file-based)`);
13236
+ if (this.isModulePatched(ConnectionClass)) {
13237
+ logger.debug(`[MysqlInstrumentation] Connection class already patched, skipping`);
13238
+ return ConnectionClass;
13239
+ }
13240
+ if (ConnectionClass.createQuery) {
13241
+ this.createQuery = ConnectionClass.createQuery;
13242
+ logger.debug(`[MysqlInstrumentation] Stored Connection.createQuery method`);
13243
+ }
13244
+ if (ConnectionClass.prototype && ConnectionClass.prototype.query) {
13245
+ if (!isWrapped$1(ConnectionClass.prototype.query)) {
13246
+ this._wrap(ConnectionClass.prototype, "query", this._getQueryPatchFn());
13247
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.query`);
13248
+ }
13249
+ }
13250
+ if (ConnectionClass.prototype && ConnectionClass.prototype.connect) {
13251
+ if (!isWrapped$1(ConnectionClass.prototype.connect)) {
13252
+ this._wrap(ConnectionClass.prototype, "connect", this._getConnectPatchFn());
13253
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.connect`);
13254
+ }
13255
+ }
13256
+ if (ConnectionClass.prototype && ConnectionClass.prototype.beginTransaction) {
13257
+ if (!isWrapped$1(ConnectionClass.prototype.beginTransaction)) {
13258
+ this._wrap(ConnectionClass.prototype, "beginTransaction", this._getBeginTransactionPatchFn());
13259
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.beginTransaction`);
13260
+ }
13261
+ }
13262
+ if (ConnectionClass.prototype && ConnectionClass.prototype.commit) {
13263
+ if (!isWrapped$1(ConnectionClass.prototype.commit)) {
13264
+ this._wrap(ConnectionClass.prototype, "commit", this._getCommitPatchFn());
13265
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.commit`);
13266
+ }
13267
+ }
13268
+ if (ConnectionClass.prototype && ConnectionClass.prototype.rollback) {
13269
+ if (!isWrapped$1(ConnectionClass.prototype.rollback)) {
13270
+ this._wrap(ConnectionClass.prototype, "rollback", this._getRollbackPatchFn());
13271
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.rollback`);
13272
+ }
13273
+ }
13274
+ if (ConnectionClass.prototype && ConnectionClass.prototype.ping) {
13275
+ if (!isWrapped$1(ConnectionClass.prototype.ping)) {
13276
+ this._wrap(ConnectionClass.prototype, "ping", this._getPingPatchFn());
13277
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.ping`);
13278
+ }
13279
+ }
13280
+ if (ConnectionClass.prototype && ConnectionClass.prototype.end) {
13281
+ if (!isWrapped$1(ConnectionClass.prototype.end)) {
13282
+ this._wrap(ConnectionClass.prototype, "end", this._getEndPatchFn());
13283
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.end`);
13284
+ }
13285
+ }
13286
+ if (ConnectionClass.prototype && ConnectionClass.prototype.changeUser) {
13287
+ if (!isWrapped$1(ConnectionClass.prototype.changeUser)) {
13288
+ this._wrap(ConnectionClass.prototype, "changeUser", this._getChangeUserPatchFn());
13289
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.changeUser`);
13290
+ }
13291
+ }
13292
+ if (ConnectionClass.prototype && ConnectionClass.prototype.pause) {
13293
+ if (!isWrapped$1(ConnectionClass.prototype.pause)) {
13294
+ this._wrap(ConnectionClass.prototype, "pause", this._getPausePatchFn());
13295
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.pause`);
13296
+ }
13297
+ }
13298
+ if (ConnectionClass.prototype && ConnectionClass.prototype.resume) {
13299
+ if (!isWrapped$1(ConnectionClass.prototype.resume)) {
13300
+ this._wrap(ConnectionClass.prototype, "resume", this._getResumePatchFn());
13301
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.resume`);
13302
+ }
13303
+ }
13304
+ if (ConnectionClass.prototype && ConnectionClass.prototype.destroy) {
13305
+ if (!isWrapped$1(ConnectionClass.prototype.destroy)) {
13306
+ this._wrap(ConnectionClass.prototype, "destroy", this._getDestroyPatchFn());
13307
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.destroy`);
13308
+ }
13309
+ }
13310
+ this.markModuleAsPatched(ConnectionClass);
13311
+ logger.debug(`[MysqlInstrumentation] Connection class patching complete`);
13312
+ return ConnectionClass;
13313
+ }
13314
+ /**
13315
+ * Patch Pool.prototype methods at the file level
13316
+ */
13317
+ _patchPoolFile(PoolClass) {
13318
+ logger.debug(`[MysqlInstrumentation] Patching Pool class (file-based)`);
13319
+ if (this.isModulePatched(PoolClass)) {
13320
+ logger.debug(`[MysqlInstrumentation] Pool class already patched, skipping`);
13321
+ return PoolClass;
13322
+ }
13323
+ if (PoolClass.prototype && PoolClass.prototype.query) {
13324
+ if (!isWrapped$1(PoolClass.prototype.query)) {
13325
+ this._wrap(PoolClass.prototype, "query", this._getQueryPatchFn());
13326
+ logger.debug(`[MysqlInstrumentation] Wrapped Pool.prototype.query`);
13327
+ }
13328
+ }
13329
+ if (PoolClass.prototype && PoolClass.prototype.getConnection) {
13330
+ if (!isWrapped$1(PoolClass.prototype.getConnection)) {
13331
+ this._wrap(PoolClass.prototype, "getConnection", this._getPoolGetConnectionPatchFn());
13332
+ logger.debug(`[MysqlInstrumentation] Wrapped Pool.prototype.getConnection`);
13333
+ }
13334
+ }
13335
+ if (PoolClass.prototype && PoolClass.prototype.end) {
13336
+ if (!isWrapped$1(PoolClass.prototype.end)) {
13337
+ this._wrap(PoolClass.prototype, "end", this._getPoolEndPatchFn());
13338
+ logger.debug(`[MysqlInstrumentation] Wrapped Pool.prototype.end`);
13339
+ }
13340
+ }
13341
+ this.markModuleAsPatched(PoolClass);
13342
+ logger.debug(`[MysqlInstrumentation] Pool class patching complete`);
13343
+ return PoolClass;
13344
+ }
13345
+ /**
13346
+ * Get wrapper function for query method (prototype-level patching)
13347
+ */
13348
+ _getQueryPatchFn() {
13349
+ const self = this;
13350
+ return (originalQuery) => {
13351
+ return function query(...args) {
13352
+ let sql;
13353
+ let values;
13354
+ let callback;
13355
+ let options = {};
13356
+ if (self.createQuery) try {
13357
+ const queryObj = self.createQuery(...args);
13358
+ sql = queryObj.sql;
13359
+ values = queryObj.values;
13360
+ options = { nestTables: queryObj.nestTables };
13361
+ callback = args.find((arg) => typeof arg === "function");
13362
+ } catch (error) {
13363
+ logger.debug(`[MysqlInstrumentation] Error using createQuery, falling back to manual parsing:`, error);
13364
+ ({sql, values, callback, options} = self._parseQueryArgs(args));
13365
+ }
13366
+ else ({sql, values, callback, options} = self._parseQueryArgs(args));
13367
+ const inputValue = {
13368
+ sql,
13369
+ values,
13370
+ options: options.nestTables ? { nestTables: options.nestTables } : void 0
13371
+ };
13372
+ const isEventEmitterMode = !callback;
13373
+ if (self.mode === TuskDriftMode.REPLAY) {
13374
+ const stackTrace = captureStackTrace(["MysqlInstrumentation"]);
13375
+ return handleReplayMode({
13376
+ noOpRequestHandler: () => {
13377
+ if (isEventEmitterMode) return self.queryMock.handleNoOpReplayQuery({
13378
+ sql,
13379
+ values,
13380
+ callback,
13381
+ options
13382
+ });
13383
+ },
13384
+ isServerRequest: false,
13385
+ replayModeHandler: () => {
13386
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(this, args), {
13387
+ name: "mysql.query",
13388
+ kind: import_src$23.SpanKind.CLIENT,
13389
+ submodule: "query",
13390
+ packageType: PackageType.MYSQL,
13391
+ packageName: "mysql",
13392
+ instrumentationName: self.INSTRUMENTATION_NAME,
13393
+ inputValue,
13394
+ isPreAppStart: false
13395
+ }, (spanInfo) => {
13396
+ const queryEmitter = self.queryMock.handleReplayQuery({
13397
+ sql,
13398
+ values,
13399
+ callback,
13400
+ options
13401
+ }, inputValue, spanInfo, stackTrace);
13402
+ if (queryEmitter && typeof queryEmitter === "object") queryEmitter.stream = function(streamOptions) {
13403
+ return self._createReplayStreamForQuery(inputValue, spanInfo, stackTrace, queryEmitter, streamOptions);
13404
+ };
13405
+ return queryEmitter;
13406
+ });
13407
+ }
13408
+ });
13409
+ } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13410
+ originalFunctionCall: () => originalQuery.apply(this, args),
13411
+ recordModeHandler: ({ isPreAppStart }) => {
13412
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(this, args), {
13413
+ name: "mysql.query",
13414
+ kind: import_src$23.SpanKind.CLIENT,
13415
+ submodule: "query",
13416
+ packageType: PackageType.MYSQL,
13417
+ packageName: "mysql",
13418
+ instrumentationName: self.INSTRUMENTATION_NAME,
13419
+ inputValue,
13420
+ isPreAppStart
13421
+ }, (spanInfo) => {
13422
+ return self._handleRecordQuery(spanInfo, originalQuery, this, args, callback, isEventEmitterMode);
13423
+ });
13424
+ },
13425
+ spanKind: import_src$23.SpanKind.CLIENT
13426
+ });
13427
+ else return originalQuery.apply(this, args);
13428
+ };
13429
+ };
13430
+ }
13431
+ /**
13432
+ * Get wrapper function for connect method
13433
+ */
13434
+ _getConnectPatchFn() {
13435
+ const self = this;
13436
+ return (originalConnect) => {
13437
+ return function connect(callback) {
13438
+ if (self.mode === TuskDriftMode.REPLAY) {
13439
+ const connectionContext = this;
13440
+ return handleReplayMode({
13441
+ noOpRequestHandler: () => {
13442
+ if (callback) setImmediate(() => callback(null));
13443
+ setImmediate(() => connectionContext.emit("connect"));
13444
+ },
13445
+ isServerRequest: false,
13446
+ replayModeHandler: () => {
13447
+ if (callback) setImmediate(() => callback(null));
13448
+ setImmediate(() => connectionContext.emit("connect"));
13449
+ }
13450
+ });
13451
+ } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13452
+ originalFunctionCall: () => originalConnect.apply(this, arguments),
13453
+ recordModeHandler: ({ isPreAppStart }) => {
13454
+ return originalConnect.apply(this, arguments);
13455
+ },
13456
+ spanKind: import_src$23.SpanKind.CLIENT
13457
+ });
13458
+ else return originalConnect.apply(this, arguments);
13459
+ };
13460
+ };
13461
+ }
13462
+ /**
13463
+ * Get wrapper function for beginTransaction method
13464
+ */
13465
+ _getBeginTransactionPatchFn() {
13466
+ const self = this;
13467
+ return (originalBeginTransaction) => {
13468
+ return function beginTransaction(callback) {
13469
+ const inputValue = { query: "BEGIN" };
13470
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13471
+ noOpRequestHandler: () => {
13472
+ if (callback) setImmediate(() => callback(null));
13473
+ },
13474
+ isServerRequest: false,
13475
+ replayModeHandler: () => {
13476
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalBeginTransaction.apply(this, arguments), {
13477
+ name: "mysql.beginTransaction",
13478
+ kind: import_src$23.SpanKind.CLIENT,
13479
+ submodule: "transaction",
13480
+ packageType: PackageType.MYSQL,
13481
+ packageName: "mysql",
13482
+ instrumentationName: self.INSTRUMENTATION_NAME,
13483
+ inputValue,
13484
+ isPreAppStart: false
13485
+ }, (spanInfo) => {
13486
+ return self._handleReplayTransaction(inputValue, callback);
13487
+ });
13488
+ }
13489
+ });
13490
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13491
+ originalFunctionCall: () => originalBeginTransaction.apply(this, arguments),
13492
+ recordModeHandler: ({ isPreAppStart }) => {
13493
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalBeginTransaction.apply(this, arguments), {
13494
+ name: "mysql.beginTransaction",
13495
+ kind: import_src$23.SpanKind.CLIENT,
13496
+ submodule: "transaction",
13497
+ packageType: PackageType.MYSQL,
13498
+ packageName: "mysql",
13499
+ instrumentationName: self.INSTRUMENTATION_NAME,
13500
+ inputValue,
13501
+ isPreAppStart
13502
+ }, (spanInfo) => {
13503
+ return self._handleRecordTransaction(spanInfo, originalBeginTransaction, this, arguments, callback);
13504
+ });
13505
+ },
13506
+ spanKind: import_src$23.SpanKind.CLIENT
13507
+ });
13508
+ else return originalBeginTransaction.apply(this, arguments);
13509
+ };
13510
+ };
13511
+ }
13512
+ /**
13513
+ * Get wrapper function for commit method
13514
+ */
13515
+ _getCommitPatchFn() {
13516
+ const self = this;
13517
+ return (originalCommit) => {
13518
+ return function commit(callback) {
13519
+ const inputValue = { query: "COMMIT" };
13520
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13521
+ noOpRequestHandler: () => {
13522
+ if (callback) setImmediate(() => callback(null));
13523
+ },
13524
+ isServerRequest: false,
13525
+ replayModeHandler: () => {
13526
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalCommit.apply(this, arguments), {
13527
+ name: "mysql.commit",
13528
+ kind: import_src$23.SpanKind.CLIENT,
13529
+ submodule: "transaction",
13530
+ packageType: PackageType.MYSQL,
13531
+ packageName: "mysql",
13532
+ instrumentationName: self.INSTRUMENTATION_NAME,
13533
+ inputValue,
13534
+ isPreAppStart: false
13535
+ }, (spanInfo) => {
13536
+ return self._handleReplayTransaction(inputValue, callback);
13537
+ });
13538
+ }
13539
+ });
13540
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13541
+ originalFunctionCall: () => originalCommit.apply(this, arguments),
13542
+ recordModeHandler: ({ isPreAppStart }) => {
13543
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalCommit.apply(this, arguments), {
13544
+ name: "mysql.commit",
13545
+ kind: import_src$23.SpanKind.CLIENT,
13546
+ submodule: "transaction",
13547
+ packageType: PackageType.MYSQL,
13548
+ packageName: "mysql",
13549
+ instrumentationName: self.INSTRUMENTATION_NAME,
13550
+ inputValue,
13551
+ isPreAppStart
13552
+ }, (spanInfo) => {
13553
+ return self._handleRecordTransaction(spanInfo, originalCommit, this, arguments, callback);
13554
+ });
13555
+ },
13556
+ spanKind: import_src$23.SpanKind.CLIENT
13557
+ });
13558
+ else return originalCommit.apply(this, arguments);
13559
+ };
13560
+ };
13561
+ }
13562
+ /**
13563
+ * Get wrapper function for rollback method
13564
+ */
13565
+ _getRollbackPatchFn() {
13566
+ const self = this;
13567
+ return (originalRollback) => {
13568
+ return function rollback(callback) {
13569
+ const inputValue = { query: "ROLLBACK" };
13570
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13571
+ noOpRequestHandler: () => {
13572
+ if (callback) setImmediate(() => callback(null));
13573
+ },
13574
+ isServerRequest: false,
13575
+ replayModeHandler: () => {
13576
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalRollback.apply(this, arguments), {
13577
+ name: "mysql.rollback",
13578
+ kind: import_src$23.SpanKind.CLIENT,
13579
+ submodule: "transaction",
13580
+ packageType: PackageType.MYSQL,
13581
+ packageName: "mysql",
13582
+ instrumentationName: self.INSTRUMENTATION_NAME,
13583
+ inputValue,
13584
+ isPreAppStart: false
13585
+ }, (spanInfo) => {
13586
+ return self._handleReplayTransaction(inputValue, callback);
13587
+ });
13588
+ }
13589
+ });
13590
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13591
+ originalFunctionCall: () => originalRollback.apply(this, arguments),
13592
+ recordModeHandler: ({ isPreAppStart }) => {
13593
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalRollback.apply(this, arguments), {
13594
+ name: "mysql.rollback",
13595
+ kind: import_src$23.SpanKind.CLIENT,
13596
+ submodule: "transaction",
13597
+ packageType: PackageType.MYSQL,
13598
+ packageName: "mysql",
13599
+ instrumentationName: self.INSTRUMENTATION_NAME,
13600
+ inputValue,
13601
+ isPreAppStart
13602
+ }, (spanInfo) => {
13603
+ return self._handleRecordTransaction(spanInfo, originalRollback, this, arguments, callback);
13604
+ });
13605
+ },
13606
+ spanKind: import_src$23.SpanKind.CLIENT
13607
+ });
13608
+ else return originalRollback.apply(this, arguments);
13609
+ };
13610
+ };
13611
+ }
13612
+ /**
13613
+ * Get wrapper function for ping method
13614
+ */
13615
+ _getPingPatchFn() {
13616
+ const self = this;
13617
+ return (originalPing) => {
13618
+ return function ping(callback) {
13619
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13620
+ noOpRequestHandler: () => {
13621
+ if (callback) setImmediate(() => callback(null));
13622
+ },
13623
+ isServerRequest: false,
13624
+ replayModeHandler: () => {
13625
+ if (callback) setImmediate(() => callback(null));
13626
+ }
13627
+ });
13628
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13629
+ originalFunctionCall: () => originalPing.apply(this, arguments),
13630
+ recordModeHandler: ({ isPreAppStart }) => {
13631
+ return originalPing.apply(this, arguments);
13632
+ },
13633
+ spanKind: import_src$23.SpanKind.CLIENT
13634
+ });
13635
+ else return originalPing.apply(this, arguments);
13636
+ };
13637
+ };
13638
+ }
13639
+ /**
13640
+ * Get wrapper function for end method
13641
+ */
13642
+ _getEndPatchFn() {
13643
+ const self = this;
13644
+ return (originalEnd) => {
13645
+ return function end(callback) {
13646
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13647
+ noOpRequestHandler: () => {
13648
+ if (callback) setImmediate(() => callback(null));
13649
+ setImmediate(() => this.emit("end"));
13650
+ },
13651
+ isServerRequest: false,
13652
+ replayModeHandler: () => {
13653
+ if (callback) setImmediate(() => callback(null));
13654
+ setImmediate(() => this.emit("end"));
13655
+ }
13656
+ });
13657
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13658
+ originalFunctionCall: () => originalEnd.apply(this, arguments),
13659
+ recordModeHandler: ({ isPreAppStart }) => {
13660
+ return originalEnd.apply(this, arguments);
13661
+ },
13662
+ spanKind: import_src$23.SpanKind.CLIENT
13663
+ });
13664
+ else return originalEnd.apply(this, arguments);
13665
+ };
13666
+ };
13667
+ }
13668
+ /**
13669
+ * Get wrapper function for changeUser method
13670
+ */
13671
+ _getChangeUserPatchFn() {
13672
+ const self = this;
13673
+ return (originalChangeUser) => {
13674
+ return function changeUser(options, callback) {
13675
+ let userCallback = callback;
13676
+ if (typeof options === "function") userCallback = options;
13677
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13678
+ noOpRequestHandler: () => {
13679
+ if (userCallback) setImmediate(() => userCallback(null));
13680
+ },
13681
+ isServerRequest: false,
13682
+ replayModeHandler: () => {
13683
+ if (userCallback) setImmediate(() => userCallback(null));
13684
+ }
13685
+ });
13686
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13687
+ originalFunctionCall: () => originalChangeUser.apply(this, arguments),
13688
+ recordModeHandler: ({ isPreAppStart }) => {
13689
+ return originalChangeUser.apply(this, arguments);
13690
+ },
13691
+ spanKind: import_src$23.SpanKind.CLIENT
13692
+ });
13693
+ else return originalChangeUser.apply(this, arguments);
13694
+ };
13695
+ };
13696
+ }
13697
+ /**
13698
+ * Get wrapper function for pause method
13699
+ */
13700
+ _getPausePatchFn() {
13701
+ const self = this;
13702
+ return (originalPause) => {
13703
+ return function pause() {
13704
+ if (self.mode === TuskDriftMode.REPLAY) return;
13705
+ else if (self.mode === TuskDriftMode.RECORD) return originalPause.apply(this, arguments);
13706
+ else return originalPause.apply(this, arguments);
13707
+ };
13708
+ };
13709
+ }
13710
+ /**
13711
+ * Get wrapper function for resume method
13712
+ */
13713
+ _getResumePatchFn() {
13714
+ const self = this;
13715
+ return (originalResume) => {
13716
+ return function resume() {
13717
+ if (self.mode === TuskDriftMode.REPLAY) return;
13718
+ else if (self.mode === TuskDriftMode.RECORD) return originalResume.apply(this, arguments);
13719
+ else return originalResume.apply(this, arguments);
13720
+ };
13721
+ };
13722
+ }
13723
+ /**
13724
+ * Get wrapper function for destroy method
13725
+ */
13726
+ _getDestroyPatchFn() {
13727
+ const self = this;
13728
+ return (originalDestroy) => {
13729
+ return function destroy() {
13730
+ if (self.mode === TuskDriftMode.REPLAY) return;
13731
+ else if (self.mode === TuskDriftMode.RECORD) return originalDestroy.apply(this, arguments);
13732
+ else return originalDestroy.apply(this, arguments);
13733
+ };
13734
+ };
13735
+ }
13736
+ /**
13737
+ * Get wrapper function for Pool.end method
13738
+ */
13739
+ _getPoolEndPatchFn() {
13740
+ const self = this;
13741
+ return (originalEnd) => {
13742
+ return function end(callback) {
13743
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13744
+ noOpRequestHandler: () => {
13745
+ if (callback) setImmediate(() => callback(null));
13746
+ },
13747
+ isServerRequest: false,
13748
+ replayModeHandler: () => {
13749
+ if (callback) setImmediate(() => callback(null));
13750
+ }
13751
+ });
13752
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13753
+ originalFunctionCall: () => originalEnd.apply(this, arguments),
13754
+ recordModeHandler: ({ isPreAppStart }) => {
13755
+ return originalEnd.apply(this, arguments);
13756
+ },
13757
+ spanKind: import_src$23.SpanKind.CLIENT
13758
+ });
13759
+ else return originalEnd.apply(this, arguments);
13760
+ };
13761
+ };
13762
+ }
13763
+ /**
13764
+ * Get wrapper function for Pool.getConnection method
13765
+ */
13766
+ _getPoolGetConnectionPatchFn() {
13767
+ const self = this;
13768
+ return (originalGetConnection) => {
13769
+ return function getConnection(callback) {
13770
+ const inputValue = { clientType: "pool" };
13771
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13772
+ noOpRequestHandler: () => {
13773
+ return self._handleNoOpReplayGetConnection(callback);
13774
+ },
13775
+ isServerRequest: false,
13776
+ replayModeHandler: () => {
13777
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalGetConnection.apply(this, [callback]), {
13778
+ name: `mysql.pool.getConnection`,
13779
+ kind: import_src$23.SpanKind.CLIENT,
13780
+ submodule: "getConnection",
13781
+ packageName: "mysql",
13782
+ packageType: PackageType.MYSQL,
13783
+ instrumentationName: self.INSTRUMENTATION_NAME,
13784
+ inputValue,
13785
+ isPreAppStart: false
13786
+ }, (spanInfo) => {
13787
+ return self._handleReplayPoolGetConnection(spanInfo, callback);
13788
+ });
13789
+ }
13790
+ });
13791
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13792
+ originalFunctionCall: () => originalGetConnection.apply(this, [callback]),
13793
+ recordModeHandler: ({ isPreAppStart }) => {
13794
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalGetConnection.apply(this, [callback]), {
13795
+ name: `mysql.pool.getConnection`,
13796
+ kind: import_src$23.SpanKind.CLIENT,
13797
+ submodule: "getConnection",
13798
+ packageName: "mysql",
13799
+ packageType: PackageType.MYSQL,
13800
+ instrumentationName: self.INSTRUMENTATION_NAME,
13801
+ inputValue,
13802
+ isPreAppStart
13803
+ }, (spanInfo) => {
13804
+ return self._handleRecordPoolGetConnectionInSpan(spanInfo, originalGetConnection, callback, this);
13805
+ });
13806
+ },
13807
+ spanKind: import_src$23.SpanKind.CLIENT
13808
+ });
13809
+ else return originalGetConnection.apply(this, [callback]);
13810
+ };
13811
+ };
13812
+ }
13813
+ _patchQueryMethod(connection) {
13814
+ const self = this;
13815
+ return (originalQuery) => {
13816
+ return function query(...args) {
13817
+ let sql;
13818
+ let values;
13819
+ let callback;
13820
+ let options = {};
13821
+ if (self.createQuery) try {
13822
+ const queryObj = self.createQuery(...args);
13823
+ sql = queryObj.sql;
13824
+ values = queryObj.values;
13825
+ options = { nestTables: queryObj.nestTables };
13826
+ callback = args.find((arg) => typeof arg === "function");
13827
+ } catch (error) {
13828
+ logger.debug(`[MysqlInstrumentation] Error using createQuery, falling back to manual parsing:`, error);
13829
+ ({sql, values, callback, options} = self._parseQueryArgs(args));
13830
+ }
13831
+ else ({sql, values, callback, options} = self._parseQueryArgs(args));
13832
+ const inputValue = {
13833
+ sql,
13834
+ values,
13835
+ options: options.nestTables ? { nestTables: options.nestTables } : void 0
13836
+ };
13837
+ const isEventEmitterMode = !callback;
13838
+ if (self.mode === TuskDriftMode.REPLAY) {
13839
+ const stackTrace = captureStackTrace(["MysqlInstrumentation"]);
13840
+ return handleReplayMode({
13841
+ noOpRequestHandler: () => {
13842
+ if (isEventEmitterMode) return new EventEmitter();
13843
+ },
13844
+ isServerRequest: false,
13845
+ replayModeHandler: () => {
13846
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(connection, args), {
13847
+ name: "mysql.query",
13848
+ kind: import_src$23.SpanKind.CLIENT,
13849
+ submodule: "query",
13850
+ packageType: PackageType.MYSQL,
13851
+ packageName: "mysql",
13852
+ instrumentationName: self.INSTRUMENTATION_NAME,
13853
+ inputValue,
13854
+ isPreAppStart: false
13855
+ }, (spanInfo) => {
13856
+ const queryEmitter = self.queryMock.handleReplayQuery({
13857
+ sql: inputValue.sql,
13858
+ values: inputValue.values,
13859
+ callback,
13860
+ options: inputValue.options
13861
+ }, inputValue, spanInfo, stackTrace);
13862
+ if (queryEmitter && typeof queryEmitter === "object") queryEmitter.stream = function(streamOptions) {
13863
+ return self._createReplayStreamForQuery(inputValue, spanInfo, stackTrace, queryEmitter, streamOptions);
13864
+ };
13865
+ return queryEmitter;
13866
+ });
13867
+ }
13868
+ });
13869
+ } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13870
+ originalFunctionCall: () => originalQuery.apply(connection, args),
13871
+ recordModeHandler: ({ isPreAppStart }) => {
13872
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(connection, args), {
13873
+ name: "mysql.query",
13874
+ kind: import_src$23.SpanKind.CLIENT,
13875
+ submodule: "query",
13876
+ packageType: PackageType.MYSQL,
13877
+ packageName: "mysql",
13878
+ instrumentationName: self.INSTRUMENTATION_NAME,
13879
+ inputValue,
13880
+ isPreAppStart
13881
+ }, (spanInfo) => {
13882
+ return self._handleRecordQuery(spanInfo, originalQuery, connection, args, callback, isEventEmitterMode);
13883
+ });
13884
+ },
13885
+ spanKind: import_src$23.SpanKind.CLIENT
13886
+ });
13887
+ else return originalQuery.apply(connection, args);
13888
+ };
13889
+ };
13890
+ }
13891
+ _handleRecordQuery(spanInfo, originalQuery, connection, args, callback, isEventEmitterMode) {
13892
+ if (isEventEmitterMode) {
13893
+ const queryEmitter = originalQuery.apply(connection, args);
13894
+ const results = [];
13895
+ const fields = [];
13896
+ let error = null;
13897
+ let queryIndex = 0;
13898
+ queryEmitter.on("error", (err) => {
13899
+ error = err;
13900
+ queryIndex = queryEmitter._index || queryIndex;
13901
+ logger.debug(`[MysqlInstrumentation] Query error: ${err.message}`);
13902
+ }).on("fields", (fieldPackets, index) => {
13903
+ fields[index] = fieldPackets;
13904
+ }).on("result", (row, index) => {
13905
+ queryIndex = index;
13906
+ if (!results[index]) if (isMysqlOkPacket(row)) results[index] = row;
13907
+ else results[index] = [];
13908
+ if (Array.isArray(results[index])) results[index].push(row);
13909
+ }).on("end", () => {
13910
+ const finalQueryCount = this._getQueryCount(queryEmitter) || queryIndex + 1;
13911
+ const outputValue = finalQueryCount > 1 ? {
13912
+ results,
13913
+ fields,
13914
+ queryCount: finalQueryCount,
13915
+ errQueryIndex: error ? queryIndex : void 0
13916
+ } : {
13917
+ results: results[0],
13918
+ fields: fields[0],
13919
+ queryCount: finalQueryCount
13920
+ };
13921
+ if (error) try {
13922
+ SpanUtils.endSpan(spanInfo.span, {
13923
+ code: import_src$23.SpanStatusCode.ERROR,
13924
+ message: error.message
13925
+ });
13926
+ } catch (error$1) {
13927
+ logger.error(`[MysqlInstrumentation] error ending span:`, error$1);
13928
+ }
13929
+ else try {
13930
+ SpanUtils.addSpanAttributes(spanInfo.span, { outputValue });
13931
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
13932
+ } catch (error$1) {
13933
+ logger.error(`[MysqlInstrumentation] error ending span:`, error$1);
13934
+ }
13935
+ logger.debug(`[MysqlInstrumentation] Query completed`);
13936
+ });
13937
+ return queryEmitter;
13938
+ } else {
13939
+ const originalCallback = callback;
13940
+ const callbackIndex = args.findIndex((arg) => typeof arg === "function");
13941
+ args[callbackIndex] = function(err, results, fields) {
13942
+ if (err) try {
13943
+ SpanUtils.endSpan(spanInfo.span, {
13944
+ code: import_src$23.SpanStatusCode.ERROR,
13945
+ message: err.message
13946
+ });
13947
+ } catch (error) {
13948
+ logger.error(`[MysqlInstrumentation] error ending span:`, error);
13949
+ }
13950
+ else try {
13951
+ const outputValue = {
13952
+ results,
13953
+ fields
13954
+ };
13955
+ SpanUtils.addSpanAttributes(spanInfo.span, { outputValue });
13956
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
13957
+ } catch (error) {
13958
+ logger.error(`[MysqlInstrumentation] error ending span:`, error);
13959
+ }
13960
+ logger.debug(`[MysqlInstrumentation] Query completed`);
13961
+ return originalCallback.apply(this, arguments);
13962
+ };
13963
+ return originalQuery.apply(connection, args);
13964
+ }
13965
+ }
13966
+ _patchConnect(connection) {
13967
+ const self = this;
13968
+ return (originalConnect) => {
13969
+ return function connect(callback) {
13970
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13971
+ noOpRequestHandler: () => {
13972
+ if (callback) setImmediate(() => callback(null));
13973
+ },
13974
+ isServerRequest: false,
13975
+ replayModeHandler: () => {
13976
+ if (callback) setImmediate(() => callback(null));
13977
+ }
13978
+ });
13979
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
13980
+ originalFunctionCall: () => originalConnect.apply(connection, arguments),
13981
+ recordModeHandler: ({ isPreAppStart }) => {
13982
+ return originalConnect.apply(connection, arguments);
13983
+ },
13984
+ spanKind: import_src$23.SpanKind.CLIENT
13985
+ });
13986
+ else return originalConnect.apply(connection, arguments);
13987
+ };
13988
+ };
13989
+ }
13990
+ _patchBeginTransaction(connection) {
13991
+ const self = this;
13992
+ return (originalBeginTransaction) => {
13993
+ return function beginTransaction(callback) {
13994
+ const inputValue = { query: "BEGIN" };
13995
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
13996
+ noOpRequestHandler: () => {
13997
+ if (callback) setImmediate(() => callback(null));
13998
+ },
13999
+ isServerRequest: false,
14000
+ replayModeHandler: () => {
14001
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalBeginTransaction.apply(connection, arguments), {
14002
+ name: "mysql.beginTransaction",
14003
+ kind: import_src$23.SpanKind.CLIENT,
14004
+ submodule: "transaction",
14005
+ packageType: PackageType.MYSQL,
14006
+ packageName: "mysql",
14007
+ instrumentationName: self.INSTRUMENTATION_NAME,
14008
+ inputValue,
14009
+ isPreAppStart: false
14010
+ }, (spanInfo) => {
14011
+ return self._handleReplayTransaction(inputValue, callback);
14012
+ });
14013
+ }
14014
+ });
14015
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
14016
+ originalFunctionCall: () => originalBeginTransaction.apply(connection, arguments),
14017
+ recordModeHandler: ({ isPreAppStart }) => {
14018
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalBeginTransaction.apply(connection, arguments), {
14019
+ name: "mysql.beginTransaction",
14020
+ kind: import_src$23.SpanKind.CLIENT,
14021
+ submodule: "transaction",
14022
+ packageType: PackageType.MYSQL,
14023
+ packageName: "mysql",
14024
+ instrumentationName: self.INSTRUMENTATION_NAME,
14025
+ inputValue,
14026
+ isPreAppStart
14027
+ }, (spanInfo) => {
14028
+ return self._handleRecordTransaction(spanInfo, originalBeginTransaction, connection, arguments, callback);
14029
+ });
14030
+ },
14031
+ spanKind: import_src$23.SpanKind.CLIENT
14032
+ });
14033
+ else return originalBeginTransaction.apply(connection, arguments);
14034
+ };
14035
+ };
14036
+ }
14037
+ _patchCommit(connection) {
14038
+ const self = this;
14039
+ return (originalCommit) => {
14040
+ return function commit(callback) {
14041
+ const inputValue = { query: "COMMIT" };
14042
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
14043
+ noOpRequestHandler: () => {
14044
+ if (callback) setImmediate(() => callback(null));
14045
+ },
14046
+ isServerRequest: false,
14047
+ replayModeHandler: () => {
14048
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalCommit.apply(connection, arguments), {
14049
+ name: "mysql.commit",
14050
+ kind: import_src$23.SpanKind.CLIENT,
14051
+ submodule: "transaction",
14052
+ packageType: PackageType.MYSQL,
14053
+ packageName: "mysql",
14054
+ instrumentationName: self.INSTRUMENTATION_NAME,
14055
+ inputValue,
14056
+ isPreAppStart: false
14057
+ }, (spanInfo) => {
14058
+ return self._handleReplayTransaction(inputValue, callback);
14059
+ });
14060
+ }
14061
+ });
14062
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
14063
+ originalFunctionCall: () => originalCommit.apply(connection, arguments),
14064
+ recordModeHandler: ({ isPreAppStart }) => {
14065
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalCommit.apply(connection, arguments), {
14066
+ name: "mysql.commit",
14067
+ kind: import_src$23.SpanKind.CLIENT,
14068
+ submodule: "transaction",
14069
+ packageType: PackageType.MYSQL,
14070
+ packageName: "mysql",
14071
+ instrumentationName: self.INSTRUMENTATION_NAME,
14072
+ inputValue,
14073
+ isPreAppStart
14074
+ }, (spanInfo) => {
14075
+ return self._handleRecordTransaction(spanInfo, originalCommit, connection, arguments, callback);
14076
+ });
14077
+ },
14078
+ spanKind: import_src$23.SpanKind.CLIENT
14079
+ });
14080
+ else return originalCommit.apply(connection, arguments);
14081
+ };
14082
+ };
14083
+ }
14084
+ _patchRollback(connection) {
14085
+ const self = this;
14086
+ return (originalRollback) => {
14087
+ return function rollback(callback) {
14088
+ const inputValue = { query: "ROLLBACK" };
14089
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
14090
+ noOpRequestHandler: () => {
14091
+ if (callback) setImmediate(() => callback(null));
14092
+ },
14093
+ isServerRequest: false,
14094
+ replayModeHandler: () => {
14095
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalRollback.apply(connection, arguments), {
14096
+ name: "mysql.rollback",
14097
+ kind: import_src$23.SpanKind.CLIENT,
14098
+ submodule: "transaction",
14099
+ packageType: PackageType.MYSQL,
14100
+ packageName: "mysql",
14101
+ instrumentationName: self.INSTRUMENTATION_NAME,
14102
+ inputValue,
14103
+ isPreAppStart: false
14104
+ }, (spanInfo) => {
14105
+ return self._handleReplayTransaction(inputValue, callback);
14106
+ });
14107
+ }
14108
+ });
14109
+ else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
14110
+ originalFunctionCall: () => originalRollback.apply(connection, arguments),
14111
+ recordModeHandler: ({ isPreAppStart }) => {
14112
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalRollback.apply(connection, arguments), {
14113
+ name: "mysql.rollback",
14114
+ kind: import_src$23.SpanKind.CLIENT,
14115
+ submodule: "transaction",
14116
+ packageType: PackageType.MYSQL,
14117
+ packageName: "mysql",
14118
+ instrumentationName: self.INSTRUMENTATION_NAME,
14119
+ inputValue,
14120
+ isPreAppStart
14121
+ }, (spanInfo) => {
14122
+ return self._handleRecordTransaction(spanInfo, originalRollback, connection, arguments, callback);
14123
+ });
14124
+ },
14125
+ spanKind: import_src$23.SpanKind.CLIENT
14126
+ });
14127
+ else return originalRollback.apply(connection, arguments);
14128
+ };
14129
+ };
12749
14130
  }
12750
- async _handleRecordQueryInSpan(spanInfo, originalSql, strings, values) {
12751
- try {
12752
- const result = await originalSql.call(this, strings, ...values);
14131
+ _handleRecordTransaction(spanInfo, originalFunction, connection, args, callback) {
14132
+ if (!callback) try {
14133
+ const result = originalFunction.apply(connection, args);
12753
14134
  try {
12754
- logger.debug(`[PostgresInstrumentation] Postgres query completed successfully (${SpanUtils.getTraceInfo()})`);
12755
- this._addOutputAttributesToSpan(spanInfo, result);
14135
+ SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: { status: "success" } });
12756
14136
  SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
12757
14137
  } catch (error) {
12758
- logger.error(`[PostgresInstrumentation] error processing query response:`, error);
14138
+ logger.error(`[MysqlInstrumentation] error adding span attributes:`, error);
12759
14139
  }
12760
14140
  return result;
12761
14141
  } catch (error) {
12762
14142
  try {
12763
- logger.debug(`[PostgresInstrumentation] Postgres query error: ${error.message} (${SpanUtils.getTraceInfo()})`);
12764
14143
  SpanUtils.endSpan(spanInfo.span, {
12765
14144
  code: import_src$23.SpanStatusCode.ERROR,
12766
14145
  message: error.message
12767
14146
  });
12768
- } catch (spanError) {
12769
- logger.error(`[PostgresInstrumentation] error ending span:`, spanError);
14147
+ } catch (error$1) {
14148
+ logger.error(`[MysqlInstrumentation] error ending span:`, error$1);
12770
14149
  }
12771
14150
  throw error;
12772
14151
  }
12773
- }
12774
- async handleReplaySqlQuery({ inputValue, spanInfo, submodule, name, stackTrace }) {
12775
- logger.debug(`[PostgresInstrumentation] Replaying Postgres sql query`);
12776
- const mockData = await findMockResponseAsync({
12777
- mockRequestData: {
12778
- traceId: spanInfo.traceId,
12779
- spanId: spanInfo.spanId,
12780
- name,
12781
- inputValue,
12782
- packageName: "postgres",
12783
- instrumentationName: this.INSTRUMENTATION_NAME,
12784
- submoduleName: submodule,
12785
- kind: import_src$23.SpanKind.CLIENT,
12786
- stackTrace
12787
- },
12788
- tuskDrift: this.tuskDrift
12789
- });
12790
- if (!mockData) {
12791
- const queryText = inputValue.query || "UNKNOWN_QUERY";
12792
- logger.warn(`[PostgresInstrumentation] No mock data found for Postgres sql query: ${queryText}`);
12793
- throw new Error(`[PostgresInstrumentation] No matching mock found for Postgres sql query: ${queryText}`);
14152
+ const argsArray = Array.from(args);
14153
+ const callbackIndex = argsArray.findIndex((arg) => typeof arg === "function");
14154
+ if (callbackIndex !== -1) {
14155
+ const originalCallback = callback;
14156
+ argsArray[callbackIndex] = function(err) {
14157
+ if (err) try {
14158
+ SpanUtils.endSpan(spanInfo.span, {
14159
+ code: import_src$23.SpanStatusCode.ERROR,
14160
+ message: err.message
14161
+ });
14162
+ } catch (error) {
14163
+ logger.error(`[MysqlInstrumentation] error ending span:`, error);
14164
+ }
14165
+ else try {
14166
+ SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: { status: "success" } });
14167
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
14168
+ } catch (error) {
14169
+ logger.error(`[MysqlInstrumentation] error ending span:`, error);
14170
+ }
14171
+ logger.debug(`[MysqlInstrumentation] Transaction completed`);
14172
+ return originalCallback.apply(this, arguments);
14173
+ };
14174
+ argsArray[callbackIndex] = import_src$23.context.bind(spanInfo.context, argsArray[callbackIndex]);
12794
14175
  }
12795
- logger.debug(`[PostgresInstrumentation] Found mock data for Postgres sql query: ${JSON.stringify(mockData)}`);
12796
- const processedResult = this.convertPostgresTypes(mockData.result);
12797
- logger.debug(`[PostgresInstrumentation] Sql query processed result: ${JSON.stringify(processedResult)}`);
12798
- const isResultObject = processedResult && typeof processedResult === "object" && "rows" in processedResult;
12799
- const rows = isResultObject ? processedResult.rows || [] : processedResult || [];
12800
- return Object.assign(rows, {
12801
- command: isResultObject ? processedResult.command : void 0,
12802
- count: isResultObject ? processedResult.count : void 0
12803
- });
14176
+ return originalFunction.apply(connection, argsArray);
12804
14177
  }
12805
- async handleReplayUnsafeQuery({ inputValue, spanInfo, submodule, name, stackTrace }) {
12806
- logger.debug(`[PostgresInstrumentation] Replaying Postgres unsafe query`);
12807
- const mockData = await findMockResponseAsync({
12808
- mockRequestData: {
12809
- traceId: spanInfo.traceId,
12810
- spanId: spanInfo.spanId,
12811
- name,
12812
- inputValue,
12813
- packageName: "postgres",
12814
- instrumentationName: this.INSTRUMENTATION_NAME,
12815
- submoduleName: submodule,
12816
- kind: import_src$23.SpanKind.CLIENT,
12817
- stackTrace
12818
- },
12819
- tuskDrift: this.tuskDrift
14178
+ async _handleReplayTransaction(inputValue, callback) {
14179
+ logger.debug(`[MysqlInstrumentation] Replaying MySQL transaction: ${inputValue.query}`);
14180
+ if (callback) setImmediate(() => {
14181
+ callback(null);
12820
14182
  });
12821
- if (!mockData) {
12822
- const queryText = inputValue.query || "UNKNOWN_QUERY";
12823
- logger.warn(`[PostgresInstrumentation] No mock data found for Postgres unsafe query: ${queryText}`);
12824
- throw new Error(`[PostgresInstrumentation] No matching mock found for Postgres unsafe query: ${queryText}`);
12825
- }
12826
- logger.debug(`[PostgresInstrumentation] Found mock data for Postgres unsafe query: ${JSON.stringify(mockData)}`);
12827
- const processedResult = this.convertPostgresTypes(mockData.result);
12828
- logger.debug(`[PostgresInstrumentation] Unsafe query processed result: ${JSON.stringify(processedResult)}`);
12829
- return processedResult;
12830
14183
  }
12831
- /**
12832
- * Create a postgres.js-compatible PendingQuery wrapper.
12833
- * This creates a thenable object with .values(), .raw(), etc. methods
12834
- * that matches the postgres.js PendingQuery interface.
12835
- *
12836
- * NOTE: This wrapper is ONLY needed for unsafe() queries, not template string queries.
12837
- * - unsafe() returns a PendingQuery with .values() method that Drizzle calls
12838
- * - Template strings return a plain Promise/array and don't need the wrapper
12839
- *
12840
- * Also NOTE: unsafe expects a PendingQuery in return. This includes most common ones, but not all.
12841
- * There is a possiblity we need to add the rest of the methods to the PendingQuery interface from "postgres" library.
12842
- */
12843
- _createPendingQueryWrapper(queryPromiseFactory) {
12844
- const mainPromise = queryPromiseFactory();
12845
- return Object.assign(mainPromise, { values: () => {
12846
- return mainPromise.then((result) => {
12847
- if (!result) return [];
12848
- const isResultObject = typeof result === "object" && "rows" in result;
12849
- const valueArrays = (isResultObject ? result.rows || [] : Array.isArray(result) ? result : []).map((row) => {
12850
- if (Array.isArray(row)) return row;
12851
- return Object.values(row);
12852
- });
12853
- return Object.assign(valueArrays, {
12854
- command: isResultObject ? result.command : void 0,
12855
- count: isResultObject ? result.count : void 0
12856
- });
14184
+ _handleRecordPoolGetConnectionInSpan(spanInfo, originalGetConnection, callback, context$6) {
14185
+ const self = this;
14186
+ if (callback) {
14187
+ const wrappedCallback = (error, connection) => {
14188
+ if (error) {
14189
+ logger.debug(`[MysqlInstrumentation] MySQL Pool getConnection error: ${error.message} (${SpanUtils.getTraceInfo()})`);
14190
+ SpanUtils.endSpan(spanInfo.span, {
14191
+ code: import_src$23.SpanStatusCode.ERROR,
14192
+ message: error.message
14193
+ });
14194
+ } else {
14195
+ logger.debug(`[MysqlInstrumentation] MySQL Pool getConnection completed successfully (${SpanUtils.getTraceInfo()})`);
14196
+ if (connection) {
14197
+ self._wrap(connection, "query", self._patchQueryMethod(connection));
14198
+ self._wrap(connection, "connect", self._patchConnect(connection));
14199
+ self._wrap(connection, "beginTransaction", self._patchBeginTransaction(connection));
14200
+ self._wrap(connection, "commit", self._patchCommit(connection));
14201
+ self._wrap(connection, "rollback", self._patchRollback(connection));
14202
+ }
14203
+ SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: {
14204
+ connected: true,
14205
+ hasConnection: !!connection
14206
+ } });
14207
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
14208
+ }
14209
+ return callback(error, connection);
14210
+ };
14211
+ return originalGetConnection.call(context$6, wrappedCallback);
14212
+ } else try {
14213
+ const result = originalGetConnection.call(context$6);
14214
+ SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: {
14215
+ connected: true,
14216
+ hasConnection: true
14217
+ } });
14218
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
14219
+ return result;
14220
+ } catch (error) {
14221
+ SpanUtils.endSpan(spanInfo.span, {
14222
+ code: import_src$23.SpanStatusCode.ERROR,
14223
+ message: error.message
12857
14224
  });
12858
- } });
14225
+ throw error;
14226
+ }
12859
14227
  }
12860
- /**
12861
- * Convert PostgreSQL string values back to appropriate JavaScript types
12862
- * based on common PostgreSQL data patterns.
12863
- */
12864
- convertPostgresTypes(result) {
12865
- if (!isPostgresOutputValueType(result)) {
12866
- logger.error(`[PostgresInstrumentation] output value is not of type PostgresOutputValueType: ${JSON.stringify(result)}`);
14228
+ _handleNoOpReplayGetConnection(callback) {
14229
+ logger.debug(`[MysqlInstrumentation] Background getConnection detected, returning mock connection`);
14230
+ const mockConnection = new TdMysqlConnectionMock(this, "pool");
14231
+ if (callback) {
14232
+ process.nextTick(() => callback(null, mockConnection));
12867
14233
  return;
12868
14234
  }
12869
- if (!result) return;
12870
- const { _tdOriginalFormat: originalFormat,...convertedResult } = result;
12871
- if (originalFormat === PostgresReturnType.OBJECT) return convertedResult;
12872
- else if (originalFormat === PostgresReturnType.ARRAY) return convertedResult.rows || [];
12873
- else {
12874
- logger.error(`[PostgresInstrumentation] Invalid result format: ${JSON.stringify(result)}`);
14235
+ return mockConnection;
14236
+ }
14237
+ _handleReplayPoolGetConnection(spanInfo, callback) {
14238
+ logger.debug(`[MysqlInstrumentation] Replaying MySQL Pool getConnection`);
14239
+ const mockConnection = new TdMysqlConnectionMock(this, "pool", spanInfo);
14240
+ if (callback) {
14241
+ process.nextTick(() => callback(null, mockConnection));
12875
14242
  return;
12876
14243
  }
14244
+ return mockConnection;
12877
14245
  }
12878
- _addOutputAttributesToSpan(spanInfo, result) {
12879
- if (!result) return;
12880
- let outputValue;
12881
- if (Array.isArray(result)) {
12882
- logger.debug(`[PostgresInstrumentation] Adding output attributes to span for array result: ${JSON.stringify(result)}`);
12883
- outputValue = {
12884
- _tdOriginalFormat: PostgresReturnType.ARRAY,
12885
- rows: result
12886
- };
12887
- } else if (typeof result === "object") {
12888
- logger.debug(`[PostgresInstrumentation] Adding output attributes to span for object result: ${JSON.stringify(result)}`);
12889
- outputValue = {
12890
- _tdOriginalFormat: PostgresReturnType.OBJECT,
12891
- count: result.count,
12892
- rows: result.rows,
12893
- command: result.command
14246
+ /**
14247
+ * Handle replay of a query from a mock connection (used by TdMysqlConnectionMock)
14248
+ * Returns an EventEmitter synchronously for streaming support
14249
+ */
14250
+ handleReplayQueryFromMock(spanInfo, inputValue, callback) {
14251
+ const stackTrace = captureStackTrace(["TdMysqlConnectionMock"]);
14252
+ return this.queryMock.handleReplayQuery({
14253
+ sql: inputValue.sql,
14254
+ values: inputValue.values,
14255
+ callback,
14256
+ options: inputValue.options
14257
+ }, inputValue, spanInfo, stackTrace);
14258
+ }
14259
+ /**
14260
+ * Get wrapper function for Query.stream method
14261
+ */
14262
+ _getStreamPatchFn() {
14263
+ const self = this;
14264
+ return (originalStream) => {
14265
+ return function stream(streamOptions) {
14266
+ const queryInstance = this;
14267
+ const sql = queryInstance.sql;
14268
+ const values = queryInstance.values;
14269
+ const nestTables = queryInstance.nestTables;
14270
+ const inputValue = {
14271
+ sql,
14272
+ values,
14273
+ streamOptions,
14274
+ options: nestTables ? { nestTables } : void 0
14275
+ };
14276
+ if (self.mode === TuskDriftMode.REPLAY) {
14277
+ const stackTrace = captureStackTrace(["MysqlInstrumentation"]);
14278
+ return handleReplayMode({
14279
+ noOpRequestHandler: () => {
14280
+ return new Readable({
14281
+ objectMode: true,
14282
+ read() {
14283
+ this.push(null);
14284
+ }
14285
+ });
14286
+ },
14287
+ isServerRequest: false,
14288
+ replayModeHandler: () => {
14289
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalStream.apply(queryInstance, arguments), {
14290
+ name: "mysql.stream",
14291
+ kind: import_src$23.SpanKind.CLIENT,
14292
+ submodule: "stream",
14293
+ packageType: PackageType.MYSQL,
14294
+ packageName: "mysql",
14295
+ instrumentationName: self.INSTRUMENTATION_NAME,
14296
+ inputValue,
14297
+ isPreAppStart: false
14298
+ }, (spanInfo) => {
14299
+ return self._handleReplayStream(inputValue, spanInfo, stackTrace, queryInstance);
14300
+ });
14301
+ }
14302
+ });
14303
+ } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
14304
+ originalFunctionCall: () => originalStream.apply(queryInstance, arguments),
14305
+ recordModeHandler: ({ isPreAppStart }) => {
14306
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalStream.apply(queryInstance, arguments), {
14307
+ name: "mysql.stream",
14308
+ kind: import_src$23.SpanKind.CLIENT,
14309
+ submodule: "stream",
14310
+ packageType: PackageType.MYSQL,
14311
+ packageName: "mysql",
14312
+ instrumentationName: self.INSTRUMENTATION_NAME,
14313
+ inputValue,
14314
+ isPreAppStart
14315
+ }, (spanInfo) => {
14316
+ return self._handleRecordStream(spanInfo, originalStream, queryInstance, streamOptions);
14317
+ });
14318
+ },
14319
+ spanKind: import_src$23.SpanKind.CLIENT
14320
+ });
14321
+ else return originalStream.apply(queryInstance, arguments);
12894
14322
  };
14323
+ };
14324
+ }
14325
+ /**
14326
+ * Helper to get query count from Query instance
14327
+ */
14328
+ _getQueryCount(queryInstance) {
14329
+ return queryInstance?._index || 0;
14330
+ }
14331
+ /**
14332
+ * Parse query arguments manually (fallback when createQuery is not available)
14333
+ */
14334
+ _parseQueryArgs(args) {
14335
+ let sql;
14336
+ let values;
14337
+ let callback;
14338
+ let options = {};
14339
+ if (typeof args[0] === "string") {
14340
+ sql = args[0];
14341
+ if (typeof args[1] === "function") callback = args[1];
14342
+ else if (Array.isArray(args[1])) {
14343
+ values = args[1];
14344
+ callback = args[2];
14345
+ }
14346
+ } else if (typeof args[0] === "object") {
14347
+ options = args[0];
14348
+ sql = options.sql;
14349
+ values = options.values;
14350
+ if (typeof args[1] === "function") callback = args[1];
14351
+ else if (Array.isArray(args[1])) {
14352
+ values = args[1];
14353
+ callback = args[2];
14354
+ }
12895
14355
  } else {
12896
- logger.error(`[PostgresInstrumentation] Invalid result format: ${JSON.stringify(result)}`);
12897
- return;
14356
+ sql = "";
14357
+ logger.debug(`[MysqlInstrumentation] Unknown query signature:`, args);
12898
14358
  }
12899
- SpanUtils.addSpanAttributes(spanInfo.span, { outputValue });
14359
+ return {
14360
+ sql,
14361
+ values,
14362
+ callback,
14363
+ options
14364
+ };
14365
+ }
14366
+ /**
14367
+ * Handle record mode for stream operations
14368
+ */
14369
+ _handleRecordStream(spanInfo, originalStream, queryInstance, streamOptions) {
14370
+ const streamInstance = originalStream.apply(queryInstance, [streamOptions]);
14371
+ const results = [];
14372
+ const fields = [];
14373
+ let error = null;
14374
+ let errQueryIndex;
14375
+ queryInstance.on("error", (err) => {
14376
+ error = err;
14377
+ errQueryIndex = queryInstance._index;
14378
+ }).on("fields", (fieldPackets, index) => {
14379
+ fields[index] = fieldPackets;
14380
+ }).on("result", (row, index) => {
14381
+ if (isMysqlOkPacket(row)) {
14382
+ results[index] = row;
14383
+ return;
14384
+ }
14385
+ if (!results[index]) results[index] = [];
14386
+ if (Array.isArray(results[index])) results[index].push(row);
14387
+ }).on("end", () => {
14388
+ const queryCount = this._getQueryCount(queryInstance);
14389
+ const isMultiStatementQuery = queryCount > 1;
14390
+ if (error) try {
14391
+ SpanUtils.endSpan(spanInfo.span, {
14392
+ code: import_src$23.SpanStatusCode.ERROR,
14393
+ message: error.message
14394
+ });
14395
+ } catch (err) {
14396
+ logger.error(`[MysqlInstrumentation] error ending span:`, err);
14397
+ }
14398
+ else try {
14399
+ const outputValue = isMultiStatementQuery ? {
14400
+ results,
14401
+ fields,
14402
+ queryCount,
14403
+ errQueryIndex
14404
+ } : {
14405
+ results: results[0],
14406
+ fields: fields[0],
14407
+ queryCount
14408
+ };
14409
+ SpanUtils.addSpanAttributes(spanInfo.span, { outputValue });
14410
+ SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
14411
+ } catch (err) {
14412
+ logger.error(`[MysqlInstrumentation] error ending span:`, err);
14413
+ }
14414
+ logger.debug(`[MysqlInstrumentation] Stream query completed`);
14415
+ });
14416
+ return streamInstance;
14417
+ }
14418
+ /**
14419
+ * Create a replay stream for query.stream() calls
14420
+ * This is called when user calls query.stream() on a query object
14421
+ */
14422
+ _createReplayStreamForQuery(inputValue, spanInfo, stackTrace, queryEmitter, streamOptions) {
14423
+ logger.debug(`[MysqlInstrumentation] Creating replay stream for query.stream()`);
14424
+ const readableStream = new Readable({
14425
+ objectMode: true,
14426
+ read() {}
14427
+ });
14428
+ queryEmitter.on("fields", (fields, index) => {
14429
+ logger.debug(`[MysqlInstrumentation] Stream received fields`);
14430
+ });
14431
+ queryEmitter.on("result", (row, index) => {
14432
+ readableStream.push(row);
14433
+ });
14434
+ queryEmitter.on("error", (err) => {
14435
+ readableStream.destroy(err);
14436
+ });
14437
+ queryEmitter.on("end", () => {
14438
+ readableStream.push(null);
14439
+ });
14440
+ return readableStream;
14441
+ }
14442
+ /**
14443
+ * Handle replay mode for stream operations
14444
+ */
14445
+ _handleReplayStream(inputValue, spanInfo, stackTrace, queryInstance) {
14446
+ logger.debug(`[MysqlInstrumentation] Replaying MySQL stream query`);
14447
+ const emitter = this.queryMock.handleReplayQuery({
14448
+ sql: inputValue.sql,
14449
+ values: inputValue.values,
14450
+ callback: void 0,
14451
+ options: inputValue.options
14452
+ }, inputValue, spanInfo, stackTrace);
14453
+ const readableStream = new Readable({
14454
+ objectMode: true,
14455
+ read() {}
14456
+ });
14457
+ emitter.on("fields", (fields, index) => {
14458
+ queryInstance.emit("fields", fields, index);
14459
+ });
14460
+ emitter.on("result", (row, index) => {
14461
+ readableStream.push(row);
14462
+ queryInstance.emit("result", row, index);
14463
+ });
14464
+ emitter.on("error", (err) => {
14465
+ readableStream.destroy(err);
14466
+ queryInstance.emit("error", err);
14467
+ });
14468
+ emitter.on("end", () => {
14469
+ readableStream.push(null);
14470
+ queryInstance.emit("end");
14471
+ });
14472
+ return readableStream;
12900
14473
  }
12901
14474
  _wrap(target, propertyName, wrapper) {
12902
14475
  wrap(target, propertyName, wrapper);
@@ -13764,7 +15337,7 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
13764
15337
  };
13765
15338
  };
13766
15339
  }
13767
- _handleSimpleCallbackMethod(spanInfo, originalMethod, callback, context$4) {
15340
+ _handleSimpleCallbackMethod(spanInfo, originalMethod, callback, context$6) {
13768
15341
  if (callback) {
13769
15342
  const wrappedCallback = (error) => {
13770
15343
  if (error) {
@@ -13788,9 +15361,9 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
13788
15361
  }
13789
15362
  return callback(error);
13790
15363
  };
13791
- return originalMethod.call(context$4, wrappedCallback);
15364
+ return originalMethod.call(context$6, wrappedCallback);
13792
15365
  } else {
13793
- const result = originalMethod.call(context$4);
15366
+ const result = originalMethod.call(context$6);
13794
15367
  if (result && typeof result.then === "function") return result.then(() => {
13795
15368
  logger.debug(`[Mysql2Instrumentation] MySQL2 method completed successfully (${SpanUtils.getTraceInfo()})`);
13796
15369
  try {
@@ -13842,7 +15415,7 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
13842
15415
  };
13843
15416
  return null;
13844
15417
  }
13845
- _handleRecordQueryInSpan(spanInfo, originalQuery, queryConfig, args, context$4) {
15418
+ _handleRecordQueryInSpan(spanInfo, originalQuery, queryConfig, args, context$6) {
13846
15419
  if (!!queryConfig.callback) {
13847
15420
  const originalCallback = queryConfig.callback;
13848
15421
  const wrappedCallback = (error, results, fields) => {
@@ -13880,9 +15453,9 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
13880
15453
  } catch (error) {
13881
15454
  logger.error(`[Mysql2Instrumentation] error replacing callback:`, error, args);
13882
15455
  }
13883
- return originalQuery.apply(context$4, args);
15456
+ return originalQuery.apply(context$6, args);
13884
15457
  } else {
13885
- const result = originalQuery.apply(context$4, args);
15458
+ const result = originalQuery.apply(context$6, args);
13886
15459
  if (result && typeof result.on === "function") {
13887
15460
  const streamResults = [];
13888
15461
  let streamFields = null;
@@ -13919,7 +15492,7 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
13919
15492
  handleNoOpReplayQuery(queryConfig) {
13920
15493
  return this.queryMock.handleNoOpReplayQuery(queryConfig);
13921
15494
  }
13922
- _handleRecordPoolGetConnectionInSpan(spanInfo, originalGetConnection, callback, context$4) {
15495
+ _handleRecordPoolGetConnectionInSpan(spanInfo, originalGetConnection, callback, context$6) {
13923
15496
  if (callback) {
13924
15497
  const wrappedCallback = (error, connection) => {
13925
15498
  if (error) {
@@ -13946,8 +15519,8 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
13946
15519
  }
13947
15520
  return callback(error, connection);
13948
15521
  };
13949
- return originalGetConnection.call(context$4, wrappedCallback);
13950
- } else return originalGetConnection.call(context$4).then((connection) => {
15522
+ return originalGetConnection.call(context$6, wrappedCallback);
15523
+ } else return originalGetConnection.call(context$6).then((connection) => {
13951
15524
  logger.debug(`[Mysql2Instrumentation] MySQL2 Pool getConnection completed successfully (${SpanUtils.getTraceInfo()})`);
13952
15525
  try {
13953
15526
  SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: {
@@ -14427,7 +16000,7 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
14427
16000
  else if (args.length >= 4 && typeof args[2] === "object") config.options = args[2];
14428
16001
  return config;
14429
16002
  }
14430
- _handleRecordVerifyInSpan(spanInfo, originalVerify, verifyConfig, args, context$4) {
16003
+ _handleRecordVerifyInSpan(spanInfo, originalVerify, verifyConfig, args, context$6) {
14431
16004
  if (!!verifyConfig.callback) {
14432
16005
  const originalCallback = verifyConfig.callback;
14433
16006
  const wrappedCallback = (error, decoded) => {
@@ -14456,7 +16029,7 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
14456
16029
  logger.error(`[JsonwebtokenInstrumentation] error replacing callback:`, error, args);
14457
16030
  }
14458
16031
  try {
14459
- return originalVerify.apply(context$4, args);
16032
+ return originalVerify.apply(context$6, args);
14460
16033
  } catch (error) {
14461
16034
  try {
14462
16035
  logger.debug(`[JsonwebtokenInstrumentation] JWT verify sync error: ${error.message} (${SpanUtils.getTraceInfo()})`);
@@ -14471,7 +16044,7 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
14471
16044
  throw error;
14472
16045
  }
14473
16046
  } else try {
14474
- const result = originalVerify.apply(context$4, args);
16047
+ const result = originalVerify.apply(context$6, args);
14475
16048
  try {
14476
16049
  logger.debug(`[JsonwebtokenInstrumentation] JWT verify completed successfully (${SpanUtils.getTraceInfo()})`);
14477
16050
  this._addOutputAttributesToSpan(spanInfo, result);
@@ -14494,7 +16067,7 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
14494
16067
  throw error;
14495
16068
  }
14496
16069
  }
14497
- _handleRecordSignInSpan(spanInfo, originalSign, signConfig, args, context$4) {
16070
+ _handleRecordSignInSpan(spanInfo, originalSign, signConfig, args, context$6) {
14498
16071
  if (!!signConfig.callback) {
14499
16072
  const originalCallback = signConfig.callback;
14500
16073
  const wrappedCallback = (error, token) => {
@@ -14522,9 +16095,9 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
14522
16095
  } catch (error) {
14523
16096
  logger.error(`[JsonwebtokenInstrumentation] error replacing callback:`, error, args);
14524
16097
  }
14525
- return originalSign.apply(context$4, args);
16098
+ return originalSign.apply(context$6, args);
14526
16099
  } else try {
14527
- const result = originalSign.apply(context$4, args);
16100
+ const result = originalSign.apply(context$6, args);
14528
16101
  try {
14529
16102
  logger.debug(`[JsonwebtokenInstrumentation] JWT sign completed successfully (${SpanUtils.getTraceInfo()})`);
14530
16103
  this._addOutputAttributesToSpan(spanInfo, result);
@@ -16579,7 +18152,7 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
16579
18152
  options
16580
18153
  };
16581
18154
  }
16582
- _handleRecordUnaryRequest(spanInfo, original, context$4, parsedParams, callback) {
18155
+ _handleRecordUnaryRequest(spanInfo, original, context$6, parsedParams, callback) {
16583
18156
  let isResponseReceived = false;
16584
18157
  let isStatusEmitted = false;
16585
18158
  let hasErrorOccurred = false;
@@ -16650,7 +18223,7 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
16650
18223
  parsedParams.options,
16651
18224
  patchedCallback
16652
18225
  ];
16653
- const result = original.apply(context$4, inputArgs);
18226
+ const result = original.apply(context$6, inputArgs);
16654
18227
  result.on("metadata", (initialMetadata) => {
16655
18228
  responseMetadataInitial = serializeGrpcMetadata(initialMetadata);
16656
18229
  });
@@ -16744,7 +18317,7 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
16744
18317
  });
16745
18318
  return emitter;
16746
18319
  }
16747
- _handleRecordServerStreamRequest(spanInfo, original, context$4, parsedParams) {
18320
+ _handleRecordServerStreamRequest(spanInfo, original, context$6, parsedParams) {
16748
18321
  let hasErrorOccurred = false;
16749
18322
  let isSpanCompleted = false;
16750
18323
  let streamResponses = [];
@@ -16772,7 +18345,7 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
16772
18345
  parsedParams.metadata,
16773
18346
  parsedParams.options
16774
18347
  ];
16775
- const stream = original.apply(context$4, inputArgs);
18348
+ const stream = original.apply(context$6, inputArgs);
16776
18349
  stream.on("data", (data) => {
16777
18350
  try {
16778
18351
  const { readableBody, bufferMap, jsonableStringMap } = serializeGrpcPayload(data);
@@ -17261,8 +18834,8 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
17261
18834
  };
17262
18835
  };
17263
18836
  }
17264
- async _handleRecordDocumentGet(spanInfo, originalGet, context$4) {
17265
- const snapshot = await originalGet.call(context$4);
18837
+ async _handleRecordDocumentGet(spanInfo, originalGet, context$6) {
18838
+ const snapshot = await originalGet.call(context$6);
17266
18839
  const documentResult = {
17267
18840
  id: snapshot.id,
17268
18841
  path: snapshot.ref.path,
@@ -17540,8 +19113,8 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
17540
19113
  };
17541
19114
  };
17542
19115
  }
17543
- async _handleRecordDocumentWrite(spanInfo, originalWrite, context$4, ...args) {
17544
- const writeResult = await originalWrite.apply(context$4, args);
19116
+ async _handleRecordDocumentWrite(spanInfo, originalWrite, context$6, ...args) {
19117
+ const writeResult = await originalWrite.apply(context$6, args);
17545
19118
  const result = { writeTime: writeResult.writeTime ? {
17546
19119
  seconds: writeResult.writeTime.seconds,
17547
19120
  nanoseconds: writeResult.writeTime.nanoseconds
@@ -17633,8 +19206,8 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
17633
19206
  };
17634
19207
  };
17635
19208
  }
17636
- async _handleRecordCollectionAdd(spanInfo, originalAdd, context$4, data) {
17637
- const docRef = await originalAdd.call(context$4, data);
19209
+ async _handleRecordCollectionAdd(spanInfo, originalAdd, context$6, data) {
19210
+ const docRef = await originalAdd.call(context$6, data);
17638
19211
  const result = {
17639
19212
  id: docRef.id,
17640
19213
  path: docRef.path
@@ -17815,8 +19388,8 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
17815
19388
  };
17816
19389
  };
17817
19390
  }
17818
- async _handleRecordQueryGet(spanInfo, originalGet, context$4) {
17819
- const querySnapshot = await originalGet.call(context$4);
19391
+ async _handleRecordQueryGet(spanInfo, originalGet, context$6) {
19392
+ const querySnapshot = await originalGet.call(context$6);
17820
19393
  const queryResult = {
17821
19394
  docs: querySnapshot.docs.map((doc) => ({
17822
19395
  id: doc.id,
@@ -18521,16 +20094,16 @@ var require_suppress_tracing = /* @__PURE__ */ __commonJS({ "node_modules/@opent
18521
20094
  Object.defineProperty(exports, "__esModule", { value: true });
18522
20095
  exports.isTracingSuppressed = exports.unsuppressTracing = exports.suppressTracing = void 0;
18523
20096
  const SUPPRESS_TRACING_KEY = (0, require_src$7().createContextKey)("OpenTelemetry SDK Context Key SUPPRESS_TRACING");
18524
- function suppressTracing(context$4) {
18525
- return context$4.setValue(SUPPRESS_TRACING_KEY, true);
20097
+ function suppressTracing(context$6) {
20098
+ return context$6.setValue(SUPPRESS_TRACING_KEY, true);
18526
20099
  }
18527
20100
  exports.suppressTracing = suppressTracing;
18528
- function unsuppressTracing(context$4) {
18529
- return context$4.deleteValue(SUPPRESS_TRACING_KEY);
20101
+ function unsuppressTracing(context$6) {
20102
+ return context$6.deleteValue(SUPPRESS_TRACING_KEY);
18530
20103
  }
18531
20104
  exports.unsuppressTracing = unsuppressTracing;
18532
- function isTracingSuppressed(context$4) {
18533
- return context$4.getValue(SUPPRESS_TRACING_KEY) === true;
20105
+ function isTracingSuppressed(context$6) {
20106
+ return context$6.getValue(SUPPRESS_TRACING_KEY) === true;
18534
20107
  }
18535
20108
  exports.isTracingSuppressed = isTracingSuppressed;
18536
20109
  }) });
@@ -18621,21 +20194,21 @@ var require_W3CBaggagePropagator = /* @__PURE__ */ __commonJS({ "node_modules/@o
18621
20194
  * https://w3c.github.io/baggage/
18622
20195
  */
18623
20196
  var W3CBaggagePropagator = class {
18624
- inject(context$4, carrier, setter) {
18625
- const baggage = api_1$33.propagation.getBaggage(context$4);
18626
- if (!baggage || (0, suppress_tracing_1$3.isTracingSuppressed)(context$4)) return;
20197
+ inject(context$6, carrier, setter) {
20198
+ const baggage = api_1$33.propagation.getBaggage(context$6);
20199
+ if (!baggage || (0, suppress_tracing_1$3.isTracingSuppressed)(context$6)) return;
18627
20200
  const keyPairs = (0, utils_1$4.getKeyPairs)(baggage).filter((pair) => {
18628
20201
  return pair.length <= constants_1$4.BAGGAGE_MAX_PER_NAME_VALUE_PAIRS;
18629
20202
  }).slice(0, constants_1$4.BAGGAGE_MAX_NAME_VALUE_PAIRS);
18630
20203
  const headerValue = (0, utils_1$4.serializeKeyPairs)(keyPairs);
18631
20204
  if (headerValue.length > 0) setter.set(carrier, constants_1$4.BAGGAGE_HEADER, headerValue);
18632
20205
  }
18633
- extract(context$4, carrier, getter) {
20206
+ extract(context$6, carrier, getter) {
18634
20207
  const headerValue = getter.get(carrier, constants_1$4.BAGGAGE_HEADER);
18635
20208
  const baggageString = Array.isArray(headerValue) ? headerValue.join(constants_1$4.BAGGAGE_ITEMS_SEPARATOR) : headerValue;
18636
- if (!baggageString) return context$4;
20209
+ if (!baggageString) return context$6;
18637
20210
  const baggage = {};
18638
- if (baggageString.length === 0) return context$4;
20211
+ if (baggageString.length === 0) return context$6;
18639
20212
  baggageString.split(constants_1$4.BAGGAGE_ITEMS_SEPARATOR).forEach((entry) => {
18640
20213
  const keyPair = (0, utils_1$4.parsePairKeyValue)(entry);
18641
20214
  if (keyPair) {
@@ -18644,8 +20217,8 @@ var require_W3CBaggagePropagator = /* @__PURE__ */ __commonJS({ "node_modules/@o
18644
20217
  baggage[keyPair.key] = baggageEntry;
18645
20218
  }
18646
20219
  });
18647
- if (Object.entries(baggage).length === 0) return context$4;
18648
- return api_1$33.propagation.setBaggage(context$4, api_1$33.propagation.createBaggage(baggage));
20220
+ if (Object.entries(baggage).length === 0) return context$6;
20221
+ return api_1$33.propagation.setBaggage(context$6, api_1$33.propagation.createBaggage(baggage));
18649
20222
  }
18650
20223
  fields() {
18651
20224
  return [constants_1$4.BAGGAGE_HEADER];
@@ -21465,9 +23038,9 @@ var require_composite = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetr
21465
23038
  * @param context Context to inject
21466
23039
  * @param carrier Carrier into which context will be injected
21467
23040
  */
21468
- inject(context$4, carrier, setter) {
23041
+ inject(context$6, carrier, setter) {
21469
23042
  for (const propagator of this._propagators) try {
21470
- propagator.inject(context$4, carrier, setter);
23043
+ propagator.inject(context$6, carrier, setter);
21471
23044
  } catch (err) {
21472
23045
  api_1$29.diag.warn(`Failed to inject with ${propagator.constructor.name}. Err: ${err.message}`);
21473
23046
  }
@@ -21481,7 +23054,7 @@ var require_composite = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetr
21481
23054
  * @param context Context to add values to
21482
23055
  * @param carrier Carrier from which to extract context
21483
23056
  */
21484
- extract(context$4, carrier, getter) {
23057
+ extract(context$6, carrier, getter) {
21485
23058
  return this._propagators.reduce((ctx, propagator) => {
21486
23059
  try {
21487
23060
  return propagator.extract(ctx, carrier, getter);
@@ -21489,7 +23062,7 @@ var require_composite = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetr
21489
23062
  api_1$29.diag.warn(`Failed to extract with ${propagator.constructor.name}. Err: ${err.message}`);
21490
23063
  }
21491
23064
  return ctx;
21492
- }, context$4);
23065
+ }, context$6);
21493
23066
  }
21494
23067
  fields() {
21495
23068
  return this._fields.slice();
@@ -21641,27 +23214,27 @@ var require_W3CTraceContextPropagator = /* @__PURE__ */ __commonJS({ "node_modul
21641
23214
  * https://www.w3.org/TR/trace-context/
21642
23215
  */
21643
23216
  var W3CTraceContextPropagator = class {
21644
- inject(context$4, carrier, setter) {
21645
- const spanContext = api_1$28.trace.getSpanContext(context$4);
21646
- if (!spanContext || (0, suppress_tracing_1$2.isTracingSuppressed)(context$4) || !(0, api_1$28.isSpanContextValid)(spanContext)) return;
23217
+ inject(context$6, carrier, setter) {
23218
+ const spanContext = api_1$28.trace.getSpanContext(context$6);
23219
+ if (!spanContext || (0, suppress_tracing_1$2.isTracingSuppressed)(context$6) || !(0, api_1$28.isSpanContextValid)(spanContext)) return;
21647
23220
  const traceParent = `${VERSION}-${spanContext.traceId}-${spanContext.spanId}-0${Number(spanContext.traceFlags || api_1$28.TraceFlags.NONE).toString(16)}`;
21648
23221
  setter.set(carrier, exports.TRACE_PARENT_HEADER, traceParent);
21649
23222
  if (spanContext.traceState) setter.set(carrier, exports.TRACE_STATE_HEADER, spanContext.traceState.serialize());
21650
23223
  }
21651
- extract(context$4, carrier, getter) {
23224
+ extract(context$6, carrier, getter) {
21652
23225
  const traceParentHeader = getter.get(carrier, exports.TRACE_PARENT_HEADER);
21653
- if (!traceParentHeader) return context$4;
23226
+ if (!traceParentHeader) return context$6;
21654
23227
  const traceParent = Array.isArray(traceParentHeader) ? traceParentHeader[0] : traceParentHeader;
21655
- if (typeof traceParent !== "string") return context$4;
23228
+ if (typeof traceParent !== "string") return context$6;
21656
23229
  const spanContext = parseTraceParent(traceParent);
21657
- if (!spanContext) return context$4;
23230
+ if (!spanContext) return context$6;
21658
23231
  spanContext.isRemote = true;
21659
23232
  const traceStateHeader = getter.get(carrier, exports.TRACE_STATE_HEADER);
21660
23233
  if (traceStateHeader) {
21661
23234
  const state = Array.isArray(traceStateHeader) ? traceStateHeader.join(",") : traceStateHeader;
21662
23235
  spanContext.traceState = new TraceState_1$1.TraceState(typeof state === "string" ? state : void 0);
21663
23236
  }
21664
- return api_1$28.trace.setSpanContext(context$4, spanContext);
23237
+ return api_1$28.trace.setSpanContext(context$6, spanContext);
21665
23238
  }
21666
23239
  fields() {
21667
23240
  return [exports.TRACE_PARENT_HEADER, exports.TRACE_STATE_HEADER];
@@ -21679,16 +23252,16 @@ var require_rpc_metadata = /* @__PURE__ */ __commonJS({ "node_modules/@opentelem
21679
23252
  (function(RPCType) {
21680
23253
  RPCType["HTTP"] = "http";
21681
23254
  })(exports.RPCType || (exports.RPCType = {}));
21682
- function setRPCMetadata(context$4, meta) {
21683
- return context$4.setValue(RPC_METADATA_KEY, meta);
23255
+ function setRPCMetadata(context$6, meta) {
23256
+ return context$6.setValue(RPC_METADATA_KEY, meta);
21684
23257
  }
21685
23258
  exports.setRPCMetadata = setRPCMetadata;
21686
- function deleteRPCMetadata(context$4) {
21687
- return context$4.deleteValue(RPC_METADATA_KEY);
23259
+ function deleteRPCMetadata(context$6) {
23260
+ return context$6.deleteValue(RPC_METADATA_KEY);
21688
23261
  }
21689
23262
  exports.deleteRPCMetadata = deleteRPCMetadata;
21690
- function getRPCMetadata(context$4) {
21691
- return context$4.getValue(RPC_METADATA_KEY);
23263
+ function getRPCMetadata(context$6) {
23264
+ return context$6.getValue(RPC_METADATA_KEY);
21692
23265
  }
21693
23266
  exports.getRPCMetadata = getRPCMetadata;
21694
23267
  }) });
@@ -21762,15 +23335,15 @@ var require_ParentBasedSampler$1 = /* @__PURE__ */ __commonJS({ "node_modules/@o
21762
23335
  this._localParentSampled = (_c = config.localParentSampled) !== null && _c !== void 0 ? _c : new AlwaysOnSampler_1$4.AlwaysOnSampler();
21763
23336
  this._localParentNotSampled = (_d = config.localParentNotSampled) !== null && _d !== void 0 ? _d : new AlwaysOffSampler_1$4.AlwaysOffSampler();
21764
23337
  }
21765
- shouldSample(context$4, traceId, spanName, spanKind, attributes, links) {
21766
- const parentContext = api_1$25.trace.getSpanContext(context$4);
21767
- if (!parentContext || !(0, api_1$25.isSpanContextValid)(parentContext)) return this._root.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
23338
+ shouldSample(context$6, traceId, spanName, spanKind, attributes, links) {
23339
+ const parentContext = api_1$25.trace.getSpanContext(context$6);
23340
+ if (!parentContext || !(0, api_1$25.isSpanContextValid)(parentContext)) return this._root.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
21768
23341
  if (parentContext.isRemote) {
21769
- if (parentContext.traceFlags & api_1$25.TraceFlags.SAMPLED) return this._remoteParentSampled.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
21770
- return this._remoteParentNotSampled.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
23342
+ if (parentContext.traceFlags & api_1$25.TraceFlags.SAMPLED) return this._remoteParentSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
23343
+ return this._remoteParentNotSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
21771
23344
  }
21772
- if (parentContext.traceFlags & api_1$25.TraceFlags.SAMPLED) return this._localParentSampled.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
21773
- return this._localParentNotSampled.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
23345
+ if (parentContext.traceFlags & api_1$25.TraceFlags.SAMPLED) return this._localParentSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
23346
+ return this._localParentNotSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
21774
23347
  }
21775
23348
  toString() {
21776
23349
  return `ParentBased{root=${this._root.toString()}, remoteParentSampled=${this._remoteParentSampled.toString()}, remoteParentNotSampled=${this._remoteParentNotSampled.toString()}, localParentSampled=${this._localParentSampled.toString()}, localParentNotSampled=${this._localParentNotSampled.toString()}}`;
@@ -21795,7 +23368,7 @@ var require_TraceIdRatioBasedSampler$1 = /* @__PURE__ */ __commonJS({ "node_modu
21795
23368
  this._ratio = this._normalize(_ratio);
21796
23369
  this._upperBound = Math.floor(this._ratio * 4294967295);
21797
23370
  }
21798
- shouldSample(context$4, traceId) {
23371
+ shouldSample(context$6, traceId) {
21799
23372
  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 };
21800
23373
  }
21801
23374
  toString() {
@@ -23381,15 +24954,15 @@ var require_AbstractAsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "nod
23381
24954
  * @param target a function or event emitter. When target or one of its callbacks is called,
23382
24955
  * the provided context will be used as the active context for the duration of the call.
23383
24956
  */
23384
- bind(context$4, target) {
23385
- if (target instanceof events_1.EventEmitter) return this._bindEventEmitter(context$4, target);
23386
- if (typeof target === "function") return this._bindFunction(context$4, target);
24957
+ bind(context$6, target) {
24958
+ if (target instanceof events_1.EventEmitter) return this._bindEventEmitter(context$6, target);
24959
+ if (typeof target === "function") return this._bindFunction(context$6, target);
23387
24960
  return target;
23388
24961
  }
23389
- _bindFunction(context$4, target) {
24962
+ _bindFunction(context$6, target) {
23390
24963
  const manager = this;
23391
24964
  const contextWrapper = function(...args) {
23392
- return manager.with(context$4, () => target.apply(this, args));
24965
+ return manager.with(context$6, () => target.apply(this, args));
23393
24966
  };
23394
24967
  Object.defineProperty(contextWrapper, "length", {
23395
24968
  enumerable: false,
@@ -23410,12 +24983,12 @@ var require_AbstractAsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "nod
23410
24983
  * @param context the context we want to bind
23411
24984
  * @param ee EventEmitter an instance of EventEmitter to patch
23412
24985
  */
23413
- _bindEventEmitter(context$4, ee) {
24986
+ _bindEventEmitter(context$6, ee) {
23414
24987
  if (this._getPatchMap(ee) !== void 0) return ee;
23415
24988
  this._createPatchMap(ee);
23416
24989
  ADD_LISTENER_METHODS.forEach((methodName) => {
23417
24990
  if (ee[methodName] === void 0) return;
23418
- ee[methodName] = this._patchAddListener(ee, ee[methodName], context$4);
24991
+ ee[methodName] = this._patchAddListener(ee, ee[methodName], context$6);
23419
24992
  });
23420
24993
  if (typeof ee.removeListener === "function") ee.removeListener = this._patchRemoveListener(ee, ee.removeListener);
23421
24994
  if (typeof ee.off === "function") ee.off = this._patchRemoveListener(ee, ee.off);
@@ -23462,7 +25035,7 @@ var require_AbstractAsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "nod
23462
25035
  * @param original reference to the patched method
23463
25036
  * @param [context] context to propagate when calling listeners
23464
25037
  */
23465
- _patchAddListener(ee, original, context$4) {
25038
+ _patchAddListener(ee, original, context$6) {
23466
25039
  const contextManager = this;
23467
25040
  return function(event, listener) {
23468
25041
  /**
@@ -23481,7 +25054,7 @@ var require_AbstractAsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "nod
23481
25054
  listeners = /* @__PURE__ */ new WeakMap();
23482
25055
  map[event] = listeners;
23483
25056
  }
23484
- const patchedListener = contextManager.bind(context$4, listener);
25057
+ const patchedListener = contextManager.bind(context$6, listener);
23485
25058
  listeners.set(listener, patchedListener);
23486
25059
  /**
23487
25060
  * See comment at the start of this function for the explanation of this property.
@@ -23531,8 +25104,8 @@ var require_AsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "node_module
23531
25104
  var _a;
23532
25105
  return (_a = this._stack[this._stack.length - 1]) !== null && _a !== void 0 ? _a : api_1$22.ROOT_CONTEXT;
23533
25106
  }
23534
- with(context$4, fn, thisArg, ...args) {
23535
- this._enterContext(context$4);
25107
+ with(context$6, fn, thisArg, ...args) {
25108
+ this._enterContext(context$6);
23536
25109
  try {
23537
25110
  return fn.call(thisArg, ...args);
23538
25111
  } finally {
@@ -23557,8 +25130,8 @@ var require_AsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "node_module
23557
25130
  */
23558
25131
  _init(uid, type) {
23559
25132
  if (type === "TIMERWRAP") return;
23560
- const context$4 = this._stack[this._stack.length - 1];
23561
- if (context$4 !== void 0) this._contexts.set(uid, context$4);
25133
+ const context$6 = this._stack[this._stack.length - 1];
25134
+ if (context$6 !== void 0) this._contexts.set(uid, context$6);
23562
25135
  }
23563
25136
  /**
23564
25137
  * Destroy hook will be called when a given context is no longer used so we can
@@ -23573,8 +25146,8 @@ var require_AsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "node_module
23573
25146
  * @param uid uid of the async context
23574
25147
  */
23575
25148
  _before(uid) {
23576
- const context$4 = this._contexts.get(uid);
23577
- if (context$4 !== void 0) this._enterContext(context$4);
25149
+ const context$6 = this._contexts.get(uid);
25150
+ if (context$6 !== void 0) this._enterContext(context$6);
23578
25151
  }
23579
25152
  /**
23580
25153
  * After hook is called just after completing the execution of a async context.
@@ -23585,8 +25158,8 @@ var require_AsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "node_module
23585
25158
  /**
23586
25159
  * Set the given context as active
23587
25160
  */
23588
- _enterContext(context$4) {
23589
- this._stack.push(context$4);
25161
+ _enterContext(context$6) {
25162
+ this._stack.push(context$6);
23590
25163
  }
23591
25164
  /**
23592
25165
  * Remove the context at the root of the stack
@@ -23615,9 +25188,9 @@ var require_AsyncLocalStorageContextManager = /* @__PURE__ */ __commonJS({ "node
23615
25188
  var _a;
23616
25189
  return (_a = this._asyncLocalStorage.getStore()) !== null && _a !== void 0 ? _a : api_1$21.ROOT_CONTEXT;
23617
25190
  }
23618
- with(context$4, fn, thisArg, ...args) {
25191
+ with(context$6, fn, thisArg, ...args) {
23619
25192
  const cb = thisArg == null ? fn : fn.bind(thisArg);
23620
- return this._asyncLocalStorage.run(context$4, cb, ...args);
25193
+ return this._asyncLocalStorage.run(context$6, cb, ...args);
23621
25194
  }
23622
25195
  enable() {
23623
25196
  return this;
@@ -23730,30 +25303,30 @@ var require_B3MultiPropagator = /* @__PURE__ */ __commonJS({ "node_modules/@open
23730
25303
  * Based on: https://github.com/openzipkin/b3-propagation
23731
25304
  */
23732
25305
  var B3MultiPropagator = class {
23733
- inject(context$4, carrier, setter) {
23734
- const spanContext = api_1$19.trace.getSpanContext(context$4);
23735
- if (!spanContext || !(0, api_1$19.isSpanContextValid)(spanContext) || (0, core_1$16.isTracingSuppressed)(context$4)) return;
23736
- const debug = context$4.getValue(common_1$1.B3_DEBUG_FLAG_KEY);
25306
+ inject(context$6, carrier, setter) {
25307
+ const spanContext = api_1$19.trace.getSpanContext(context$6);
25308
+ if (!spanContext || !(0, api_1$19.isSpanContextValid)(spanContext) || (0, core_1$16.isTracingSuppressed)(context$6)) return;
25309
+ const debug = context$6.getValue(common_1$1.B3_DEBUG_FLAG_KEY);
23737
25310
  setter.set(carrier, constants_1$3.X_B3_TRACE_ID, spanContext.traceId);
23738
25311
  setter.set(carrier, constants_1$3.X_B3_SPAN_ID, spanContext.spanId);
23739
25312
  if (debug === "1") setter.set(carrier, constants_1$3.X_B3_FLAGS, debug);
23740
25313
  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");
23741
25314
  }
23742
- extract(context$4, carrier, getter) {
25315
+ extract(context$6, carrier, getter) {
23743
25316
  const traceId = getTraceId(carrier, getter);
23744
25317
  const spanId = getSpanId(carrier, getter);
23745
25318
  const traceFlags = getTraceFlags(carrier, getter);
23746
25319
  const debug = getDebug(carrier, getter);
23747
25320
  if ((0, api_1$19.isValidTraceId)(traceId) && (0, api_1$19.isValidSpanId)(spanId) && isValidSampledValue(traceFlags)) {
23748
- context$4 = context$4.setValue(common_1$1.B3_DEBUG_FLAG_KEY, debug);
23749
- return api_1$19.trace.setSpanContext(context$4, {
25321
+ context$6 = context$6.setValue(common_1$1.B3_DEBUG_FLAG_KEY, debug);
25322
+ return api_1$19.trace.setSpanContext(context$6, {
23750
25323
  traceId,
23751
25324
  spanId,
23752
25325
  isRemote: true,
23753
25326
  traceFlags
23754
25327
  });
23755
25328
  }
23756
- return context$4;
25329
+ return context$6;
23757
25330
  }
23758
25331
  fields() {
23759
25332
  return [
@@ -23793,25 +25366,25 @@ var require_B3SinglePropagator = /* @__PURE__ */ __commonJS({ "node_modules/@ope
23793
25366
  * Based on: https://github.com/openzipkin/b3-propagation
23794
25367
  */
23795
25368
  var B3SinglePropagator = class {
23796
- inject(context$4, carrier, setter) {
23797
- const spanContext = api_1$18.trace.getSpanContext(context$4);
23798
- if (!spanContext || !(0, api_1$18.isSpanContextValid)(spanContext) || (0, core_1$15.isTracingSuppressed)(context$4)) return;
23799
- const samplingState = context$4.getValue(common_1.B3_DEBUG_FLAG_KEY) || spanContext.traceFlags & 1;
25369
+ inject(context$6, carrier, setter) {
25370
+ const spanContext = api_1$18.trace.getSpanContext(context$6);
25371
+ if (!spanContext || !(0, api_1$18.isSpanContextValid)(spanContext) || (0, core_1$15.isTracingSuppressed)(context$6)) return;
25372
+ const samplingState = context$6.getValue(common_1.B3_DEBUG_FLAG_KEY) || spanContext.traceFlags & 1;
23800
25373
  const value = `${spanContext.traceId}-${spanContext.spanId}-${samplingState}`;
23801
25374
  setter.set(carrier, constants_1$2.B3_CONTEXT_HEADER, value);
23802
25375
  }
23803
- extract(context$4, carrier, getter) {
25376
+ extract(context$6, carrier, getter) {
23804
25377
  const header = getter.get(carrier, constants_1$2.B3_CONTEXT_HEADER);
23805
25378
  const b3Context = Array.isArray(header) ? header[0] : header;
23806
- if (typeof b3Context !== "string") return context$4;
25379
+ if (typeof b3Context !== "string") return context$6;
23807
25380
  const match = b3Context.match(B3_CONTEXT_REGEX);
23808
- if (!match) return context$4;
25381
+ if (!match) return context$6;
23809
25382
  const [, extractedTraceId, spanId, samplingState] = match;
23810
25383
  const traceId = convertToTraceId128(extractedTraceId);
23811
- if (!(0, api_1$18.isValidTraceId)(traceId) || !(0, api_1$18.isValidSpanId)(spanId)) return context$4;
25384
+ if (!(0, api_1$18.isValidTraceId)(traceId) || !(0, api_1$18.isValidSpanId)(spanId)) return context$6;
23812
25385
  const traceFlags = convertToTraceFlags(samplingState);
23813
- if (samplingState === DEBUG_STATE) context$4 = context$4.setValue(common_1.B3_DEBUG_FLAG_KEY, samplingState);
23814
- return api_1$18.trace.setSpanContext(context$4, {
25386
+ if (samplingState === DEBUG_STATE) context$6 = context$6.setValue(common_1.B3_DEBUG_FLAG_KEY, samplingState);
25387
+ return api_1$18.trace.setSpanContext(context$6, {
23815
25388
  traceId,
23816
25389
  spanId,
23817
25390
  isRemote: true,
@@ -23865,14 +25438,14 @@ var require_B3Propagator = /* @__PURE__ */ __commonJS({ "node_modules/@opentelem
23865
25438
  this._fields = this._b3SinglePropagator.fields();
23866
25439
  }
23867
25440
  }
23868
- inject(context$4, carrier, setter) {
23869
- if ((0, core_1$14.isTracingSuppressed)(context$4)) return;
23870
- this._inject(context$4, carrier, setter);
25441
+ inject(context$6, carrier, setter) {
25442
+ if ((0, core_1$14.isTracingSuppressed)(context$6)) return;
25443
+ this._inject(context$6, carrier, setter);
23871
25444
  }
23872
- extract(context$4, carrier, getter) {
25445
+ extract(context$6, carrier, getter) {
23873
25446
  const header = getter.get(carrier, constants_1$1.B3_CONTEXT_HEADER);
23874
- if (Array.isArray(header) ? header[0] : header) return this._b3SinglePropagator.extract(context$4, carrier, getter);
23875
- else return this._b3MultiPropagator.extract(context$4, carrier, getter);
25447
+ if (Array.isArray(header) ? header[0] : header) return this._b3SinglePropagator.extract(context$6, carrier, getter);
25448
+ else return this._b3MultiPropagator.extract(context$6, carrier, getter);
23876
25449
  }
23877
25450
  fields() {
23878
25451
  return this._fields;
@@ -25934,7 +27507,7 @@ var require_Span = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/sdk
25934
27507
  *
25935
27508
  * @deprecated calling Span constructor directly is not supported. Please use tracer.startSpan.
25936
27509
  * */
25937
- constructor(parentTracer, context$4, spanName, spanContext, kind, parentSpanId, links = [], startTime, _deprecatedClock, attributes) {
27510
+ constructor(parentTracer, context$6, spanName, spanContext, kind, parentSpanId, links = [], startTime, _deprecatedClock, attributes) {
25938
27511
  this.attributes = {};
25939
27512
  this.links = [];
25940
27513
  this.events = [];
@@ -25961,7 +27534,7 @@ var require_Span = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/sdk
25961
27534
  this._attributeValueLengthLimit = this._spanLimits.attributeValueLengthLimit || 0;
25962
27535
  if (attributes != null) this.setAttributes(attributes);
25963
27536
  this._spanProcessor = parentTracer.getActiveSpanProcessor();
25964
- this._spanProcessor.onStart(this, context$4);
27537
+ this._spanProcessor.onStart(this, context$6);
25965
27538
  }
25966
27539
  spanContext() {
25967
27540
  return this._spanContext;
@@ -26216,15 +27789,15 @@ var require_ParentBasedSampler = /* @__PURE__ */ __commonJS({ "node_modules/@ope
26216
27789
  this._localParentSampled = (_c = config.localParentSampled) !== null && _c !== void 0 ? _c : new AlwaysOnSampler_1$2.AlwaysOnSampler();
26217
27790
  this._localParentNotSampled = (_d = config.localParentNotSampled) !== null && _d !== void 0 ? _d : new AlwaysOffSampler_1$2.AlwaysOffSampler();
26218
27791
  }
26219
- shouldSample(context$4, traceId, spanName, spanKind, attributes, links) {
26220
- const parentContext = api_1$16.trace.getSpanContext(context$4);
26221
- if (!parentContext || !(0, api_1$16.isSpanContextValid)(parentContext)) return this._root.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
27792
+ shouldSample(context$6, traceId, spanName, spanKind, attributes, links) {
27793
+ const parentContext = api_1$16.trace.getSpanContext(context$6);
27794
+ if (!parentContext || !(0, api_1$16.isSpanContextValid)(parentContext)) return this._root.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
26222
27795
  if (parentContext.isRemote) {
26223
- if (parentContext.traceFlags & api_1$16.TraceFlags.SAMPLED) return this._remoteParentSampled.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
26224
- return this._remoteParentNotSampled.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
27796
+ if (parentContext.traceFlags & api_1$16.TraceFlags.SAMPLED) return this._remoteParentSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
27797
+ return this._remoteParentNotSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
26225
27798
  }
26226
- if (parentContext.traceFlags & api_1$16.TraceFlags.SAMPLED) return this._localParentSampled.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
26227
- return this._localParentNotSampled.shouldSample(context$4, traceId, spanName, spanKind, attributes, links);
27799
+ if (parentContext.traceFlags & api_1$16.TraceFlags.SAMPLED) return this._localParentSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
27800
+ return this._localParentNotSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
26228
27801
  }
26229
27802
  toString() {
26230
27803
  return `ParentBased{root=${this._root.toString()}, remoteParentSampled=${this._remoteParentSampled.toString()}, remoteParentNotSampled=${this._remoteParentNotSampled.toString()}, localParentSampled=${this._localParentSampled.toString()}, localParentNotSampled=${this._localParentNotSampled.toString()}}`;
@@ -26247,7 +27820,7 @@ var require_TraceIdRatioBasedSampler = /* @__PURE__ */ __commonJS({ "node_module
26247
27820
  this._ratio = this._normalize(_ratio);
26248
27821
  this._upperBound = Math.floor(this._ratio * 4294967295);
26249
27822
  }
26250
- shouldSample(context$4, traceId) {
27823
+ shouldSample(context$6, traceId) {
26251
27824
  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 };
26252
27825
  }
26253
27826
  toString() {
@@ -26649,11 +28222,11 @@ var require_Tracer = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/s
26649
28222
  * Starts a new Span or returns the default NoopSpan based on the sampling
26650
28223
  * decision.
26651
28224
  */
26652
- startSpan(name, options = {}, context$4 = api.context.active()) {
28225
+ startSpan(name, options = {}, context$6 = api.context.active()) {
26653
28226
  var _a, _b, _c;
26654
- if (options.root) context$4 = api.trace.deleteSpan(context$4);
26655
- const parentSpan = api.trace.getSpan(context$4);
26656
- if ((0, core_1$8.isTracingSuppressed)(context$4)) {
28227
+ if (options.root) context$6 = api.trace.deleteSpan(context$6);
28228
+ const parentSpan = api.trace.getSpan(context$6);
28229
+ if ((0, core_1$8.isTracingSuppressed)(context$6)) {
26657
28230
  api.diag.debug("Instrumentation suppressed, returning Noop Span");
26658
28231
  return api.trace.wrapSpanContext(api.INVALID_SPAN_CONTEXT);
26659
28232
  }
@@ -26676,7 +28249,7 @@ var require_Tracer = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/s
26676
28249
  };
26677
28250
  });
26678
28251
  const attributes = (0, core_1$8.sanitizeAttributes)(options.attributes);
26679
- const samplingResult = this._sampler.shouldSample(context$4, traceId, name, spanKind, attributes, links);
28252
+ const samplingResult = this._sampler.shouldSample(context$6, traceId, name, spanKind, attributes, links);
26680
28253
  traceState = (_c = samplingResult.traceState) !== null && _c !== void 0 ? _c : traceState;
26681
28254
  const traceFlags = samplingResult.decision === api.SamplingDecision.RECORD_AND_SAMPLED ? api.TraceFlags.SAMPLED : api.TraceFlags.NONE;
26682
28255
  const spanContext = {
@@ -26690,7 +28263,7 @@ var require_Tracer = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/s
26690
28263
  return api.trace.wrapSpanContext(spanContext);
26691
28264
  }
26692
28265
  const initAttributes = (0, core_1$8.sanitizeAttributes)(Object.assign(attributes, samplingResult.attributes));
26693
- return new Span_1$1.Span(this, context$4, name, spanContext, spanKind, parentSpanId, links, options.startTime, void 0, initAttributes);
28266
+ return new Span_1$1.Span(this, context$6, name, spanContext, spanKind, parentSpanId, links, options.startTime, void 0, initAttributes);
26694
28267
  }
26695
28268
  startActiveSpan(name, arg2, arg3, arg4) {
26696
28269
  let opts;
@@ -29737,8 +31310,8 @@ var require_MultiSpanProcessor = /* @__PURE__ */ __commonJS({ "node_modules/@ope
29737
31310
  });
29738
31311
  });
29739
31312
  }
29740
- onStart(span, context$4) {
29741
- for (const spanProcessor of this._spanProcessors) spanProcessor.onStart(span, context$4);
31313
+ onStart(span, context$6) {
31314
+ for (const spanProcessor of this._spanProcessors) spanProcessor.onStart(span, context$6);
29742
31315
  }
29743
31316
  onEnd(span) {
29744
31317
  for (const spanProcessor of this._spanProcessors) spanProcessor.onEnd(span);
@@ -30244,16 +31817,16 @@ var require_JaegerPropagator = /* @__PURE__ */ __commonJS({ "node_modules/@opent
30244
31817
  this._jaegerBaggageHeaderPrefix = (config === null || config === void 0 ? void 0 : config.customBaggageHeaderPrefix) || exports.UBER_BAGGAGE_HEADER_PREFIX;
30245
31818
  }
30246
31819
  }
30247
- inject(context$4, carrier, setter) {
30248
- const spanContext = api_1.trace.getSpanContext(context$4);
30249
- const baggage = api_1.propagation.getBaggage(context$4);
30250
- if (spanContext && (0, core_1.isTracingSuppressed)(context$4) === false) {
31820
+ inject(context$6, carrier, setter) {
31821
+ const spanContext = api_1.trace.getSpanContext(context$6);
31822
+ const baggage = api_1.propagation.getBaggage(context$6);
31823
+ if (spanContext && (0, core_1.isTracingSuppressed)(context$6) === false) {
30251
31824
  const traceFlags = `0${(spanContext.traceFlags || api_1.TraceFlags.NONE).toString(16)}`;
30252
31825
  setter.set(carrier, this._jaegerTraceHeader, `${spanContext.traceId}:${spanContext.spanId}:0:${traceFlags}`);
30253
31826
  }
30254
31827
  if (baggage) for (const [key, entry] of baggage.getAllEntries()) setter.set(carrier, `${this._jaegerBaggageHeaderPrefix}-${key}`, encodeURIComponent(entry.value));
30255
31828
  }
30256
- extract(context$4, carrier, getter) {
31829
+ extract(context$6, carrier, getter) {
30257
31830
  var _a;
30258
31831
  const uberTraceIdHeader = getter.get(carrier, this._jaegerTraceHeader);
30259
31832
  const uberTraceId = Array.isArray(uberTraceIdHeader) ? uberTraceIdHeader[0] : uberTraceIdHeader;
@@ -30264,13 +31837,13 @@ var require_JaegerPropagator = /* @__PURE__ */ __commonJS({ "node_modules/@opent
30264
31837
  value: Array.isArray(value) ? value[0] : value
30265
31838
  };
30266
31839
  });
30267
- let newContext = context$4;
31840
+ let newContext = context$6;
30268
31841
  if (typeof uberTraceId === "string") {
30269
31842
  const spanContext = deserializeSpanContext(uberTraceId);
30270
31843
  if (spanContext) newContext = api_1.trace.setSpanContext(newContext, spanContext);
30271
31844
  }
30272
31845
  if (baggageValues.length === 0) return newContext;
30273
- let currentBaggage = (_a = api_1.propagation.getBaggage(context$4)) !== null && _a !== void 0 ? _a : api_1.propagation.createBaggage();
31846
+ let currentBaggage = (_a = api_1.propagation.getBaggage(context$6)) !== null && _a !== void 0 ? _a : api_1.propagation.createBaggage();
30274
31847
  for (const baggageEntry of baggageValues) {
30275
31848
  if (baggageEntry.value === void 0) continue;
30276
31849
  currentBaggage = currentBaggage.setEntry(baggageEntry.key, { value: decodeURIComponent(baggageEntry.value) });
@@ -30473,7 +32046,7 @@ var require_src = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/sdk-
30473
32046
  //#endregion
30474
32047
  //#region package.json
30475
32048
  var import_src$1 = /* @__PURE__ */ __toESM(require_src(), 1);
30476
- var version = "0.1.14";
32049
+ var version = "0.1.16";
30477
32050
 
30478
32051
  //#endregion
30479
32052
  //#region src/version.ts
@@ -32322,6 +33895,10 @@ var TuskDriftCore = class TuskDriftCore {
32322
33895
  enabled: true,
32323
33896
  mode: this.mode
32324
33897
  });
33898
+ new MysqlInstrumentation({
33899
+ enabled: true,
33900
+ mode: this.mode
33901
+ });
32325
33902
  }
32326
33903
  initializeTracing({ baseDirectory }) {
32327
33904
  const serviceName = this.config.service?.name || "unknown";