@use-tusk/drift-node-sdk 0.1.14 → 0.1.15
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/README.md +9 -1
- package/dist/index.cjs +2125 -590
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2124 -589
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -60,10 +60,10 @@ let crypto = require("crypto");
|
|
|
60
60
|
crypto = __toESM(crypto);
|
|
61
61
|
let jsonpath = require("jsonpath");
|
|
62
62
|
jsonpath = __toESM(jsonpath);
|
|
63
|
-
let net = require("net");
|
|
64
|
-
net = __toESM(net);
|
|
65
63
|
let stream = require("stream");
|
|
66
64
|
stream = __toESM(stream);
|
|
65
|
+
let net = require("net");
|
|
66
|
+
net = __toESM(net);
|
|
67
67
|
let child_process = require("child_process");
|
|
68
68
|
child_process = __toESM(child_process);
|
|
69
69
|
|
|
@@ -4351,14 +4351,14 @@ var require_context$1 = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetr
|
|
|
4351
4351
|
self._currentContext = parentContext ? new Map(parentContext) : /* @__PURE__ */ new Map();
|
|
4352
4352
|
self.getValue = (key) => self._currentContext.get(key);
|
|
4353
4353
|
self.setValue = (key, value) => {
|
|
4354
|
-
const context$
|
|
4355
|
-
context$
|
|
4356
|
-
return context$
|
|
4354
|
+
const context$6 = new BaseContext(self._currentContext);
|
|
4355
|
+
context$6._currentContext.set(key, value);
|
|
4356
|
+
return context$6;
|
|
4357
4357
|
};
|
|
4358
4358
|
self.deleteValue = (key) => {
|
|
4359
|
-
const context$
|
|
4360
|
-
context$
|
|
4361
|
-
return context$
|
|
4359
|
+
const context$6 = new BaseContext(self._currentContext);
|
|
4360
|
+
context$6._currentContext.delete(key);
|
|
4361
|
+
return context$6;
|
|
4362
4362
|
};
|
|
4363
4363
|
}
|
|
4364
4364
|
};
|
|
@@ -4614,8 +4614,8 @@ var require_context = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/
|
|
|
4614
4614
|
* @param thisArg optional receiver to be used for calling fn
|
|
4615
4615
|
* @param args optional arguments forwarded to fn
|
|
4616
4616
|
*/
|
|
4617
|
-
with(context$
|
|
4618
|
-
return this._getContextManager().with(context$
|
|
4617
|
+
with(context$6, fn, thisArg, ...args) {
|
|
4618
|
+
return this._getContextManager().with(context$6, fn, thisArg, ...args);
|
|
4619
4619
|
}
|
|
4620
4620
|
/**
|
|
4621
4621
|
* Bind a context to a target function or event emitter
|
|
@@ -4623,8 +4623,8 @@ var require_context = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/
|
|
|
4623
4623
|
* @param context context to bind to the event emitter or function. Defaults to the currently active context
|
|
4624
4624
|
* @param target function or event emitter to bind
|
|
4625
4625
|
*/
|
|
4626
|
-
bind(context$
|
|
4627
|
-
return this._getContextManager().bind(context$
|
|
4626
|
+
bind(context$6, target) {
|
|
4627
|
+
return this._getContextManager().bind(context$6, target);
|
|
4628
4628
|
}
|
|
4629
4629
|
_getContextManager() {
|
|
4630
4630
|
return (0, global_utils_1$3.getGlobal)(API_NAME$3) || NOOP_CONTEXT_MANAGER;
|
|
@@ -4725,8 +4725,8 @@ var require_context_utils = /* @__PURE__ */ __commonJS({ "node_modules/@opentele
|
|
|
4725
4725
|
*
|
|
4726
4726
|
* @param context context to get span from
|
|
4727
4727
|
*/
|
|
4728
|
-
function getSpan(context$
|
|
4729
|
-
return context$
|
|
4728
|
+
function getSpan(context$6) {
|
|
4729
|
+
return context$6.getValue(SPAN_KEY) || void 0;
|
|
4730
4730
|
}
|
|
4731
4731
|
exports.getSpan = getSpan;
|
|
4732
4732
|
/**
|
|
@@ -4742,8 +4742,8 @@ var require_context_utils = /* @__PURE__ */ __commonJS({ "node_modules/@opentele
|
|
|
4742
4742
|
* @param context context to use as parent
|
|
4743
4743
|
* @param span span to set active
|
|
4744
4744
|
*/
|
|
4745
|
-
function setSpan(context$
|
|
4746
|
-
return context$
|
|
4745
|
+
function setSpan(context$6, span) {
|
|
4746
|
+
return context$6.setValue(SPAN_KEY, span);
|
|
4747
4747
|
}
|
|
4748
4748
|
exports.setSpan = setSpan;
|
|
4749
4749
|
/**
|
|
@@ -4751,8 +4751,8 @@ var require_context_utils = /* @__PURE__ */ __commonJS({ "node_modules/@opentele
|
|
|
4751
4751
|
*
|
|
4752
4752
|
* @param context context to delete span from
|
|
4753
4753
|
*/
|
|
4754
|
-
function deleteSpan(context$
|
|
4755
|
-
return context$
|
|
4754
|
+
function deleteSpan(context$6) {
|
|
4755
|
+
return context$6.deleteValue(SPAN_KEY);
|
|
4756
4756
|
}
|
|
4757
4757
|
exports.deleteSpan = deleteSpan;
|
|
4758
4758
|
/**
|
|
@@ -4762,8 +4762,8 @@ var require_context_utils = /* @__PURE__ */ __commonJS({ "node_modules/@opentele
|
|
|
4762
4762
|
* @param context context to set active span on
|
|
4763
4763
|
* @param spanContext span context to be wrapped
|
|
4764
4764
|
*/
|
|
4765
|
-
function setSpanContext(context$
|
|
4766
|
-
return setSpan(context$
|
|
4765
|
+
function setSpanContext(context$6, spanContext) {
|
|
4766
|
+
return setSpan(context$6, new NonRecordingSpan_1$2.NonRecordingSpan(spanContext));
|
|
4767
4767
|
}
|
|
4768
4768
|
exports.setSpanContext = setSpanContext;
|
|
4769
4769
|
/**
|
|
@@ -4771,9 +4771,9 @@ var require_context_utils = /* @__PURE__ */ __commonJS({ "node_modules/@opentele
|
|
|
4771
4771
|
*
|
|
4772
4772
|
* @param context context to get values from
|
|
4773
4773
|
*/
|
|
4774
|
-
function getSpanContext(context$
|
|
4774
|
+
function getSpanContext(context$6) {
|
|
4775
4775
|
var _a;
|
|
4776
|
-
return (_a = getSpan(context$
|
|
4776
|
+
return (_a = getSpan(context$6)) === null || _a === void 0 ? void 0 : _a.spanContext();
|
|
4777
4777
|
}
|
|
4778
4778
|
exports.getSpanContext = getSpanContext;
|
|
4779
4779
|
}) });
|
|
@@ -4829,9 +4829,9 @@ var require_NoopTracer = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemet
|
|
|
4829
4829
|
* No-op implementations of {@link Tracer}.
|
|
4830
4830
|
*/
|
|
4831
4831
|
var NoopTracer = class {
|
|
4832
|
-
startSpan(name, options, context$
|
|
4832
|
+
startSpan(name, options, context$6 = contextApi.active()) {
|
|
4833
4833
|
if (Boolean(options === null || options === void 0 ? void 0 : options.root)) return new NonRecordingSpan_1.NonRecordingSpan();
|
|
4834
|
-
const parentFromContext = context$
|
|
4834
|
+
const parentFromContext = context$6 && (0, context_utils_1$1.getSpanContext)(context$6);
|
|
4835
4835
|
if (isSpanContext(parentFromContext) && (0, spancontext_utils_1$2.isSpanContextValid)(parentFromContext)) return new NonRecordingSpan_1.NonRecordingSpan(parentFromContext);
|
|
4836
4836
|
else return new NonRecordingSpan_1.NonRecordingSpan();
|
|
4837
4837
|
}
|
|
@@ -4877,8 +4877,8 @@ var require_ProxyTracer = /* @__PURE__ */ __commonJS({ "node_modules/@openteleme
|
|
|
4877
4877
|
this.version = version$1;
|
|
4878
4878
|
this.options = options;
|
|
4879
4879
|
}
|
|
4880
|
-
startSpan(name, options, context$
|
|
4881
|
-
return this._getTracer().startSpan(name, options, context$
|
|
4880
|
+
startSpan(name, options, context$6) {
|
|
4881
|
+
return this._getTracer().startSpan(name, options, context$6);
|
|
4882
4882
|
}
|
|
4883
4883
|
startActiveSpan(_name, _options, _context, _fn) {
|
|
4884
4884
|
const tracer = this._getTracer();
|
|
@@ -4989,31 +4989,31 @@ var require_SamplingResult = /* @__PURE__ */ __commonJS({ "node_modules/@opentel
|
|
|
4989
4989
|
var require_span_kind = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/api/build/src/trace/span_kind.js": ((exports) => {
|
|
4990
4990
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4991
4991
|
exports.SpanKind = void 0;
|
|
4992
|
-
(function(SpanKind$
|
|
4992
|
+
(function(SpanKind$24) {
|
|
4993
4993
|
/** Default value. Indicates that the span is used internally. */
|
|
4994
|
-
SpanKind$
|
|
4994
|
+
SpanKind$24[SpanKind$24["INTERNAL"] = 0] = "INTERNAL";
|
|
4995
4995
|
/**
|
|
4996
4996
|
* Indicates that the span covers server-side handling of an RPC or other
|
|
4997
4997
|
* remote request.
|
|
4998
4998
|
*/
|
|
4999
|
-
SpanKind$
|
|
4999
|
+
SpanKind$24[SpanKind$24["SERVER"] = 1] = "SERVER";
|
|
5000
5000
|
/**
|
|
5001
5001
|
* Indicates that the span covers the client-side wrapper around an RPC or
|
|
5002
5002
|
* other remote request.
|
|
5003
5003
|
*/
|
|
5004
|
-
SpanKind$
|
|
5004
|
+
SpanKind$24[SpanKind$24["CLIENT"] = 2] = "CLIENT";
|
|
5005
5005
|
/**
|
|
5006
5006
|
* Indicates that the span describes producer sending a message to a
|
|
5007
5007
|
* broker. Unlike client and server, there is no direct critical path latency
|
|
5008
5008
|
* relationship between producer and consumer spans.
|
|
5009
5009
|
*/
|
|
5010
|
-
SpanKind$
|
|
5010
|
+
SpanKind$24[SpanKind$24["PRODUCER"] = 3] = "PRODUCER";
|
|
5011
5011
|
/**
|
|
5012
5012
|
* Indicates that the span describes consumer receiving a message from a
|
|
5013
5013
|
* broker. Unlike client and server, there is no direct critical path latency
|
|
5014
5014
|
* relationship between producer and consumer spans.
|
|
5015
5015
|
*/
|
|
5016
|
-
SpanKind$
|
|
5016
|
+
SpanKind$24[SpanKind$24["CONSUMER"] = 4] = "CONSUMER";
|
|
5017
5017
|
})(exports.SpanKind || (exports.SpanKind = {}));
|
|
5018
5018
|
}) });
|
|
5019
5019
|
|
|
@@ -5022,20 +5022,20 @@ var require_span_kind = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetr
|
|
|
5022
5022
|
var require_status = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/api/build/src/trace/status.js": ((exports) => {
|
|
5023
5023
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5024
5024
|
exports.SpanStatusCode = void 0;
|
|
5025
|
-
(function(SpanStatusCode$
|
|
5025
|
+
(function(SpanStatusCode$13) {
|
|
5026
5026
|
/**
|
|
5027
5027
|
* The default status.
|
|
5028
5028
|
*/
|
|
5029
|
-
SpanStatusCode$
|
|
5029
|
+
SpanStatusCode$13[SpanStatusCode$13["UNSET"] = 0] = "UNSET";
|
|
5030
5030
|
/**
|
|
5031
5031
|
* The operation has been validated by an Application developer or
|
|
5032
5032
|
* Operator to have completed successfully.
|
|
5033
5033
|
*/
|
|
5034
|
-
SpanStatusCode$
|
|
5034
|
+
SpanStatusCode$13[SpanStatusCode$13["OK"] = 1] = "OK";
|
|
5035
5035
|
/**
|
|
5036
5036
|
* The operation contains an error.
|
|
5037
5037
|
*/
|
|
5038
|
-
SpanStatusCode$
|
|
5038
|
+
SpanStatusCode$13[SpanStatusCode$13["ERROR"] = 2] = "ERROR";
|
|
5039
5039
|
})(exports.SpanStatusCode || (exports.SpanStatusCode = {}));
|
|
5040
5040
|
}) });
|
|
5041
5041
|
|
|
@@ -5267,8 +5267,8 @@ var require_NoopTextMapPropagator = /* @__PURE__ */ __commonJS({ "node_modules/@
|
|
|
5267
5267
|
/** Noop inject function does nothing */
|
|
5268
5268
|
inject(_context, _carrier) {}
|
|
5269
5269
|
/** Noop extract function does nothing and returns the input context */
|
|
5270
|
-
extract(context$
|
|
5271
|
-
return context$
|
|
5270
|
+
extract(context$6, _carrier) {
|
|
5271
|
+
return context$6;
|
|
5272
5272
|
}
|
|
5273
5273
|
fields() {
|
|
5274
5274
|
return [];
|
|
@@ -5293,8 +5293,8 @@ var require_context_helpers = /* @__PURE__ */ __commonJS({ "node_modules/@opente
|
|
|
5293
5293
|
* @param {Context} Context that manage all context values
|
|
5294
5294
|
* @returns {Baggage} Extracted baggage from the context
|
|
5295
5295
|
*/
|
|
5296
|
-
function getBaggage(context$
|
|
5297
|
-
return context$
|
|
5296
|
+
function getBaggage(context$6) {
|
|
5297
|
+
return context$6.getValue(BAGGAGE_KEY) || void 0;
|
|
5298
5298
|
}
|
|
5299
5299
|
exports.getBaggage = getBaggage;
|
|
5300
5300
|
/**
|
|
@@ -5312,8 +5312,8 @@ var require_context_helpers = /* @__PURE__ */ __commonJS({ "node_modules/@opente
|
|
|
5312
5312
|
* @param {Context} Context that manage all context values
|
|
5313
5313
|
* @param {Baggage} baggage that will be set in the actual context
|
|
5314
5314
|
*/
|
|
5315
|
-
function setBaggage(context$
|
|
5316
|
-
return context$
|
|
5315
|
+
function setBaggage(context$6, baggage) {
|
|
5316
|
+
return context$6.setValue(BAGGAGE_KEY, baggage);
|
|
5317
5317
|
}
|
|
5318
5318
|
exports.setBaggage = setBaggage;
|
|
5319
5319
|
/**
|
|
@@ -5321,8 +5321,8 @@ var require_context_helpers = /* @__PURE__ */ __commonJS({ "node_modules/@opente
|
|
|
5321
5321
|
*
|
|
5322
5322
|
* @param {Context} Context that manage all context values
|
|
5323
5323
|
*/
|
|
5324
|
-
function deleteBaggage(context$
|
|
5325
|
-
return context$
|
|
5324
|
+
function deleteBaggage(context$6) {
|
|
5325
|
+
return context$6.deleteValue(BAGGAGE_KEY);
|
|
5326
5326
|
}
|
|
5327
5327
|
exports.deleteBaggage = deleteBaggage;
|
|
5328
5328
|
}) });
|
|
@@ -5372,8 +5372,8 @@ var require_propagation = /* @__PURE__ */ __commonJS({ "node_modules/@openteleme
|
|
|
5372
5372
|
* @param carrier carrier to inject context into
|
|
5373
5373
|
* @param setter Function used to set values on the carrier
|
|
5374
5374
|
*/
|
|
5375
|
-
inject(context$
|
|
5376
|
-
return this._getGlobalPropagator().inject(context$
|
|
5375
|
+
inject(context$6, carrier, setter = TextMapPropagator_1$1.defaultTextMapSetter) {
|
|
5376
|
+
return this._getGlobalPropagator().inject(context$6, carrier, setter);
|
|
5377
5377
|
}
|
|
5378
5378
|
/**
|
|
5379
5379
|
* Extract context from a carrier
|
|
@@ -5382,8 +5382,8 @@ var require_propagation = /* @__PURE__ */ __commonJS({ "node_modules/@openteleme
|
|
|
5382
5382
|
* @param carrier Carrier to extract context from
|
|
5383
5383
|
* @param getter Function used to extract keys from a carrier
|
|
5384
5384
|
*/
|
|
5385
|
-
extract(context$
|
|
5386
|
-
return this._getGlobalPropagator().extract(context$
|
|
5385
|
+
extract(context$6, carrier, getter = TextMapPropagator_1$1.defaultTextMapGetter) {
|
|
5386
|
+
return this._getGlobalPropagator().extract(context$6, carrier, getter);
|
|
5387
5387
|
}
|
|
5388
5388
|
/**
|
|
5389
5389
|
* Return a list of all fields which may be used by the propagator.
|
|
@@ -5684,7 +5684,7 @@ var require_src$7 = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/ap
|
|
|
5684
5684
|
|
|
5685
5685
|
//#endregion
|
|
5686
5686
|
//#region node_modules/@use-tusk/drift-schemas/dist/duration-B3fwb4jB.js
|
|
5687
|
-
var import_src$
|
|
5687
|
+
var import_src$34 = /* @__PURE__ */ __toESM(require_src$7(), 1);
|
|
5688
5688
|
var import_commonjs$9 = /* @__PURE__ */ __toESM(require_commonjs$2(), 1);
|
|
5689
5689
|
var Duration$Type = class extends import_commonjs$9.MessageType {
|
|
5690
5690
|
constructor() {
|
|
@@ -6997,11 +6997,11 @@ const Trace = new Trace$Type();
|
|
|
6997
6997
|
const toStruct = (obj) => obj ? objectToProtobufStruct(obj) : void 0;
|
|
6998
6998
|
const mapOtToPb = (k) => {
|
|
6999
6999
|
switch (k) {
|
|
7000
|
-
case import_src$
|
|
7001
|
-
case import_src$
|
|
7002
|
-
case import_src$
|
|
7003
|
-
case import_src$
|
|
7004
|
-
case import_src$
|
|
7000
|
+
case import_src$34.SpanKind.INTERNAL: return SpanKind.INTERNAL;
|
|
7001
|
+
case import_src$34.SpanKind.SERVER: return SpanKind.SERVER;
|
|
7002
|
+
case import_src$34.SpanKind.CLIENT: return SpanKind.CLIENT;
|
|
7003
|
+
case import_src$34.SpanKind.PRODUCER: return SpanKind.PRODUCER;
|
|
7004
|
+
case import_src$34.SpanKind.CONSUMER: return SpanKind.CONSUMER;
|
|
7005
7005
|
default: return SpanKind.UNSPECIFIED;
|
|
7006
7006
|
}
|
|
7007
7007
|
};
|
|
@@ -7405,13 +7405,13 @@ var TdInstrumentationNodeModule = class {
|
|
|
7405
7405
|
|
|
7406
7406
|
//#endregion
|
|
7407
7407
|
//#region src/core/types.ts
|
|
7408
|
-
var import_src$
|
|
7408
|
+
var import_src$33 = /* @__PURE__ */ __toESM(require_src$7(), 1);
|
|
7409
7409
|
const TD_INSTRUMENTATION_LIBRARY_NAME = "tusk-drift-sdk";
|
|
7410
|
-
const REPLAY_TRACE_ID_CONTEXT_KEY = (0, import_src$
|
|
7411
|
-
const SPAN_KIND_CONTEXT_KEY = (0, import_src$
|
|
7412
|
-
const IS_PRE_APP_START_CONTEXT_KEY = (0, import_src$
|
|
7413
|
-
const STOP_RECORDING_CHILD_SPANS_CONTEXT_KEY = (0, import_src$
|
|
7414
|
-
const CALLING_LIBRARY_CONTEXT_KEY = (0, import_src$
|
|
7410
|
+
const REPLAY_TRACE_ID_CONTEXT_KEY = (0, import_src$33.createContextKey)("td.replayTraceId");
|
|
7411
|
+
const SPAN_KIND_CONTEXT_KEY = (0, import_src$33.createContextKey)("td.spanKind");
|
|
7412
|
+
const IS_PRE_APP_START_CONTEXT_KEY = (0, import_src$33.createContextKey)("td.isPreAppStart");
|
|
7413
|
+
const STOP_RECORDING_CHILD_SPANS_CONTEXT_KEY = (0, import_src$33.createContextKey)("td.stopRecordingChildSpans");
|
|
7414
|
+
const CALLING_LIBRARY_CONTEXT_KEY = (0, import_src$33.createContextKey)("td.callingLibrary");
|
|
7415
7415
|
let TdSpanAttributes = /* @__PURE__ */ function(TdSpanAttributes$1) {
|
|
7416
7416
|
/**
|
|
7417
7417
|
* Presentational information:
|
|
@@ -7523,7 +7523,7 @@ TraceBlockingManager.instance = null;
|
|
|
7523
7523
|
|
|
7524
7524
|
//#endregion
|
|
7525
7525
|
//#region src/core/tracing/SpanUtils.ts
|
|
7526
|
-
var import_src$
|
|
7526
|
+
var import_src$32 = /* @__PURE__ */ __toESM(require_src$7(), 1);
|
|
7527
7527
|
var SpanUtils = class SpanUtils {
|
|
7528
7528
|
/**
|
|
7529
7529
|
* Creates a new span and returns span info including trace ID and span ID
|
|
@@ -7531,8 +7531,8 @@ var SpanUtils = class SpanUtils {
|
|
|
7531
7531
|
static createSpan(options) {
|
|
7532
7532
|
try {
|
|
7533
7533
|
const tracer = TuskDriftCore.getInstance().getTracer();
|
|
7534
|
-
const parentContext = options.parentContext || import_src$
|
|
7535
|
-
const activeSpan = import_src$
|
|
7534
|
+
const parentContext = options.parentContext || import_src$32.context.active();
|
|
7535
|
+
const activeSpan = import_src$32.trace.getSpan(parentContext);
|
|
7536
7536
|
if (activeSpan) {
|
|
7537
7537
|
const parentTraceId = activeSpan.spanContext().traceId;
|
|
7538
7538
|
if (TraceBlockingManager.getInstance().isTraceBlocked(parentTraceId)) {
|
|
@@ -7541,11 +7541,11 @@ var SpanUtils = class SpanUtils {
|
|
|
7541
7541
|
}
|
|
7542
7542
|
}
|
|
7543
7543
|
const span = tracer.startSpan(options.name, {
|
|
7544
|
-
kind: options.kind || import_src$
|
|
7544
|
+
kind: options.kind || import_src$32.SpanKind.CLIENT,
|
|
7545
7545
|
attributes: options.attributes || {}
|
|
7546
7546
|
}, parentContext);
|
|
7547
7547
|
const spanContext = span.spanContext();
|
|
7548
|
-
const newContext = import_src$
|
|
7548
|
+
const newContext = import_src$32.trace.setSpan(parentContext, span).setValue(SPAN_KIND_CONTEXT_KEY, options.kind).setValue(IS_PRE_APP_START_CONTEXT_KEY, options.isPreAppStart);
|
|
7549
7549
|
return {
|
|
7550
7550
|
traceId: spanContext.traceId,
|
|
7551
7551
|
spanId: spanContext.spanId,
|
|
@@ -7562,7 +7562,7 @@ var SpanUtils = class SpanUtils {
|
|
|
7562
7562
|
* Executes a function within a span context
|
|
7563
7563
|
*/
|
|
7564
7564
|
static withSpan(spanInfo, fn) {
|
|
7565
|
-
return import_src$
|
|
7565
|
+
return import_src$32.context.with(spanInfo.context, fn);
|
|
7566
7566
|
}
|
|
7567
7567
|
/**
|
|
7568
7568
|
* Execute a function within a properly configured span
|
|
@@ -7579,9 +7579,9 @@ var SpanUtils = class SpanUtils {
|
|
|
7579
7579
|
* @returns The result of the function execution
|
|
7580
7580
|
*/
|
|
7581
7581
|
static createAndExecuteSpan(mode, originalFunctionCall, options, fn) {
|
|
7582
|
-
const spanContext = import_src$
|
|
7582
|
+
const spanContext = import_src$32.trace.getActiveSpan()?.spanContext();
|
|
7583
7583
|
if (spanContext) {
|
|
7584
|
-
if (import_src$
|
|
7584
|
+
if (import_src$32.context.active().getValue(STOP_RECORDING_CHILD_SPANS_CONTEXT_KEY)) {
|
|
7585
7585
|
logger.debug(`[SpanUtils] Stopping recording of child spans for span ${spanContext.spanId}, packageName: ${options.packageName}, instrumentationName: ${options.instrumentationName}`);
|
|
7586
7586
|
return originalFunctionCall();
|
|
7587
7587
|
}
|
|
@@ -7619,15 +7619,15 @@ var SpanUtils = class SpanUtils {
|
|
|
7619
7619
|
*/
|
|
7620
7620
|
static getCurrentSpanInfo() {
|
|
7621
7621
|
try {
|
|
7622
|
-
const activeSpan = import_src$
|
|
7622
|
+
const activeSpan = import_src$32.trace.getActiveSpan();
|
|
7623
7623
|
if (!activeSpan) return null;
|
|
7624
7624
|
const spanContext = activeSpan.spanContext();
|
|
7625
7625
|
return {
|
|
7626
7626
|
traceId: spanContext.traceId,
|
|
7627
7627
|
spanId: spanContext.spanId,
|
|
7628
7628
|
span: activeSpan,
|
|
7629
|
-
context: import_src$
|
|
7630
|
-
isPreAppStart: import_src$
|
|
7629
|
+
context: import_src$32.context.active(),
|
|
7630
|
+
isPreAppStart: import_src$32.context.active().getValue(IS_PRE_APP_START_CONTEXT_KEY)
|
|
7631
7631
|
};
|
|
7632
7632
|
} catch (error) {
|
|
7633
7633
|
logger.error("SpanUtils error getting current span info:", error);
|
|
@@ -7691,7 +7691,7 @@ var SpanUtils = class SpanUtils {
|
|
|
7691
7691
|
}
|
|
7692
7692
|
static setCurrentReplayTraceId(replayTraceId) {
|
|
7693
7693
|
try {
|
|
7694
|
-
return import_src$
|
|
7694
|
+
return import_src$32.context.active().setValue(REPLAY_TRACE_ID_CONTEXT_KEY, replayTraceId);
|
|
7695
7695
|
} catch (error) {
|
|
7696
7696
|
logger.error("SpanUtils error setting current replay trace id:", error);
|
|
7697
7697
|
return null;
|
|
@@ -7702,7 +7702,7 @@ var SpanUtils = class SpanUtils {
|
|
|
7702
7702
|
*/
|
|
7703
7703
|
static getCurrentReplayTraceId() {
|
|
7704
7704
|
try {
|
|
7705
|
-
return import_src$
|
|
7705
|
+
return import_src$32.context.active().getValue(REPLAY_TRACE_ID_CONTEXT_KEY);
|
|
7706
7706
|
} catch (error) {
|
|
7707
7707
|
logger.error("SpanUtils error getting current replay trace id:", error);
|
|
7708
7708
|
return null;
|
|
@@ -8364,7 +8364,7 @@ function findMockResponseSync({ mockRequestData, tuskDrift, inputValueSchemaMerg
|
|
|
8364
8364
|
|
|
8365
8365
|
//#endregion
|
|
8366
8366
|
//#region src/instrumentation/libraries/http/mocks/TdMockClientRequest.ts
|
|
8367
|
-
var import_src$
|
|
8367
|
+
var import_src$31 = /* @__PURE__ */ __toESM(require_src$7(), 1);
|
|
8368
8368
|
let ClientRequest;
|
|
8369
8369
|
/**
|
|
8370
8370
|
* Mock ClientRequest implementation for Tusk Drift HTTP replay
|
|
@@ -8535,7 +8535,7 @@ var TdMockClientRequest = class TdMockClientRequest extends events.EventEmitter
|
|
|
8535
8535
|
instrumentationName: this.INSTRUMENTATION_NAME,
|
|
8536
8536
|
submoduleName: rawInputValue.method,
|
|
8537
8537
|
inputValue,
|
|
8538
|
-
kind: import_src$
|
|
8538
|
+
kind: import_src$31.SpanKind.CLIENT,
|
|
8539
8539
|
stackTrace: this.stackTrace
|
|
8540
8540
|
},
|
|
8541
8541
|
tuskDrift: this.tuskDrift,
|
|
@@ -8712,7 +8712,7 @@ var HttpReplayHooks = class {
|
|
|
8712
8712
|
|
|
8713
8713
|
//#endregion
|
|
8714
8714
|
//#region src/instrumentation/core/utils/modeUtils.ts
|
|
8715
|
-
var import_src$
|
|
8715
|
+
var import_src$30 = /* @__PURE__ */ __toESM(require_src$7(), 1);
|
|
8716
8716
|
/**
|
|
8717
8717
|
* Utility function that abstracts the common record mode pattern of checking for current span context
|
|
8718
8718
|
* and deciding whether to execute record mode logic or just call the original function.
|
|
@@ -8733,7 +8733,7 @@ function handleRecordMode({ originalFunctionCall, recordModeHandler, spanKind })
|
|
|
8733
8733
|
return originalFunctionCall();
|
|
8734
8734
|
}
|
|
8735
8735
|
if (!isAppReady) return recordModeHandler({ isPreAppStart: true });
|
|
8736
|
-
if (!currentSpanInfo && spanKind !== import_src$
|
|
8736
|
+
if (!currentSpanInfo && spanKind !== import_src$30.SpanKind.SERVER || currentSpanInfo?.isPreAppStart) return originalFunctionCall();
|
|
8737
8737
|
else return recordModeHandler({ isPreAppStart: false });
|
|
8738
8738
|
}
|
|
8739
8739
|
/**
|
|
@@ -10213,7 +10213,7 @@ function captureStackTrace(excludeClassNames = []) {
|
|
|
10213
10213
|
|
|
10214
10214
|
//#endregion
|
|
10215
10215
|
//#region src/instrumentation/libraries/http/HttpTransformEngine.ts
|
|
10216
|
-
var import_src$
|
|
10216
|
+
var import_src$29 = /* @__PURE__ */ __toESM(require_src$7(), 1);
|
|
10217
10217
|
/**
|
|
10218
10218
|
* Creates an empty HttpClientInputValue object for dropped spans
|
|
10219
10219
|
*/
|
|
@@ -10266,7 +10266,7 @@ var HttpTransformEngine = class {
|
|
|
10266
10266
|
const testSpan = {
|
|
10267
10267
|
traceId: "",
|
|
10268
10268
|
spanId: "",
|
|
10269
|
-
kind: import_src$
|
|
10269
|
+
kind: import_src$29.SpanKind.SERVER,
|
|
10270
10270
|
protocol: "http",
|
|
10271
10271
|
inputValue: {
|
|
10272
10272
|
method,
|
|
@@ -10289,7 +10289,7 @@ var HttpTransformEngine = class {
|
|
|
10289
10289
|
const testSpan = {
|
|
10290
10290
|
traceId: "",
|
|
10291
10291
|
spanId: "",
|
|
10292
|
-
kind: import_src$
|
|
10292
|
+
kind: import_src$29.SpanKind.CLIENT,
|
|
10293
10293
|
protocol: inputValue.protocol || "http",
|
|
10294
10294
|
inputValue: clonedInputValue
|
|
10295
10295
|
};
|
|
@@ -10316,8 +10316,8 @@ var HttpTransformEngine = class {
|
|
|
10316
10316
|
const matcherFunction = this.compileMatcher(matcher);
|
|
10317
10317
|
if (action.type === "drop") return (span) => {
|
|
10318
10318
|
if (!matcherFunction(span)) return;
|
|
10319
|
-
if (span.inputValue) span.inputValue = span.kind === import_src$
|
|
10320
|
-
if (span.outputValue) span.outputValue = span.kind === import_src$
|
|
10319
|
+
if (span.inputValue) span.inputValue = span.kind === import_src$29.SpanKind.CLIENT ? createEmptyClientInputValue(span.protocol) : createEmptyServerInputValue();
|
|
10320
|
+
if (span.outputValue) span.outputValue = span.kind === import_src$29.SpanKind.CLIENT ? createEmptyClientOutputValue() : createEmptyServerOutputValue();
|
|
10321
10321
|
return {
|
|
10322
10322
|
type: "drop",
|
|
10323
10323
|
field: "entire_span",
|
|
@@ -10347,8 +10347,8 @@ var HttpTransformEngine = class {
|
|
|
10347
10347
|
}
|
|
10348
10348
|
compileMatcher(matcher) {
|
|
10349
10349
|
const checks = [];
|
|
10350
|
-
if (matcher.direction === "outbound") checks.push((span) => span.kind === import_src$
|
|
10351
|
-
else if (matcher.direction === "inbound") checks.push((span) => span.kind === import_src$
|
|
10350
|
+
if (matcher.direction === "outbound") checks.push((span) => span.kind === import_src$29.SpanKind.CLIENT);
|
|
10351
|
+
else if (matcher.direction === "inbound") checks.push((span) => span.kind === import_src$29.SpanKind.SERVER);
|
|
10352
10352
|
if (matcher.method) if (matcher.method.length === 0) {} else {
|
|
10353
10353
|
const methods = matcher.method.map((method) => method.toUpperCase());
|
|
10354
10354
|
checks.push((span) => {
|
|
@@ -10576,7 +10576,7 @@ var HttpTransformEngine = class {
|
|
|
10576
10576
|
|
|
10577
10577
|
//#endregion
|
|
10578
10578
|
//#region src/instrumentation/libraries/http/Instrumentation.ts
|
|
10579
|
-
var import_src$
|
|
10579
|
+
var import_src$28 = /* @__PURE__ */ __toESM(require_src$7(), 1);
|
|
10580
10580
|
var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
10581
10581
|
constructor(config) {
|
|
10582
10582
|
super("http", config);
|
|
@@ -10670,10 +10670,10 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
|
10670
10670
|
}
|
|
10671
10671
|
const ctxWithReplayTraceId = SpanUtils.setCurrentReplayTraceId(replayTraceId);
|
|
10672
10672
|
if (!ctxWithReplayTraceId) throw new Error("Error setting current replay trace id");
|
|
10673
|
-
return import_src$
|
|
10673
|
+
return import_src$28.context.with(ctxWithReplayTraceId, () => {
|
|
10674
10674
|
return SpanUtils.createAndExecuteSpan(this.mode, () => originalHandler.call(this), {
|
|
10675
10675
|
name: `${target}`,
|
|
10676
|
-
kind: import_src$
|
|
10676
|
+
kind: import_src$28.SpanKind.SERVER,
|
|
10677
10677
|
packageName: spanProtocol,
|
|
10678
10678
|
submodule: method,
|
|
10679
10679
|
packageType: PackageType.HTTP,
|
|
@@ -10718,7 +10718,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
|
10718
10718
|
logger.debug(`[HttpInstrumentation] Http inbound request arriving, inputValue: ${JSON.stringify(inputValue)}`);
|
|
10719
10719
|
return SpanUtils.createAndExecuteSpan(this.mode, () => originalHandler.call(this), {
|
|
10720
10720
|
name: `${target}`,
|
|
10721
|
-
kind: import_src$
|
|
10721
|
+
kind: import_src$28.SpanKind.SERVER,
|
|
10722
10722
|
packageName: spanProtocol,
|
|
10723
10723
|
packageType: PackageType.HTTP,
|
|
10724
10724
|
submodule: method,
|
|
@@ -10738,7 +10738,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
|
10738
10738
|
});
|
|
10739
10739
|
});
|
|
10740
10740
|
},
|
|
10741
|
-
spanKind: import_src$
|
|
10741
|
+
spanKind: import_src$28.SpanKind.SERVER
|
|
10742
10742
|
});
|
|
10743
10743
|
} else return originalHandler.call(this);
|
|
10744
10744
|
}
|
|
@@ -10755,8 +10755,8 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
|
10755
10755
|
_handleInboundRequestInSpan({ req, res, originalHandler, spanInfo, inputValue, schemaMerges, protocol }) {
|
|
10756
10756
|
const self = this;
|
|
10757
10757
|
const spanProtocol = this._normalizeProtocol(protocol, "http");
|
|
10758
|
-
import_src$
|
|
10759
|
-
import_src$
|
|
10758
|
+
import_src$28.context.bind(spanInfo.context, req);
|
|
10759
|
+
import_src$28.context.bind(spanInfo.context, res);
|
|
10760
10760
|
let completeInputValue = inputValue;
|
|
10761
10761
|
this._captureServerRequestBody(req, spanInfo, inputValue, schemaMerges, (updatedInputValue) => {
|
|
10762
10762
|
completeInputValue = updatedInputValue;
|
|
@@ -10794,7 +10794,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
|
10794
10794
|
const spanData = {
|
|
10795
10795
|
traceId: spanInfo.traceId,
|
|
10796
10796
|
spanId: spanInfo.spanId,
|
|
10797
|
-
kind: import_src$
|
|
10797
|
+
kind: import_src$28.SpanKind.SERVER,
|
|
10798
10798
|
protocol: spanProtocol,
|
|
10799
10799
|
inputValue: completeInputValue,
|
|
10800
10800
|
outputValue
|
|
@@ -10815,9 +10815,9 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
|
10815
10815
|
});
|
|
10816
10816
|
EnvVarTracker.clearEnvVars(spanInfo.traceId);
|
|
10817
10817
|
const status = statusCode >= 400 ? {
|
|
10818
|
-
code: import_src$
|
|
10818
|
+
code: import_src$28.SpanStatusCode.ERROR,
|
|
10819
10819
|
message: `HTTP ${statusCode}`
|
|
10820
|
-
} : { code: import_src$
|
|
10820
|
+
} : { code: import_src$28.SpanStatusCode.OK };
|
|
10821
10821
|
SpanUtils.setStatus(spanInfo.span, status);
|
|
10822
10822
|
const decodedType = getDecodedType(outputValue.headers?.["content-type"] || "");
|
|
10823
10823
|
if (decodedType && !ACCEPTABLE_CONTENT_TYPES.has(decodedType)) {
|
|
@@ -10866,7 +10866,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
|
10866
10866
|
outputSchemaHash: JsonSchemaHelper.generateDeterministicHash(outputSchema),
|
|
10867
10867
|
inputValueHash,
|
|
10868
10868
|
outputValueHash,
|
|
10869
|
-
kind: import_src$
|
|
10869
|
+
kind: import_src$28.SpanKind.SERVER,
|
|
10870
10870
|
packageType: PackageType.HTTP,
|
|
10871
10871
|
status: {
|
|
10872
10872
|
code: statusCode >= 400 ? StatusCode.ERROR : StatusCode.OK,
|
|
@@ -10895,7 +10895,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
|
10895
10895
|
try {
|
|
10896
10896
|
logger.debug(`[HttpInstrumentation] Server request error: ${error.message} (${SpanUtils.getTraceInfo()})`);
|
|
10897
10897
|
SpanUtils.endSpan(spanInfo.span, {
|
|
10898
|
-
code: import_src$
|
|
10898
|
+
code: import_src$28.SpanStatusCode.ERROR,
|
|
10899
10899
|
message: error.message
|
|
10900
10900
|
});
|
|
10901
10901
|
} catch (error$1) {
|
|
@@ -10906,7 +10906,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
|
10906
10906
|
try {
|
|
10907
10907
|
logger.debug(`[HttpInstrumentation] Server response error: ${error.message} (${SpanUtils.getTraceInfo()})`);
|
|
10908
10908
|
SpanUtils.endSpan(spanInfo.span, {
|
|
10909
|
-
code: import_src$
|
|
10909
|
+
code: import_src$28.SpanStatusCode.ERROR,
|
|
10910
10910
|
message: error.message
|
|
10911
10911
|
});
|
|
10912
10912
|
} catch (error$1) {
|
|
@@ -11111,7 +11111,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
|
11111
11111
|
inputValue: completeInputValue
|
|
11112
11112
|
});
|
|
11113
11113
|
SpanUtils.endSpan(spanInfo.span, {
|
|
11114
|
-
code: import_src$
|
|
11114
|
+
code: import_src$28.SpanStatusCode.ERROR,
|
|
11115
11115
|
message: error.message
|
|
11116
11116
|
});
|
|
11117
11117
|
} catch (error$1) {
|
|
@@ -11128,7 +11128,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
|
11128
11128
|
const spanData = {
|
|
11129
11129
|
traceId: spanInfo.traceId,
|
|
11130
11130
|
spanId: spanInfo.spanId,
|
|
11131
|
-
kind: import_src$
|
|
11131
|
+
kind: import_src$28.SpanKind.CLIENT,
|
|
11132
11132
|
protocol: normalizedProtocol,
|
|
11133
11133
|
inputValue,
|
|
11134
11134
|
outputValue
|
|
@@ -11141,9 +11141,9 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
|
11141
11141
|
transformMetadata: spanData.transformMetadata ? spanData.transformMetadata : void 0
|
|
11142
11142
|
});
|
|
11143
11143
|
const status = statusCode >= 400 ? {
|
|
11144
|
-
code: import_src$
|
|
11144
|
+
code: import_src$28.SpanStatusCode.ERROR,
|
|
11145
11145
|
message: `HTTP ${statusCode}`
|
|
11146
|
-
} : { code: import_src$
|
|
11146
|
+
} : { code: import_src$28.SpanStatusCode.OK };
|
|
11147
11147
|
SpanUtils.endSpan(spanInfo.span, status);
|
|
11148
11148
|
}
|
|
11149
11149
|
_captureHeadersFromRawHeaders(rawHeaders) {
|
|
@@ -11197,7 +11197,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
|
11197
11197
|
};
|
|
11198
11198
|
return SpanUtils.createAndExecuteSpan(self.mode, () => originalRequest.apply(this, args), {
|
|
11199
11199
|
name: requestOptions.path || `${requestProtocol.toUpperCase()} ${method}`,
|
|
11200
|
-
kind: import_src$
|
|
11200
|
+
kind: import_src$28.SpanKind.CLIENT,
|
|
11201
11201
|
packageName: requestProtocol,
|
|
11202
11202
|
packageType: PackageType.HTTP,
|
|
11203
11203
|
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
@@ -11232,7 +11232,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
|
11232
11232
|
};
|
|
11233
11233
|
return SpanUtils.createAndExecuteSpan(self.mode, () => originalRequest.apply(this, args), {
|
|
11234
11234
|
name: requestOptions.path || `${requestProtocol.toUpperCase()} ${method}`,
|
|
11235
|
-
kind: import_src$
|
|
11235
|
+
kind: import_src$28.SpanKind.CLIENT,
|
|
11236
11236
|
packageName: requestProtocol,
|
|
11237
11237
|
packageType: PackageType.HTTP,
|
|
11238
11238
|
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
@@ -11244,7 +11244,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
|
11244
11244
|
return self._handleOutboundRequestInSpan(originalRequest, args, spanInfo, inputValue, { headers: { matchImportance: 0 } });
|
|
11245
11245
|
});
|
|
11246
11246
|
},
|
|
11247
|
-
spanKind: import_src$
|
|
11247
|
+
spanKind: import_src$28.SpanKind.CLIENT
|
|
11248
11248
|
});
|
|
11249
11249
|
else return originalRequest.apply(this, args);
|
|
11250
11250
|
};
|
|
@@ -11290,7 +11290,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
|
11290
11290
|
};
|
|
11291
11291
|
return SpanUtils.createAndExecuteSpan(self.mode, () => originalGet.apply(this, args), {
|
|
11292
11292
|
name: requestOptions.path || `${requestProtocol.toUpperCase()} ${method}`,
|
|
11293
|
-
kind: import_src$
|
|
11293
|
+
kind: import_src$28.SpanKind.CLIENT,
|
|
11294
11294
|
packageName: requestProtocol,
|
|
11295
11295
|
packageType: PackageType.HTTP,
|
|
11296
11296
|
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
@@ -11324,7 +11324,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
|
11324
11324
|
};
|
|
11325
11325
|
return SpanUtils.createAndExecuteSpan(self.mode, () => originalGet.apply(this, args), {
|
|
11326
11326
|
name: requestOptions.path || `${requestProtocol.toUpperCase()} ${method}`,
|
|
11327
|
-
kind: import_src$
|
|
11327
|
+
kind: import_src$28.SpanKind.CLIENT,
|
|
11328
11328
|
packageName: requestProtocol,
|
|
11329
11329
|
packageType: PackageType.HTTP,
|
|
11330
11330
|
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
@@ -11336,7 +11336,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
|
|
|
11336
11336
|
return self._handleOutboundRequestInSpan(originalGet, args, spanInfo, inputValue, { headers: { matchImportance: 0 } });
|
|
11337
11337
|
});
|
|
11338
11338
|
},
|
|
11339
|
-
spanKind: import_src$
|
|
11339
|
+
spanKind: import_src$28.SpanKind.CLIENT
|
|
11340
11340
|
});
|
|
11341
11341
|
else return originalGet.apply(this, args);
|
|
11342
11342
|
};
|
|
@@ -11471,7 +11471,7 @@ var EnvInstrumentation = class extends TdInstrumentationBase {
|
|
|
11471
11471
|
|
|
11472
11472
|
//#endregion
|
|
11473
11473
|
//#region src/instrumentation/libraries/date/Instrumentation.ts
|
|
11474
|
-
var import_src$
|
|
11474
|
+
var import_src$27 = /* @__PURE__ */ __toESM(require_src$7(), 1);
|
|
11475
11475
|
/**
|
|
11476
11476
|
* Date instrumentation that provides consistent dates in replay mode.
|
|
11477
11477
|
* In replay mode, new Date() calls return the latest mock response timestamp.
|
|
@@ -11510,7 +11510,7 @@ var DateInstrumentation = class DateInstrumentation extends TdInstrumentationBas
|
|
|
11510
11510
|
if (this.mode !== TuskDriftMode.REPLAY) return this._callOriginalDate(args, isConstructorCall);
|
|
11511
11511
|
const currentSpanInfo = SpanUtils.getCurrentSpanInfo();
|
|
11512
11512
|
if (!currentSpanInfo) return this._callOriginalDate(args, isConstructorCall);
|
|
11513
|
-
if (currentSpanInfo.context.getValue(SPAN_KIND_CONTEXT_KEY) !== import_src$
|
|
11513
|
+
if (currentSpanInfo.context.getValue(SPAN_KIND_CONTEXT_KEY) !== import_src$27.SpanKind.SERVER) return this._callOriginalDate(args, isConstructorCall);
|
|
11514
11514
|
this.isInPatchedCall = true;
|
|
11515
11515
|
try {
|
|
11516
11516
|
return this._handleReplayDate(args, isConstructorCall);
|
|
@@ -11630,10 +11630,10 @@ var GraphqlInstrumentation = class extends TdInstrumentationBase {
|
|
|
11630
11630
|
/**
|
|
11631
11631
|
* Handle GraphQL execution - add metadata to parent server span if present
|
|
11632
11632
|
*/
|
|
11633
|
-
_handleGraphQLExecution(methodName, originalMethod, args, context$
|
|
11633
|
+
_handleGraphQLExecution(methodName, originalMethod, args, context$6) {
|
|
11634
11634
|
if (this.tuskDrift.getMode() !== TuskDriftMode.RECORD) {
|
|
11635
11635
|
logger.debug(`[GraphQLInstrumentation] Not in RECORD mode, skipping instrumentation`);
|
|
11636
|
-
return originalMethod.apply(context$
|
|
11636
|
+
return originalMethod.apply(context$6, args);
|
|
11637
11637
|
}
|
|
11638
11638
|
let currentSpanInfo = null;
|
|
11639
11639
|
try {
|
|
@@ -11643,7 +11643,7 @@ var GraphqlInstrumentation = class extends TdInstrumentationBase {
|
|
|
11643
11643
|
}
|
|
11644
11644
|
if (!currentSpanInfo) {
|
|
11645
11645
|
logger.debug(`[GraphQLInstrumentation] No current span found for ${methodName}, calling original`);
|
|
11646
|
-
return originalMethod.apply(context$
|
|
11646
|
+
return originalMethod.apply(context$6, args);
|
|
11647
11647
|
}
|
|
11648
11648
|
try {
|
|
11649
11649
|
logger.debug(`[GraphQLInstrumentation] Update span attributes with GraphQL info`);
|
|
@@ -11651,7 +11651,7 @@ var GraphqlInstrumentation = class extends TdInstrumentationBase {
|
|
|
11651
11651
|
} catch (error) {
|
|
11652
11652
|
logger.warn(`[GraphQLInstrumentation] Failed to update span attributes with GraphQL info:`, error);
|
|
11653
11653
|
}
|
|
11654
|
-
return originalMethod.apply(context$
|
|
11654
|
+
return originalMethod.apply(context$6, args);
|
|
11655
11655
|
}
|
|
11656
11656
|
/**
|
|
11657
11657
|
* Extract GraphQL metadata from execution args and add to span
|
|
@@ -11756,7 +11756,7 @@ var TdPgClientMock = class extends events.EventEmitter {
|
|
|
11756
11756
|
|
|
11757
11757
|
//#endregion
|
|
11758
11758
|
//#region src/instrumentation/libraries/pg/Instrumentation.ts
|
|
11759
|
-
var import_src$
|
|
11759
|
+
var import_src$26 = /* @__PURE__ */ __toESM(require_src$7(), 1);
|
|
11760
11760
|
var PgInstrumentation = class extends TdInstrumentationBase {
|
|
11761
11761
|
constructor(config = {}) {
|
|
11762
11762
|
super("pg", config);
|
|
@@ -11824,7 +11824,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
11824
11824
|
const spanName = inputValue.clientType === "pool" ? "pg-pool.query" : "pg.query";
|
|
11825
11825
|
return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(this, args), {
|
|
11826
11826
|
name: spanName,
|
|
11827
|
-
kind: import_src$
|
|
11827
|
+
kind: import_src$26.SpanKind.CLIENT,
|
|
11828
11828
|
submodule: "query",
|
|
11829
11829
|
packageType: PackageType.PG,
|
|
11830
11830
|
packageName,
|
|
@@ -11843,7 +11843,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
11843
11843
|
const spanName = inputValue.clientType === "pool" ? "pg-pool.query" : "pg.query";
|
|
11844
11844
|
return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(this, args), {
|
|
11845
11845
|
name: spanName,
|
|
11846
|
-
kind: import_src$
|
|
11846
|
+
kind: import_src$26.SpanKind.CLIENT,
|
|
11847
11847
|
submodule: "query",
|
|
11848
11848
|
packageType: PackageType.PG,
|
|
11849
11849
|
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
@@ -11854,7 +11854,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
11854
11854
|
return self._handleRecordQueryInSpan(spanInfo, originalQuery, queryConfig, args, this);
|
|
11855
11855
|
});
|
|
11856
11856
|
},
|
|
11857
|
-
spanKind: import_src$
|
|
11857
|
+
spanKind: import_src$26.SpanKind.CLIENT
|
|
11858
11858
|
});
|
|
11859
11859
|
else return originalQuery.apply(this, args);
|
|
11860
11860
|
};
|
|
@@ -11876,7 +11876,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
11876
11876
|
replayModeHandler: () => {
|
|
11877
11877
|
return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
|
|
11878
11878
|
name: `pg.connect`,
|
|
11879
|
-
kind: import_src$
|
|
11879
|
+
kind: import_src$26.SpanKind.CLIENT,
|
|
11880
11880
|
submodule: "connect",
|
|
11881
11881
|
packageName: "pg",
|
|
11882
11882
|
packageType: PackageType.PG,
|
|
@@ -11893,7 +11893,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
11893
11893
|
recordModeHandler: ({ isPreAppStart }) => {
|
|
11894
11894
|
return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
|
|
11895
11895
|
name: `pg.connect`,
|
|
11896
|
-
kind: import_src$
|
|
11896
|
+
kind: import_src$26.SpanKind.CLIENT,
|
|
11897
11897
|
submodule: "connect",
|
|
11898
11898
|
packageName: "pg",
|
|
11899
11899
|
packageType: PackageType.PG,
|
|
@@ -11904,7 +11904,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
11904
11904
|
return self._handleRecordConnectInSpan(spanInfo, originalConnect, callback, this);
|
|
11905
11905
|
});
|
|
11906
11906
|
},
|
|
11907
|
-
spanKind: import_src$
|
|
11907
|
+
spanKind: import_src$26.SpanKind.CLIENT
|
|
11908
11908
|
});
|
|
11909
11909
|
else return originalConnect.apply(this, [callback]);
|
|
11910
11910
|
};
|
|
@@ -11928,7 +11928,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
11928
11928
|
};
|
|
11929
11929
|
return null;
|
|
11930
11930
|
}
|
|
11931
|
-
_handleRecordQueryInSpan(spanInfo, originalQuery, queryConfig, args, context$
|
|
11931
|
+
_handleRecordQueryInSpan(spanInfo, originalQuery, queryConfig, args, context$6) {
|
|
11932
11932
|
if (!!queryConfig.callback) {
|
|
11933
11933
|
const originalCallback = queryConfig.callback;
|
|
11934
11934
|
const wrappedCallback = (error, result) => {
|
|
@@ -11936,7 +11936,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
11936
11936
|
logger.debug(`[PgInstrumentation] PG query error (hasCallback): ${error.message} (${SpanUtils.getTraceInfo()})`);
|
|
11937
11937
|
try {
|
|
11938
11938
|
SpanUtils.endSpan(spanInfo.span, {
|
|
11939
|
-
code: import_src$
|
|
11939
|
+
code: import_src$26.SpanStatusCode.ERROR,
|
|
11940
11940
|
message: error.message
|
|
11941
11941
|
});
|
|
11942
11942
|
} catch (error$1) {
|
|
@@ -11946,7 +11946,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
11946
11946
|
logger.debug(`[PgInstrumentation] PG query completed successfully (hasCallback) (${SpanUtils.getTraceInfo()})`);
|
|
11947
11947
|
try {
|
|
11948
11948
|
this._addOutputAttributesToSpan(spanInfo, result);
|
|
11949
|
-
SpanUtils.endSpan(spanInfo.span, { code: import_src$
|
|
11949
|
+
SpanUtils.endSpan(spanInfo.span, { code: import_src$26.SpanStatusCode.OK });
|
|
11950
11950
|
} catch (error$1) {
|
|
11951
11951
|
logger.error(`[PgInstrumentation] error processing response:`, error$1);
|
|
11952
11952
|
}
|
|
@@ -11968,12 +11968,12 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
11968
11968
|
} catch (error) {
|
|
11969
11969
|
logger.error(`[PgInstrumentation] error replacing callback:`, error, args);
|
|
11970
11970
|
}
|
|
11971
|
-
return originalQuery.apply(context$
|
|
11972
|
-
} else return originalQuery.apply(context$
|
|
11971
|
+
return originalQuery.apply(context$6, args);
|
|
11972
|
+
} else return originalQuery.apply(context$6, args).then((result) => {
|
|
11973
11973
|
logger.debug(`[PgInstrumentation] PG query completed successfully (${SpanUtils.getTraceInfo()})`);
|
|
11974
11974
|
try {
|
|
11975
11975
|
this._addOutputAttributesToSpan(spanInfo, result);
|
|
11976
|
-
SpanUtils.endSpan(spanInfo.span, { code: import_src$
|
|
11976
|
+
SpanUtils.endSpan(spanInfo.span, { code: import_src$26.SpanStatusCode.OK });
|
|
11977
11977
|
} catch (error) {
|
|
11978
11978
|
logger.error(`[PgInstrumentation] error processing response:`, error);
|
|
11979
11979
|
}
|
|
@@ -11982,7 +11982,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
11982
11982
|
logger.debug(`[PgInstrumentation] PG query error: ${error.message} (${SpanUtils.getTraceInfo()})`);
|
|
11983
11983
|
try {
|
|
11984
11984
|
SpanUtils.endSpan(spanInfo.span, {
|
|
11985
|
-
code: import_src$
|
|
11985
|
+
code: import_src$26.SpanStatusCode.ERROR,
|
|
11986
11986
|
message: error.message
|
|
11987
11987
|
});
|
|
11988
11988
|
} catch (error$1) {
|
|
@@ -12014,7 +12014,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
12014
12014
|
packageName,
|
|
12015
12015
|
instrumentationName: this.INSTRUMENTATION_NAME,
|
|
12016
12016
|
submoduleName: "query",
|
|
12017
|
-
kind: import_src$
|
|
12017
|
+
kind: import_src$26.SpanKind.CLIENT,
|
|
12018
12018
|
stackTrace
|
|
12019
12019
|
},
|
|
12020
12020
|
tuskDrift: this.tuskDrift
|
|
@@ -12070,14 +12070,14 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
12070
12070
|
rows: convertedRows
|
|
12071
12071
|
};
|
|
12072
12072
|
}
|
|
12073
|
-
_handleRecordConnectInSpan(spanInfo, originalConnect, callback, context$
|
|
12073
|
+
_handleRecordConnectInSpan(spanInfo, originalConnect, callback, context$6) {
|
|
12074
12074
|
if (callback) {
|
|
12075
12075
|
const wrappedCallback = (error) => {
|
|
12076
12076
|
if (error) {
|
|
12077
12077
|
logger.debug(`[PgInstrumentation] PG connect error: ${error.message} (${SpanUtils.getTraceInfo()})`);
|
|
12078
12078
|
try {
|
|
12079
12079
|
SpanUtils.endSpan(spanInfo.span, {
|
|
12080
|
-
code: import_src$
|
|
12080
|
+
code: import_src$26.SpanStatusCode.ERROR,
|
|
12081
12081
|
message: error.message
|
|
12082
12082
|
});
|
|
12083
12083
|
} catch (error$1) {
|
|
@@ -12087,19 +12087,19 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
12087
12087
|
logger.debug(`[PgInstrumentation] PG connect completed successfully (${SpanUtils.getTraceInfo()})`);
|
|
12088
12088
|
try {
|
|
12089
12089
|
SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: { connected: true } });
|
|
12090
|
-
SpanUtils.endSpan(spanInfo.span, { code: import_src$
|
|
12090
|
+
SpanUtils.endSpan(spanInfo.span, { code: import_src$26.SpanStatusCode.OK });
|
|
12091
12091
|
} catch (error$1) {
|
|
12092
12092
|
logger.error(`[PgInstrumentation] error processing connect response:`, error$1);
|
|
12093
12093
|
}
|
|
12094
12094
|
}
|
|
12095
12095
|
return callback(error);
|
|
12096
12096
|
};
|
|
12097
|
-
return originalConnect.call(context$
|
|
12098
|
-
} else return originalConnect.call(context$
|
|
12097
|
+
return originalConnect.call(context$6, wrappedCallback);
|
|
12098
|
+
} else return originalConnect.call(context$6).then((result) => {
|
|
12099
12099
|
logger.debug(`[PgInstrumentation] PG connect completed successfully (${SpanUtils.getTraceInfo()})`);
|
|
12100
12100
|
try {
|
|
12101
12101
|
SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: { connected: true } });
|
|
12102
|
-
SpanUtils.endSpan(spanInfo.span, { code: import_src$
|
|
12102
|
+
SpanUtils.endSpan(spanInfo.span, { code: import_src$26.SpanStatusCode.OK });
|
|
12103
12103
|
} catch (error) {
|
|
12104
12104
|
logger.error(`[PgInstrumentation] error processing connect response:`, error);
|
|
12105
12105
|
}
|
|
@@ -12108,7 +12108,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
12108
12108
|
logger.debug(`[PgInstrumentation] PG connect error: ${error.message} (${SpanUtils.getTraceInfo()})`);
|
|
12109
12109
|
try {
|
|
12110
12110
|
SpanUtils.endSpan(spanInfo.span, {
|
|
12111
|
-
code: import_src$
|
|
12111
|
+
code: import_src$26.SpanStatusCode.ERROR,
|
|
12112
12112
|
message: error.message
|
|
12113
12113
|
});
|
|
12114
12114
|
} catch (error$1) {
|
|
@@ -12169,7 +12169,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
12169
12169
|
replayModeHandler: () => {
|
|
12170
12170
|
return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
|
|
12171
12171
|
name: `pg-pool.connect`,
|
|
12172
|
-
kind: import_src$
|
|
12172
|
+
kind: import_src$26.SpanKind.CLIENT,
|
|
12173
12173
|
submodule: "connect",
|
|
12174
12174
|
packageName: "pg-pool",
|
|
12175
12175
|
packageType: PackageType.PG,
|
|
@@ -12186,7 +12186,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
12186
12186
|
recordModeHandler: ({ isPreAppStart }) => {
|
|
12187
12187
|
return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
|
|
12188
12188
|
name: `pg-pool.connect`,
|
|
12189
|
-
kind: import_src$
|
|
12189
|
+
kind: import_src$26.SpanKind.CLIENT,
|
|
12190
12190
|
submodule: "connect",
|
|
12191
12191
|
packageName: "pg-pool",
|
|
12192
12192
|
packageType: PackageType.PG,
|
|
@@ -12197,20 +12197,20 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
12197
12197
|
return self._handleRecordPoolConnectInSpan(spanInfo, originalConnect, callback, this);
|
|
12198
12198
|
});
|
|
12199
12199
|
},
|
|
12200
|
-
spanKind: import_src$
|
|
12200
|
+
spanKind: import_src$26.SpanKind.CLIENT
|
|
12201
12201
|
});
|
|
12202
12202
|
else return originalConnect.apply(this, [callback]);
|
|
12203
12203
|
};
|
|
12204
12204
|
};
|
|
12205
12205
|
}
|
|
12206
|
-
_handleRecordPoolConnectInSpan(spanInfo, originalConnect, callback, context$
|
|
12206
|
+
_handleRecordPoolConnectInSpan(spanInfo, originalConnect, callback, context$6) {
|
|
12207
12207
|
if (callback) {
|
|
12208
12208
|
const wrappedCallback = (error, client, done) => {
|
|
12209
12209
|
if (error) {
|
|
12210
12210
|
logger.debug(`[PgInstrumentation] PG Pool connect error: ${error.message} (${SpanUtils.getTraceInfo()})`);
|
|
12211
12211
|
try {
|
|
12212
12212
|
SpanUtils.endSpan(spanInfo.span, {
|
|
12213
|
-
code: import_src$
|
|
12213
|
+
code: import_src$26.SpanStatusCode.ERROR,
|
|
12214
12214
|
message: error.message
|
|
12215
12215
|
});
|
|
12216
12216
|
} catch (error$1) {
|
|
@@ -12223,22 +12223,22 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
12223
12223
|
connected: true,
|
|
12224
12224
|
hasClient: !!client
|
|
12225
12225
|
} });
|
|
12226
|
-
SpanUtils.endSpan(spanInfo.span, { code: import_src$
|
|
12226
|
+
SpanUtils.endSpan(spanInfo.span, { code: import_src$26.SpanStatusCode.OK });
|
|
12227
12227
|
} catch (error$1) {
|
|
12228
12228
|
logger.error(`[PgInstrumentation] error processing pool connect response:`, error$1);
|
|
12229
12229
|
}
|
|
12230
12230
|
}
|
|
12231
12231
|
return callback(error, client, done);
|
|
12232
12232
|
};
|
|
12233
|
-
return originalConnect.call(context$
|
|
12234
|
-
} else return originalConnect.call(context$
|
|
12233
|
+
return originalConnect.call(context$6, wrappedCallback);
|
|
12234
|
+
} else return originalConnect.call(context$6).then((client) => {
|
|
12235
12235
|
logger.debug(`[PgInstrumentation] PG Pool connect completed successfully (${SpanUtils.getTraceInfo()})`);
|
|
12236
12236
|
try {
|
|
12237
12237
|
SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: {
|
|
12238
12238
|
connected: true,
|
|
12239
12239
|
hasClient: !!client
|
|
12240
12240
|
} });
|
|
12241
|
-
SpanUtils.endSpan(spanInfo.span, { code: import_src$
|
|
12241
|
+
SpanUtils.endSpan(spanInfo.span, { code: import_src$26.SpanStatusCode.OK });
|
|
12242
12242
|
} catch (error) {
|
|
12243
12243
|
logger.error(`[PgInstrumentation] error processing pool connect response:`, error);
|
|
12244
12244
|
}
|
|
@@ -12247,7 +12247,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
12247
12247
|
logger.debug(`[PgInstrumentation] PG Pool connect error: ${error.message} (${SpanUtils.getTraceInfo()})`);
|
|
12248
12248
|
try {
|
|
12249
12249
|
SpanUtils.endSpan(spanInfo.span, {
|
|
12250
|
-
code: import_src$
|
|
12250
|
+
code: import_src$26.SpanStatusCode.ERROR,
|
|
12251
12251
|
message: error.message
|
|
12252
12252
|
});
|
|
12253
12253
|
} catch (error$1) {
|
|
@@ -12272,17 +12272,12 @@ var PgInstrumentation = class extends TdInstrumentationBase {
|
|
|
12272
12272
|
//#endregion
|
|
12273
12273
|
//#region src/instrumentation/libraries/postgres/types.ts
|
|
12274
12274
|
function isPostgresOutputValueType(value) {
|
|
12275
|
-
return value !== null && value !== void 0 && typeof value === "object"
|
|
12275
|
+
return value !== null && value !== void 0 && typeof value === "object";
|
|
12276
12276
|
}
|
|
12277
|
-
let PostgresReturnType = /* @__PURE__ */ function(PostgresReturnType$1) {
|
|
12278
|
-
PostgresReturnType$1["ARRAY"] = "array";
|
|
12279
|
-
PostgresReturnType$1["OBJECT"] = "object";
|
|
12280
|
-
return PostgresReturnType$1;
|
|
12281
|
-
}({});
|
|
12282
12277
|
|
|
12283
12278
|
//#endregion
|
|
12284
12279
|
//#region src/instrumentation/libraries/postgres/Instrumentation.ts
|
|
12285
|
-
var import_src$
|
|
12280
|
+
var import_src$25 = /* @__PURE__ */ __toESM(require_src$7(), 1);
|
|
12286
12281
|
var PostgresInstrumentation = class extends TdInstrumentationBase {
|
|
12287
12282
|
constructor(config = {}) {
|
|
12288
12283
|
super("postgres", config);
|
|
@@ -12346,13 +12341,17 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
|
|
|
12346
12341
|
};
|
|
12347
12342
|
if (this.mode === TuskDriftMode.REPLAY) return handleReplayMode({
|
|
12348
12343
|
noOpRequestHandler: () => {
|
|
12349
|
-
|
|
12350
|
-
|
|
12351
|
-
|
|
12352
|
-
}
|
|
12353
|
-
|
|
12354
|
-
|
|
12355
|
-
|
|
12344
|
+
const mockSql = () => Promise.resolve(Object.assign([], {
|
|
12345
|
+
count: 0,
|
|
12346
|
+
command: null
|
|
12347
|
+
}));
|
|
12348
|
+
mockSql.unsafe = () => Promise.resolve(Object.assign([], {
|
|
12349
|
+
count: 0,
|
|
12350
|
+
command: null
|
|
12351
|
+
}));
|
|
12352
|
+
mockSql.begin = () => Promise.resolve();
|
|
12353
|
+
mockSql.end = () => Promise.resolve();
|
|
12354
|
+
return mockSql;
|
|
12356
12355
|
},
|
|
12357
12356
|
isServerRequest: false,
|
|
12358
12357
|
replayModeHandler: () => {
|
|
@@ -12361,7 +12360,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
|
|
|
12361
12360
|
return this._wrapSqlInstance(sqlInstance);
|
|
12362
12361
|
}, {
|
|
12363
12362
|
name: "postgres.connect",
|
|
12364
|
-
kind: import_src$
|
|
12363
|
+
kind: import_src$25.SpanKind.CLIENT,
|
|
12365
12364
|
submodule: "connect",
|
|
12366
12365
|
packageType: PackageType.PG,
|
|
12367
12366
|
packageName: "postgres",
|
|
@@ -12384,7 +12383,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
|
|
|
12384
12383
|
return this._wrapSqlInstance(sqlInstance);
|
|
12385
12384
|
}, {
|
|
12386
12385
|
name: "postgres.connect",
|
|
12387
|
-
kind: import_src$
|
|
12386
|
+
kind: import_src$25.SpanKind.CLIENT,
|
|
12388
12387
|
submodule: "connect",
|
|
12389
12388
|
packageType: PackageType.PG,
|
|
12390
12389
|
packageName: "postgres",
|
|
@@ -12395,7 +12394,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
|
|
|
12395
12394
|
return this._handleRecordConnect(spanInfo, originalFunction, args);
|
|
12396
12395
|
});
|
|
12397
12396
|
},
|
|
12398
|
-
spanKind: import_src$
|
|
12397
|
+
spanKind: import_src$25.SpanKind.CLIENT
|
|
12399
12398
|
});
|
|
12400
12399
|
else return originalFunction(...args);
|
|
12401
12400
|
}
|
|
@@ -12426,7 +12425,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
|
|
|
12426
12425
|
try {
|
|
12427
12426
|
logger.debug(`[PostgresInstrumentation] Postgres connection created successfully (${SpanUtils.getTraceInfo()})`);
|
|
12428
12427
|
SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: { connected: true } });
|
|
12429
|
-
SpanUtils.endSpan(spanInfo.span, { code: import_src$
|
|
12428
|
+
SpanUtils.endSpan(spanInfo.span, { code: import_src$25.SpanStatusCode.OK });
|
|
12430
12429
|
} catch (error) {
|
|
12431
12430
|
logger.error(`[PostgresInstrumentation] error adding span attributes:`, error);
|
|
12432
12431
|
}
|
|
@@ -12487,121 +12486,189 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
|
|
|
12487
12486
|
};
|
|
12488
12487
|
}
|
|
12489
12488
|
_handleSqlQuery(originalSql, strings, values) {
|
|
12490
|
-
|
|
12491
|
-
|
|
12492
|
-
|
|
12493
|
-
|
|
12494
|
-
|
|
12495
|
-
|
|
12496
|
-
|
|
12497
|
-
|
|
12498
|
-
|
|
12499
|
-
|
|
12500
|
-
|
|
12501
|
-
|
|
12502
|
-
|
|
12503
|
-
|
|
12504
|
-
|
|
12505
|
-
|
|
12506
|
-
|
|
12507
|
-
|
|
12508
|
-
|
|
12509
|
-
|
|
12510
|
-
packageName: "postgres",
|
|
12511
|
-
instrumentationName: this.INSTRUMENTATION_NAME,
|
|
12512
|
-
inputValue,
|
|
12513
|
-
isPreAppStart: false
|
|
12514
|
-
}, (spanInfo) => {
|
|
12515
|
-
return this.handleReplaySqlQuery({
|
|
12516
|
-
inputValue,
|
|
12517
|
-
spanInfo,
|
|
12518
|
-
submodule: "query",
|
|
12489
|
+
if (!strings || !Array.isArray(strings.raw)) return originalSql.call(this, strings, ...values);
|
|
12490
|
+
const creationContext = import_src$25.context.active();
|
|
12491
|
+
const query = originalSql.call(this, strings, ...values);
|
|
12492
|
+
const originalThen = query.then.bind(query);
|
|
12493
|
+
const self = this;
|
|
12494
|
+
query.then = function(onFulfilled, onRejected) {
|
|
12495
|
+
let queryString = "";
|
|
12496
|
+
for (let i = 0; i < strings.length; i++) {
|
|
12497
|
+
queryString += strings[i];
|
|
12498
|
+
if (i < values.length) queryString += `$${i + 1}`;
|
|
12499
|
+
}
|
|
12500
|
+
const inputValue = {
|
|
12501
|
+
query: queryString.trim(),
|
|
12502
|
+
parameters: values
|
|
12503
|
+
};
|
|
12504
|
+
return import_src$25.context.with(creationContext, () => {
|
|
12505
|
+
if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
|
|
12506
|
+
originalFunctionCall: () => originalThen(onFulfilled, onRejected),
|
|
12507
|
+
recordModeHandler: ({ isPreAppStart }) => {
|
|
12508
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalThen(onFulfilled, onRejected), {
|
|
12519
12509
|
name: "postgres.query",
|
|
12520
|
-
|
|
12510
|
+
kind: import_src$25.SpanKind.CLIENT,
|
|
12511
|
+
submodule: "query",
|
|
12512
|
+
packageType: PackageType.PG,
|
|
12513
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
12514
|
+
packageName: "postgres",
|
|
12515
|
+
inputValue,
|
|
12516
|
+
isPreAppStart
|
|
12517
|
+
}, (spanInfo) => {
|
|
12518
|
+
const wrappedOnFulfilled = (result) => {
|
|
12519
|
+
try {
|
|
12520
|
+
logger.debug(`[PostgresInstrumentation] Postgres query completed successfully`, result);
|
|
12521
|
+
self._addOutputAttributesToSpan(spanInfo, result);
|
|
12522
|
+
SpanUtils.endSpan(spanInfo.span, { code: import_src$25.SpanStatusCode.OK });
|
|
12523
|
+
} catch (error) {
|
|
12524
|
+
logger.error(`[PostgresInstrumentation] error processing query response:`, error);
|
|
12525
|
+
}
|
|
12526
|
+
return onFulfilled ? onFulfilled(result) : result;
|
|
12527
|
+
};
|
|
12528
|
+
const wrappedOnRejected = (error) => {
|
|
12529
|
+
try {
|
|
12530
|
+
logger.debug(`[PostgresInstrumentation] Postgres query error`, error);
|
|
12531
|
+
SpanUtils.endSpan(spanInfo.span, {
|
|
12532
|
+
code: import_src$25.SpanStatusCode.ERROR,
|
|
12533
|
+
message: error.message
|
|
12534
|
+
});
|
|
12535
|
+
} catch (spanError) {
|
|
12536
|
+
logger.error(`[PostgresInstrumentation] error ending span:`, spanError);
|
|
12537
|
+
}
|
|
12538
|
+
if (onRejected) return onRejected(error);
|
|
12539
|
+
throw error;
|
|
12540
|
+
};
|
|
12541
|
+
return originalThen(wrappedOnFulfilled, wrappedOnRejected);
|
|
12521
12542
|
});
|
|
12543
|
+
},
|
|
12544
|
+
spanKind: import_src$25.SpanKind.CLIENT
|
|
12545
|
+
});
|
|
12546
|
+
else if (self.mode === TuskDriftMode.REPLAY) {
|
|
12547
|
+
const stackTrace = captureStackTrace(["PostgresInstrumentation"]);
|
|
12548
|
+
return handleReplayMode({
|
|
12549
|
+
noOpRequestHandler: () => Promise.resolve(Object.assign([], {
|
|
12550
|
+
count: 0,
|
|
12551
|
+
command: null
|
|
12552
|
+
})),
|
|
12553
|
+
isServerRequest: false,
|
|
12554
|
+
replayModeHandler: () => {
|
|
12555
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalThen(onFulfilled, onRejected), {
|
|
12556
|
+
name: "postgres.query",
|
|
12557
|
+
kind: import_src$25.SpanKind.CLIENT,
|
|
12558
|
+
submodule: "query",
|
|
12559
|
+
packageType: PackageType.PG,
|
|
12560
|
+
packageName: "postgres",
|
|
12561
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
12562
|
+
inputValue,
|
|
12563
|
+
isPreAppStart: false
|
|
12564
|
+
}, async (spanInfo) => {
|
|
12565
|
+
const mockedResult = await self.handleReplaySqlQuery({
|
|
12566
|
+
inputValue,
|
|
12567
|
+
spanInfo,
|
|
12568
|
+
submodule: "query",
|
|
12569
|
+
name: "postgres.query",
|
|
12570
|
+
stackTrace
|
|
12571
|
+
});
|
|
12572
|
+
return onFulfilled ? onFulfilled(mockedResult) : mockedResult;
|
|
12573
|
+
});
|
|
12574
|
+
}
|
|
12522
12575
|
});
|
|
12523
|
-
}
|
|
12576
|
+
} else return originalThen(onFulfilled, onRejected);
|
|
12524
12577
|
});
|
|
12525
|
-
}
|
|
12526
|
-
|
|
12527
|
-
recordModeHandler: ({ isPreAppStart }) => {
|
|
12528
|
-
return SpanUtils.createAndExecuteSpan(this.mode, () => originalSql.call(this, strings, ...values), {
|
|
12529
|
-
name: "postgres.query",
|
|
12530
|
-
kind: import_src$23.SpanKind.CLIENT,
|
|
12531
|
-
submodule: "query",
|
|
12532
|
-
packageType: PackageType.PG,
|
|
12533
|
-
instrumentationName: this.INSTRUMENTATION_NAME,
|
|
12534
|
-
packageName: "postgres",
|
|
12535
|
-
inputValue,
|
|
12536
|
-
isPreAppStart
|
|
12537
|
-
}, (spanInfo) => {
|
|
12538
|
-
return this._handleRecordQueryInSpan(spanInfo, originalSql, strings, values);
|
|
12539
|
-
});
|
|
12540
|
-
},
|
|
12541
|
-
spanKind: import_src$23.SpanKind.CLIENT
|
|
12542
|
-
});
|
|
12543
|
-
else return originalSql.call(this, strings, ...values);
|
|
12578
|
+
};
|
|
12579
|
+
return query;
|
|
12544
12580
|
}
|
|
12545
12581
|
_handleUnsafeQuery(sqlInstance, originalUnsafe, query, parameters, queryOptions) {
|
|
12546
|
-
const
|
|
12582
|
+
const unsafeQuery = (() => {
|
|
12547
12583
|
if (queryOptions !== void 0) return originalUnsafe.call(sqlInstance, query, parameters, queryOptions);
|
|
12548
12584
|
else if (parameters !== void 0) return originalUnsafe.call(sqlInstance, query, parameters);
|
|
12549
12585
|
else return originalUnsafe.call(sqlInstance, query);
|
|
12550
|
-
};
|
|
12586
|
+
})();
|
|
12587
|
+
const creationContext = import_src$25.context.active();
|
|
12588
|
+
const originalThen = unsafeQuery.then.bind(unsafeQuery);
|
|
12589
|
+
const self = this;
|
|
12551
12590
|
const inputValue = {
|
|
12552
12591
|
query: query.trim(),
|
|
12553
12592
|
parameters: parameters || [],
|
|
12554
12593
|
options: queryOptions
|
|
12555
12594
|
};
|
|
12556
|
-
|
|
12557
|
-
|
|
12558
|
-
|
|
12559
|
-
|
|
12560
|
-
|
|
12561
|
-
|
|
12562
|
-
isServerRequest: false,
|
|
12563
|
-
replayModeHandler: () => {
|
|
12564
|
-
return this._createPendingQueryWrapper(() => {
|
|
12565
|
-
return SpanUtils.createAndExecuteSpan(this.mode, () => executeUnsafe(), {
|
|
12595
|
+
unsafeQuery.then = function(onFulfilled, onRejected) {
|
|
12596
|
+
return import_src$25.context.with(creationContext, () => {
|
|
12597
|
+
if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
|
|
12598
|
+
originalFunctionCall: () => originalThen(onFulfilled, onRejected),
|
|
12599
|
+
recordModeHandler: ({ isPreAppStart }) => {
|
|
12600
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalThen(onFulfilled, onRejected), {
|
|
12566
12601
|
name: "postgres.unsafe",
|
|
12567
|
-
kind: import_src$
|
|
12602
|
+
kind: import_src$25.SpanKind.CLIENT,
|
|
12568
12603
|
submodule: "unsafe",
|
|
12569
12604
|
packageType: PackageType.PG,
|
|
12570
12605
|
packageName: "postgres",
|
|
12571
|
-
instrumentationName:
|
|
12606
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
12572
12607
|
inputValue,
|
|
12573
|
-
isPreAppStart
|
|
12608
|
+
isPreAppStart
|
|
12574
12609
|
}, (spanInfo) => {
|
|
12575
|
-
|
|
12576
|
-
|
|
12577
|
-
|
|
12578
|
-
|
|
12610
|
+
const wrappedOnFulfilled = (result) => {
|
|
12611
|
+
try {
|
|
12612
|
+
logger.debug(`[PostgresInstrumentation] Postgres unsafe query completed successfully (${SpanUtils.getTraceInfo()})`);
|
|
12613
|
+
self._addOutputAttributesToSpan(spanInfo, result);
|
|
12614
|
+
SpanUtils.endSpan(spanInfo.span, { code: import_src$25.SpanStatusCode.OK });
|
|
12615
|
+
} catch (error) {
|
|
12616
|
+
logger.error(`[PostgresInstrumentation] error processing unsafe query response:`, error);
|
|
12617
|
+
}
|
|
12618
|
+
return onFulfilled ? onFulfilled(result) : result;
|
|
12619
|
+
};
|
|
12620
|
+
const wrappedOnRejected = (error) => {
|
|
12621
|
+
try {
|
|
12622
|
+
logger.debug(`[PostgresInstrumentation] Postgres unsafe query error: ${error.message}`);
|
|
12623
|
+
SpanUtils.endSpan(spanInfo.span, {
|
|
12624
|
+
code: import_src$25.SpanStatusCode.ERROR,
|
|
12625
|
+
message: error.message
|
|
12626
|
+
});
|
|
12627
|
+
} catch (spanError) {
|
|
12628
|
+
logger.error(`[PostgresInstrumentation] error ending span:`, spanError);
|
|
12629
|
+
}
|
|
12630
|
+
if (onRejected) return onRejected(error);
|
|
12631
|
+
throw error;
|
|
12632
|
+
};
|
|
12633
|
+
return originalThen(wrappedOnFulfilled, wrappedOnRejected);
|
|
12634
|
+
});
|
|
12635
|
+
},
|
|
12636
|
+
spanKind: import_src$25.SpanKind.CLIENT
|
|
12637
|
+
});
|
|
12638
|
+
else if (self.mode === TuskDriftMode.REPLAY) {
|
|
12639
|
+
const stackTrace = captureStackTrace(["PostgresInstrumentation"]);
|
|
12640
|
+
return handleReplayMode({
|
|
12641
|
+
noOpRequestHandler: () => Promise.resolve(Object.assign([], {
|
|
12642
|
+
count: 0,
|
|
12643
|
+
command: null
|
|
12644
|
+
})),
|
|
12645
|
+
isServerRequest: false,
|
|
12646
|
+
replayModeHandler: () => {
|
|
12647
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalThen(onFulfilled, onRejected), {
|
|
12579
12648
|
name: "postgres.unsafe",
|
|
12580
|
-
|
|
12649
|
+
kind: import_src$25.SpanKind.CLIENT,
|
|
12650
|
+
submodule: "unsafe",
|
|
12651
|
+
packageType: PackageType.PG,
|
|
12652
|
+
packageName: "postgres",
|
|
12653
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
12654
|
+
inputValue,
|
|
12655
|
+
isPreAppStart: false
|
|
12656
|
+
}, async (spanInfo) => {
|
|
12657
|
+
const mockedResult = await self.handleReplayUnsafeQuery({
|
|
12658
|
+
inputValue,
|
|
12659
|
+
spanInfo,
|
|
12660
|
+
submodule: "unsafe",
|
|
12661
|
+
name: "postgres.unsafe",
|
|
12662
|
+
stackTrace
|
|
12663
|
+
});
|
|
12664
|
+
return onFulfilled ? onFulfilled(mockedResult) : mockedResult;
|
|
12581
12665
|
});
|
|
12582
|
-
}
|
|
12666
|
+
}
|
|
12583
12667
|
});
|
|
12584
|
-
}
|
|
12668
|
+
} else return originalThen(onFulfilled, onRejected);
|
|
12585
12669
|
});
|
|
12586
|
-
}
|
|
12587
|
-
|
|
12588
|
-
recordModeHandler: ({ isPreAppStart }) => {
|
|
12589
|
-
return SpanUtils.createAndExecuteSpan(this.mode, executeUnsafe, {
|
|
12590
|
-
name: "postgres.unsafe",
|
|
12591
|
-
kind: import_src$23.SpanKind.CLIENT,
|
|
12592
|
-
submodule: "unsafe",
|
|
12593
|
-
packageType: PackageType.PG,
|
|
12594
|
-
packageName: "postgres",
|
|
12595
|
-
instrumentationName: this.INSTRUMENTATION_NAME,
|
|
12596
|
-
inputValue,
|
|
12597
|
-
isPreAppStart
|
|
12598
|
-
}, (spanInfo) => {
|
|
12599
|
-
return this._executeThenAddOutputAttributes(spanInfo, executeUnsafe);
|
|
12600
|
-
});
|
|
12601
|
-
},
|
|
12602
|
-
spanKind: import_src$23.SpanKind.CLIENT
|
|
12603
|
-
});
|
|
12604
|
-
else return executeUnsafe();
|
|
12670
|
+
};
|
|
12671
|
+
return unsafeQuery;
|
|
12605
12672
|
}
|
|
12606
12673
|
_handleBeginTransaction(sqlInstance, originalBegin, options, transactionCallback) {
|
|
12607
12674
|
const inputValue = {
|
|
@@ -12616,12 +12683,12 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
|
|
|
12616
12683
|
if (this.mode === TuskDriftMode.REPLAY) {
|
|
12617
12684
|
const stackTrace = captureStackTrace(["PostgresInstrumentation"]);
|
|
12618
12685
|
return handleReplayMode({
|
|
12619
|
-
noOpRequestHandler: () =>
|
|
12686
|
+
noOpRequestHandler: () => Promise.resolve(),
|
|
12620
12687
|
isServerRequest: false,
|
|
12621
12688
|
replayModeHandler: () => {
|
|
12622
12689
|
return SpanUtils.createAndExecuteSpan(this.mode, () => executeBegin(), {
|
|
12623
12690
|
name: "postgres.begin",
|
|
12624
|
-
kind: import_src$
|
|
12691
|
+
kind: import_src$25.SpanKind.CLIENT,
|
|
12625
12692
|
submodule: "transaction",
|
|
12626
12693
|
packageType: PackageType.PG,
|
|
12627
12694
|
packageName: "postgres",
|
|
@@ -12638,7 +12705,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
|
|
|
12638
12705
|
recordModeHandler: ({ isPreAppStart }) => {
|
|
12639
12706
|
return SpanUtils.createAndExecuteSpan(this.mode, executeBegin, {
|
|
12640
12707
|
name: "postgres.begin",
|
|
12641
|
-
kind: import_src$
|
|
12708
|
+
kind: import_src$25.SpanKind.CLIENT,
|
|
12642
12709
|
submodule: "transaction",
|
|
12643
12710
|
packageType: PackageType.PG,
|
|
12644
12711
|
packageName: "postgres",
|
|
@@ -12649,52 +12716,10 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
|
|
|
12649
12716
|
return this._handleRecordBeginTransaction(spanInfo, executeBegin);
|
|
12650
12717
|
});
|
|
12651
12718
|
},
|
|
12652
|
-
spanKind: import_src$
|
|
12719
|
+
spanKind: import_src$25.SpanKind.CLIENT
|
|
12653
12720
|
});
|
|
12654
12721
|
else return executeBegin();
|
|
12655
12722
|
}
|
|
12656
|
-
/**
|
|
12657
|
-
* Execute postgres.js unsafe query and create span afterwards.
|
|
12658
|
-
*
|
|
12659
|
-
* postgres.js has sophisticated internal session and connection management
|
|
12660
|
-
* that is extremely sensitive to async context changes. Unlike the regular 'pg' library,
|
|
12661
|
-
* postgres.js maintains internal state using promise identity and async context tracking.
|
|
12662
|
-
*
|
|
12663
|
-
* The issue: promise chain modification breaks postgres.js.
|
|
12664
|
-
* Calling .then()/.catch() creates new promise objects, breaking postgres.js's internal tracking
|
|
12665
|
-
*
|
|
12666
|
-
* Solution: We must execute the postgres.js query in its completely unmodified context:
|
|
12667
|
-
* - Return the original promise object unchanged
|
|
12668
|
-
* - Use promise.finally() to track completion without creating a new promise chain
|
|
12669
|
-
*
|
|
12670
|
-
* This preserves postgres.js's internal session management while still providing tracing.
|
|
12671
|
-
* The 'pg' library doesn't have this issue because it has simpler internal state management.
|
|
12672
|
-
*/
|
|
12673
|
-
_executeThenAddOutputAttributes(spanInfo, executeUnsafe) {
|
|
12674
|
-
const promise = executeUnsafe();
|
|
12675
|
-
promise.finally(() => {
|
|
12676
|
-
promise.then((result) => {
|
|
12677
|
-
logger.debug(`[PostgresInstrumentation] Postgres unsafe query completed successfully`);
|
|
12678
|
-
try {
|
|
12679
|
-
this._addOutputAttributesToSpan(spanInfo, result);
|
|
12680
|
-
SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
|
|
12681
|
-
} catch (error) {
|
|
12682
|
-
logger.error(`[PostgresInstrumentation] error processing unsafe query response:`, error);
|
|
12683
|
-
}
|
|
12684
|
-
}).catch((error) => {
|
|
12685
|
-
logger.debug(`[PostgresInstrumentation] Postgres unsafe query error: ${error.message}`);
|
|
12686
|
-
try {
|
|
12687
|
-
SpanUtils.endSpan(spanInfo.span, {
|
|
12688
|
-
code: import_src$23.SpanStatusCode.ERROR,
|
|
12689
|
-
message: error.message
|
|
12690
|
-
});
|
|
12691
|
-
} catch (error$1) {
|
|
12692
|
-
logger.error(`[PostgresInstrumentation] error ending span:`, error$1);
|
|
12693
|
-
}
|
|
12694
|
-
});
|
|
12695
|
-
});
|
|
12696
|
-
return promise;
|
|
12697
|
-
}
|
|
12698
12723
|
_handleRecordBeginTransaction(spanInfo, executeBegin) {
|
|
12699
12724
|
const promise = executeBegin();
|
|
12700
12725
|
promise.finally(() => {
|
|
@@ -12705,7 +12730,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
|
|
|
12705
12730
|
status: "committed",
|
|
12706
12731
|
result
|
|
12707
12732
|
} });
|
|
12708
|
-
SpanUtils.endSpan(spanInfo.span, { code: import_src$
|
|
12733
|
+
SpanUtils.endSpan(spanInfo.span, { code: import_src$25.SpanStatusCode.OK });
|
|
12709
12734
|
} catch (error) {
|
|
12710
12735
|
logger.error(`[PostgresInstrumentation] error processing transaction response:`, error);
|
|
12711
12736
|
}
|
|
@@ -12717,7 +12742,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
|
|
|
12717
12742
|
error: error.message
|
|
12718
12743
|
} });
|
|
12719
12744
|
SpanUtils.endSpan(spanInfo.span, {
|
|
12720
|
-
code: import_src$
|
|
12745
|
+
code: import_src$25.SpanStatusCode.ERROR,
|
|
12721
12746
|
message: error.message
|
|
12722
12747
|
});
|
|
12723
12748
|
} catch (spanError) {
|
|
@@ -12727,187 +12752,1693 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
|
|
|
12727
12752
|
});
|
|
12728
12753
|
return promise;
|
|
12729
12754
|
}
|
|
12730
|
-
async _handleReplayBeginTransaction(spanInfo, options, stackTrace) {
|
|
12731
|
-
logger.debug(`[PostgresInstrumentation] Replaying Postgres transaction`);
|
|
12732
|
-
const mockData = await findMockResponseAsync({
|
|
12733
|
-
mockRequestData: {
|
|
12734
|
-
traceId: spanInfo.traceId,
|
|
12735
|
-
spanId: spanInfo.spanId,
|
|
12736
|
-
name: "postgres.begin",
|
|
12737
|
-
inputValue: {
|
|
12738
|
-
query: "BEGIN",
|
|
12739
|
-
options: options ? { transactionOptions: options } : void 0
|
|
12740
|
-
},
|
|
12741
|
-
packageName: "postgres",
|
|
12742
|
-
instrumentationName: this.INSTRUMENTATION_NAME,
|
|
12743
|
-
submoduleName: "transaction",
|
|
12744
|
-
kind: import_src$
|
|
12745
|
-
stackTrace
|
|
12746
|
-
},
|
|
12747
|
-
tuskDrift: this.tuskDrift
|
|
12748
|
-
});
|
|
12749
|
-
if (!mockData) {
|
|
12750
|
-
logger.warn(`[PostgresInstrumentation] No mock data found for transaction BEGIN`);
|
|
12751
|
-
throw new Error(`[PostgresInstrumentation] No matching mock found for transaction BEGIN`);
|
|
12752
|
-
}
|
|
12753
|
-
logger.debug(`[PostgresInstrumentation] Found mock data for transaction: ${JSON.stringify(mockData)}`);
|
|
12754
|
-
const transactionResult = mockData.result;
|
|
12755
|
-
if (transactionResult && typeof transactionResult === "object" && "status" in transactionResult && transactionResult.status === "committed") return transactionResult.result;
|
|
12756
|
-
else {
|
|
12757
|
-
const errorMessage = transactionResult && typeof transactionResult === "object" && "error" in transactionResult && transactionResult.error ? transactionResult.error : "Transaction rolled back";
|
|
12758
|
-
throw new Error(errorMessage);
|
|
12759
|
-
}
|
|
12755
|
+
async _handleReplayBeginTransaction(spanInfo, options, stackTrace) {
|
|
12756
|
+
logger.debug(`[PostgresInstrumentation] Replaying Postgres transaction`);
|
|
12757
|
+
const mockData = await findMockResponseAsync({
|
|
12758
|
+
mockRequestData: {
|
|
12759
|
+
traceId: spanInfo.traceId,
|
|
12760
|
+
spanId: spanInfo.spanId,
|
|
12761
|
+
name: "postgres.begin",
|
|
12762
|
+
inputValue: createMockInputValue({
|
|
12763
|
+
query: "BEGIN",
|
|
12764
|
+
options: options ? { transactionOptions: options } : void 0
|
|
12765
|
+
}),
|
|
12766
|
+
packageName: "postgres",
|
|
12767
|
+
instrumentationName: this.INSTRUMENTATION_NAME,
|
|
12768
|
+
submoduleName: "transaction",
|
|
12769
|
+
kind: import_src$25.SpanKind.CLIENT,
|
|
12770
|
+
stackTrace
|
|
12771
|
+
},
|
|
12772
|
+
tuskDrift: this.tuskDrift
|
|
12773
|
+
});
|
|
12774
|
+
if (!mockData) {
|
|
12775
|
+
logger.warn(`[PostgresInstrumentation] No mock data found for transaction BEGIN`);
|
|
12776
|
+
throw new Error(`[PostgresInstrumentation] No matching mock found for transaction BEGIN`);
|
|
12777
|
+
}
|
|
12778
|
+
logger.debug(`[PostgresInstrumentation] Found mock data for transaction: ${JSON.stringify(mockData)}`);
|
|
12779
|
+
const transactionResult = mockData.result;
|
|
12780
|
+
if (transactionResult && typeof transactionResult === "object" && "status" in transactionResult && transactionResult.status === "committed") return transactionResult.result;
|
|
12781
|
+
else {
|
|
12782
|
+
const errorMessage = transactionResult && typeof transactionResult === "object" && "error" in transactionResult && transactionResult.error ? transactionResult.error : "Transaction rolled back";
|
|
12783
|
+
throw new Error(errorMessage);
|
|
12784
|
+
}
|
|
12785
|
+
}
|
|
12786
|
+
async handleReplaySqlQuery({ inputValue, spanInfo, submodule, name, stackTrace }) {
|
|
12787
|
+
logger.debug(`[PostgresInstrumentation] Replaying Postgres sql query`);
|
|
12788
|
+
const mockData = await findMockResponseAsync({
|
|
12789
|
+
mockRequestData: {
|
|
12790
|
+
traceId: spanInfo.traceId,
|
|
12791
|
+
spanId: spanInfo.spanId,
|
|
12792
|
+
name,
|
|
12793
|
+
inputValue: createMockInputValue(inputValue),
|
|
12794
|
+
packageName: "postgres",
|
|
12795
|
+
instrumentationName: this.INSTRUMENTATION_NAME,
|
|
12796
|
+
submoduleName: submodule,
|
|
12797
|
+
kind: import_src$25.SpanKind.CLIENT,
|
|
12798
|
+
stackTrace
|
|
12799
|
+
},
|
|
12800
|
+
tuskDrift: this.tuskDrift
|
|
12801
|
+
});
|
|
12802
|
+
if (!mockData) {
|
|
12803
|
+
const queryText = inputValue.query || "UNKNOWN_QUERY";
|
|
12804
|
+
logger.warn(`[PostgresInstrumentation] No mock data found for Postgres sql query: ${queryText}`);
|
|
12805
|
+
throw new Error(`[PostgresInstrumentation] No matching mock found for Postgres sql query: ${queryText}`);
|
|
12806
|
+
}
|
|
12807
|
+
logger.debug(`[PostgresInstrumentation] Found mock data for Postgres sql query: ${JSON.stringify(mockData)}`);
|
|
12808
|
+
const processedResult = this.convertPostgresTypes(mockData.result);
|
|
12809
|
+
logger.debug(`[PostgresInstrumentation] Sql query processed result: ${JSON.stringify(processedResult)}`);
|
|
12810
|
+
return processedResult;
|
|
12811
|
+
}
|
|
12812
|
+
async handleReplayUnsafeQuery({ inputValue, spanInfo, submodule, name, stackTrace }) {
|
|
12813
|
+
logger.debug(`[PostgresInstrumentation] Replaying Postgres unsafe query`);
|
|
12814
|
+
const mockData = await findMockResponseAsync({
|
|
12815
|
+
mockRequestData: {
|
|
12816
|
+
traceId: spanInfo.traceId,
|
|
12817
|
+
spanId: spanInfo.spanId,
|
|
12818
|
+
name,
|
|
12819
|
+
inputValue: createMockInputValue(inputValue),
|
|
12820
|
+
packageName: "postgres",
|
|
12821
|
+
instrumentationName: this.INSTRUMENTATION_NAME,
|
|
12822
|
+
submoduleName: submodule,
|
|
12823
|
+
kind: import_src$25.SpanKind.CLIENT,
|
|
12824
|
+
stackTrace
|
|
12825
|
+
},
|
|
12826
|
+
tuskDrift: this.tuskDrift
|
|
12827
|
+
});
|
|
12828
|
+
if (!mockData) {
|
|
12829
|
+
const queryText = inputValue.query || "UNKNOWN_QUERY";
|
|
12830
|
+
logger.warn(`[PostgresInstrumentation] No mock data found for Postgres unsafe query: ${queryText}`);
|
|
12831
|
+
throw new Error(`[PostgresInstrumentation] No matching mock found for Postgres unsafe query: ${queryText}`);
|
|
12832
|
+
}
|
|
12833
|
+
logger.debug(`[PostgresInstrumentation] Found mock data for Postgres unsafe query: ${JSON.stringify(mockData)}`);
|
|
12834
|
+
const processedResult = this.convertPostgresTypes(mockData.result);
|
|
12835
|
+
logger.debug(`[PostgresInstrumentation] Unsafe query processed result: ${JSON.stringify(processedResult)}`);
|
|
12836
|
+
return processedResult;
|
|
12837
|
+
}
|
|
12838
|
+
convertPostgresTypes(result) {
|
|
12839
|
+
if (!isPostgresOutputValueType(result)) {
|
|
12840
|
+
logger.error(`[PostgresInstrumentation] output value is not of type PostgresOutputValueType`, result);
|
|
12841
|
+
return;
|
|
12842
|
+
}
|
|
12843
|
+
const { rows, count, command } = result;
|
|
12844
|
+
const resultArray = Array.from(rows || []);
|
|
12845
|
+
Object.defineProperties(resultArray, {
|
|
12846
|
+
count: {
|
|
12847
|
+
value: count !== void 0 ? count : null,
|
|
12848
|
+
writable: true,
|
|
12849
|
+
enumerable: false
|
|
12850
|
+
},
|
|
12851
|
+
command: {
|
|
12852
|
+
value: command || null,
|
|
12853
|
+
writable: true,
|
|
12854
|
+
enumerable: false
|
|
12855
|
+
}
|
|
12856
|
+
});
|
|
12857
|
+
return resultArray;
|
|
12858
|
+
}
|
|
12859
|
+
_addOutputAttributesToSpan(spanInfo, result) {
|
|
12860
|
+
if (!result) return;
|
|
12861
|
+
const isArray$1 = Array.isArray(result);
|
|
12862
|
+
logger.debug(`[PostgresInstrumentation] Adding output attributes to span for ${isArray$1 ? "array" : "object"} result`);
|
|
12863
|
+
const outputValue = {
|
|
12864
|
+
rows: isArray$1 ? Array.from(result) : result.rows || [],
|
|
12865
|
+
count: result.count !== void 0 && result.count !== null ? result.count : void 0,
|
|
12866
|
+
command: result.command || void 0
|
|
12867
|
+
};
|
|
12868
|
+
SpanUtils.addSpanAttributes(spanInfo.span, { outputValue });
|
|
12869
|
+
}
|
|
12870
|
+
_wrap(target, propertyName, wrapper) {
|
|
12871
|
+
wrap(target, propertyName, wrapper);
|
|
12872
|
+
}
|
|
12873
|
+
};
|
|
12874
|
+
|
|
12875
|
+
//#endregion
|
|
12876
|
+
//#region src/instrumentation/libraries/mysql/types.ts
|
|
12877
|
+
/**
|
|
12878
|
+
* Helper to check if a result is an OkPacket
|
|
12879
|
+
*/
|
|
12880
|
+
function isMysqlOkPacket(result) {
|
|
12881
|
+
return result && typeof result === "object" && "affectedRows" in result && "insertId" in result && "fieldCount" in result;
|
|
12882
|
+
}
|
|
12883
|
+
|
|
12884
|
+
//#endregion
|
|
12885
|
+
//#region src/instrumentation/libraries/mysql/mocks/TdMysqlConnectionMock.ts
|
|
12886
|
+
/**
|
|
12887
|
+
* Mock MySQL connection/pool connection for replay mode
|
|
12888
|
+
* Extends EventEmitter to properly handle all connection methods and events
|
|
12889
|
+
*/
|
|
12890
|
+
var TdMysqlConnectionMock = class extends events.EventEmitter {
|
|
12891
|
+
constructor(mysqlInstrumentation, clientType = "poolConnection", spanInfo) {
|
|
12892
|
+
super();
|
|
12893
|
+
this.threadId = null;
|
|
12894
|
+
this.config = {
|
|
12895
|
+
host: "localhost",
|
|
12896
|
+
port: 3306,
|
|
12897
|
+
database: "mock",
|
|
12898
|
+
user: "mock"
|
|
12899
|
+
};
|
|
12900
|
+
this.mysqlInstrumentation = mysqlInstrumentation;
|
|
12901
|
+
this.spanInfo = spanInfo;
|
|
12902
|
+
this.clientType = clientType;
|
|
12903
|
+
this.threadId = 1;
|
|
12904
|
+
}
|
|
12905
|
+
query(...args) {
|
|
12906
|
+
logger.debug(`[TdMysqlConnectionMock] Mock connection query intercepted in REPLAY mode`);
|
|
12907
|
+
let sql;
|
|
12908
|
+
let values;
|
|
12909
|
+
let callback;
|
|
12910
|
+
let options = {};
|
|
12911
|
+
if (typeof args[0] === "string") {
|
|
12912
|
+
sql = args[0];
|
|
12913
|
+
if (typeof args[1] === "function") callback = args[1];
|
|
12914
|
+
else if (Array.isArray(args[1])) {
|
|
12915
|
+
values = args[1];
|
|
12916
|
+
callback = args[2];
|
|
12917
|
+
}
|
|
12918
|
+
} else if (typeof args[0] === "object") {
|
|
12919
|
+
options = args[0];
|
|
12920
|
+
sql = options.sql;
|
|
12921
|
+
values = options.values;
|
|
12922
|
+
if (typeof args[1] === "function") callback = args[1];
|
|
12923
|
+
else if (Array.isArray(args[1])) {
|
|
12924
|
+
values = args[1];
|
|
12925
|
+
callback = args[2];
|
|
12926
|
+
}
|
|
12927
|
+
} else {
|
|
12928
|
+
logger.debug(`[TdMysqlConnectionMock] Could not parse mock connection query, returning empty result`);
|
|
12929
|
+
const emptyResult = {
|
|
12930
|
+
rows: [],
|
|
12931
|
+
fields: []
|
|
12932
|
+
};
|
|
12933
|
+
if (callback) {
|
|
12934
|
+
process.nextTick(() => callback(null, emptyResult.rows, emptyResult.fields));
|
|
12935
|
+
return;
|
|
12936
|
+
}
|
|
12937
|
+
return new events.EventEmitter();
|
|
12938
|
+
}
|
|
12939
|
+
const inputValue = {
|
|
12940
|
+
sql,
|
|
12941
|
+
values,
|
|
12942
|
+
options: options.nestTables ? { nestTables: options.nestTables } : void 0
|
|
12943
|
+
};
|
|
12944
|
+
if (this.spanInfo) return this.mysqlInstrumentation.handleReplayQueryFromMock(this.spanInfo, inputValue, callback);
|
|
12945
|
+
else {
|
|
12946
|
+
const emptyResult = {
|
|
12947
|
+
rows: [],
|
|
12948
|
+
fields: []
|
|
12949
|
+
};
|
|
12950
|
+
if (callback) {
|
|
12951
|
+
process.nextTick(() => callback(null, emptyResult.rows, emptyResult.fields));
|
|
12952
|
+
return;
|
|
12953
|
+
}
|
|
12954
|
+
const emitter = new events.EventEmitter();
|
|
12955
|
+
setImmediate(() => {
|
|
12956
|
+
emitter.emit("fields", [], 0);
|
|
12957
|
+
emitter.emit("end");
|
|
12958
|
+
});
|
|
12959
|
+
return emitter;
|
|
12960
|
+
}
|
|
12961
|
+
}
|
|
12962
|
+
release() {
|
|
12963
|
+
this.emit("end");
|
|
12964
|
+
}
|
|
12965
|
+
destroy() {
|
|
12966
|
+
this.emit("end");
|
|
12967
|
+
}
|
|
12968
|
+
end(callback) {
|
|
12969
|
+
this.emit("end");
|
|
12970
|
+
if (callback) {
|
|
12971
|
+
process.nextTick(() => callback(null));
|
|
12972
|
+
return;
|
|
12973
|
+
}
|
|
12974
|
+
}
|
|
12975
|
+
connect(callback) {
|
|
12976
|
+
if (callback) {
|
|
12977
|
+
process.nextTick(() => callback(null));
|
|
12978
|
+
return;
|
|
12979
|
+
}
|
|
12980
|
+
}
|
|
12981
|
+
ping(callback) {
|
|
12982
|
+
if (callback) {
|
|
12983
|
+
process.nextTick(() => callback(null));
|
|
12984
|
+
return;
|
|
12985
|
+
}
|
|
12986
|
+
}
|
|
12987
|
+
beginTransaction(callback) {
|
|
12988
|
+
if (callback) {
|
|
12989
|
+
process.nextTick(() => callback(null));
|
|
12990
|
+
return;
|
|
12991
|
+
}
|
|
12992
|
+
}
|
|
12993
|
+
commit(callback) {
|
|
12994
|
+
if (callback) {
|
|
12995
|
+
process.nextTick(() => callback(null));
|
|
12996
|
+
return;
|
|
12997
|
+
}
|
|
12998
|
+
}
|
|
12999
|
+
rollback(callback) {
|
|
13000
|
+
if (callback) {
|
|
13001
|
+
process.nextTick(() => callback(null));
|
|
13002
|
+
return;
|
|
13003
|
+
}
|
|
13004
|
+
}
|
|
13005
|
+
changeUser(options, callback) {
|
|
13006
|
+
if (callback) {
|
|
13007
|
+
process.nextTick(() => callback(null));
|
|
13008
|
+
return;
|
|
13009
|
+
}
|
|
13010
|
+
}
|
|
13011
|
+
pause() {}
|
|
13012
|
+
resume() {}
|
|
13013
|
+
escape(value) {
|
|
13014
|
+
if (value === null || value === void 0) return "NULL";
|
|
13015
|
+
if (typeof value === "string") return `'${value.replace(/'/g, "''")}'`;
|
|
13016
|
+
if (typeof value === "number") return value.toString();
|
|
13017
|
+
if (typeof value === "boolean") return value ? "1" : "0";
|
|
13018
|
+
if (value instanceof Date) return `'${value.toISOString()}'`;
|
|
13019
|
+
return `'${String(value)}'`;
|
|
13020
|
+
}
|
|
13021
|
+
escapeId(identifier) {
|
|
13022
|
+
return `\`${identifier.replace(/`/g, "``")}\``;
|
|
13023
|
+
}
|
|
13024
|
+
format(sql, values) {
|
|
13025
|
+
if (!values || values.length === 0) return sql;
|
|
13026
|
+
let index = 0;
|
|
13027
|
+
return sql.replace(/\?/g, () => {
|
|
13028
|
+
if (index >= values.length) return "?";
|
|
13029
|
+
return this.escape(values[index++]);
|
|
13030
|
+
});
|
|
13031
|
+
}
|
|
13032
|
+
};
|
|
13033
|
+
|
|
13034
|
+
//#endregion
|
|
13035
|
+
//#region src/instrumentation/libraries/mysql/mocks/TdMysqlQueryMock.ts
|
|
13036
|
+
var import_src$24 = /* @__PURE__ */ __toESM(require_src$7(), 1);
|
|
13037
|
+
/**
|
|
13038
|
+
* Handles replay mode for MySQL query operations
|
|
13039
|
+
* Returns EventEmitters synchronously to support both callback and streaming modes
|
|
13040
|
+
*/
|
|
13041
|
+
var TdMysqlQueryMock = class {
|
|
13042
|
+
constructor() {
|
|
13043
|
+
this.INSTRUMENTATION_NAME = "MysqlInstrumentation";
|
|
13044
|
+
this.tuskDrift = TuskDriftCore.getInstance();
|
|
13045
|
+
}
|
|
13046
|
+
/**
|
|
13047
|
+
* Handle replay of a MySQL query
|
|
13048
|
+
* Always returns an EventEmitter (like mysql does)
|
|
13049
|
+
*/
|
|
13050
|
+
handleReplayQuery(queryConfig, inputValue, spanInfo, stackTrace) {
|
|
13051
|
+
logger.debug(`[MysqlInstrumentation] Replaying MySQL query`);
|
|
13052
|
+
return this._handleQuery(queryConfig, inputValue, spanInfo, stackTrace);
|
|
13053
|
+
}
|
|
13054
|
+
/**
|
|
13055
|
+
* Handle background query requests (outside of trace context)
|
|
13056
|
+
* Returns an EventEmitter that immediately completes with empty results
|
|
13057
|
+
*/
|
|
13058
|
+
handleNoOpReplayQuery(queryConfig) {
|
|
13059
|
+
logger.debug(`[MysqlInstrumentation] Background query detected, returning empty result`);
|
|
13060
|
+
const emitter = new events.EventEmitter();
|
|
13061
|
+
emitter.then = function(onResolve, onReject) {
|
|
13062
|
+
return new Promise((resolve) => {
|
|
13063
|
+
emitter.once("end", () => {
|
|
13064
|
+
resolve([[], []]);
|
|
13065
|
+
});
|
|
13066
|
+
}).then(onResolve, onReject);
|
|
13067
|
+
};
|
|
13068
|
+
process.nextTick(() => {
|
|
13069
|
+
const callback = queryConfig.callback;
|
|
13070
|
+
if (callback) callback(null, [], []);
|
|
13071
|
+
emitter.emit("fields", [], 0);
|
|
13072
|
+
emitter.emit("end");
|
|
13073
|
+
});
|
|
13074
|
+
return emitter;
|
|
13075
|
+
}
|
|
13076
|
+
/**
|
|
13077
|
+
* Handle query - always returns an EventEmitter (like mysql does)
|
|
13078
|
+
* This handles both callback and streaming modes
|
|
13079
|
+
* The EventEmitter is also thenable (has a .then() method) to support await/Promise usage
|
|
13080
|
+
*/
|
|
13081
|
+
_handleQuery(queryConfig, inputValue, spanInfo, stackTrace) {
|
|
13082
|
+
const emitter = new events.EventEmitter();
|
|
13083
|
+
let storedResults = null;
|
|
13084
|
+
let storedFields = null;
|
|
13085
|
+
emitter.then = function(onResolve, onReject) {
|
|
13086
|
+
return new Promise((resolve, reject) => {
|
|
13087
|
+
emitter.once("end", () => {
|
|
13088
|
+
resolve([storedResults, storedFields]);
|
|
13089
|
+
});
|
|
13090
|
+
emitter.once("error", (error) => {
|
|
13091
|
+
reject(error);
|
|
13092
|
+
});
|
|
13093
|
+
}).then(onResolve, onReject);
|
|
13094
|
+
};
|
|
13095
|
+
(async () => {
|
|
13096
|
+
try {
|
|
13097
|
+
const mockData = await this._fetchMockData(inputValue, spanInfo, stackTrace);
|
|
13098
|
+
if (!mockData) {
|
|
13099
|
+
const sql = inputValue.sql || "UNKNOWN_QUERY";
|
|
13100
|
+
logger.warn(`[MysqlInstrumentation] No mock data found for MySQL query: ${sql}`);
|
|
13101
|
+
throw new Error(`[MysqlInstrumentation] No matching mock found for query: ${sql}`);
|
|
13102
|
+
}
|
|
13103
|
+
const outputValue = mockData.result;
|
|
13104
|
+
const results = outputValue.results;
|
|
13105
|
+
const fields = outputValue.fields;
|
|
13106
|
+
const queryCount = outputValue.queryCount || 1;
|
|
13107
|
+
const isMultiStatement = queryCount > 1;
|
|
13108
|
+
storedResults = results;
|
|
13109
|
+
storedFields = fields;
|
|
13110
|
+
process.nextTick(() => {
|
|
13111
|
+
try {
|
|
13112
|
+
if (isMultiStatement) for (let i = 0; i < queryCount; i++) {
|
|
13113
|
+
const resultSet = Array.isArray(results) ? results[i] : results;
|
|
13114
|
+
const fieldSet = Array.isArray(fields) ? fields[i] : fields;
|
|
13115
|
+
if (fieldSet) emitter.emit("fields", fieldSet, i);
|
|
13116
|
+
if (Array.isArray(resultSet)) resultSet.forEach((row) => {
|
|
13117
|
+
emitter.emit("result", row, i);
|
|
13118
|
+
});
|
|
13119
|
+
else emitter.emit("result", resultSet, i);
|
|
13120
|
+
}
|
|
13121
|
+
else {
|
|
13122
|
+
if (fields) emitter.emit("fields", fields, 0);
|
|
13123
|
+
if (Array.isArray(results)) results.forEach((row) => {
|
|
13124
|
+
emitter.emit("result", row, 0);
|
|
13125
|
+
});
|
|
13126
|
+
else emitter.emit("result", results, 0);
|
|
13127
|
+
}
|
|
13128
|
+
if (queryConfig.callback) queryConfig.callback(null, results, fields);
|
|
13129
|
+
emitter.emit("end");
|
|
13130
|
+
} catch (emitError) {
|
|
13131
|
+
logger.error(`[MysqlInstrumentation] Error emitting events: ${emitError}`);
|
|
13132
|
+
emitter.emit("error", emitError);
|
|
13133
|
+
}
|
|
13134
|
+
});
|
|
13135
|
+
} catch (error) {
|
|
13136
|
+
process.nextTick(() => {
|
|
13137
|
+
if (queryConfig.callback) queryConfig.callback(error);
|
|
13138
|
+
emitter.emit("error", error);
|
|
13139
|
+
});
|
|
13140
|
+
}
|
|
13141
|
+
})();
|
|
13142
|
+
return emitter;
|
|
13143
|
+
}
|
|
13144
|
+
/**
|
|
13145
|
+
* Fetch mock data from CLI
|
|
13146
|
+
*/
|
|
13147
|
+
async _fetchMockData(inputValue, spanInfo, stackTrace) {
|
|
13148
|
+
return await findMockResponseAsync({
|
|
13149
|
+
mockRequestData: {
|
|
13150
|
+
traceId: spanInfo.traceId,
|
|
13151
|
+
spanId: spanInfo.spanId,
|
|
13152
|
+
name: "mysql.query",
|
|
13153
|
+
inputValue,
|
|
13154
|
+
packageName: "mysql",
|
|
13155
|
+
instrumentationName: this.INSTRUMENTATION_NAME,
|
|
13156
|
+
submoduleName: "query",
|
|
13157
|
+
kind: import_src$24.SpanKind.CLIENT,
|
|
13158
|
+
stackTrace
|
|
13159
|
+
},
|
|
13160
|
+
tuskDrift: this.tuskDrift
|
|
13161
|
+
});
|
|
13162
|
+
}
|
|
13163
|
+
};
|
|
13164
|
+
|
|
13165
|
+
//#endregion
|
|
13166
|
+
//#region src/instrumentation/libraries/mysql/Instrumentation.ts
|
|
13167
|
+
var import_src$23 = /* @__PURE__ */ __toESM(require_src$7(), 1);
|
|
13168
|
+
var MysqlInstrumentation = class extends TdInstrumentationBase {
|
|
13169
|
+
constructor(config = {}) {
|
|
13170
|
+
super("mysql", config);
|
|
13171
|
+
this.INSTRUMENTATION_NAME = "MysqlInstrumentation";
|
|
13172
|
+
this.createQuery = null;
|
|
13173
|
+
this.mode = config.mode || TuskDriftMode.DISABLED;
|
|
13174
|
+
this.queryMock = new TdMysqlQueryMock();
|
|
13175
|
+
}
|
|
13176
|
+
init() {
|
|
13177
|
+
return [new TdInstrumentationNodeModule({
|
|
13178
|
+
name: "mysql",
|
|
13179
|
+
supportedVersions: ["2.*"],
|
|
13180
|
+
files: [
|
|
13181
|
+
new TdInstrumentationNodeModuleFile({
|
|
13182
|
+
name: "mysql/lib/protocol/sequences/Query.js",
|
|
13183
|
+
supportedVersions: ["2.*"],
|
|
13184
|
+
patch: (moduleExports) => this._patchQueryFile(moduleExports)
|
|
13185
|
+
}),
|
|
13186
|
+
new TdInstrumentationNodeModuleFile({
|
|
13187
|
+
name: "mysql/lib/Connection.js",
|
|
13188
|
+
supportedVersions: ["2.*"],
|
|
13189
|
+
patch: (moduleExports) => this._patchConnectionFile(moduleExports)
|
|
13190
|
+
}),
|
|
13191
|
+
new TdInstrumentationNodeModuleFile({
|
|
13192
|
+
name: "mysql/lib/Pool.js",
|
|
13193
|
+
supportedVersions: ["2.*"],
|
|
13194
|
+
patch: (moduleExports) => this._patchPoolFile(moduleExports)
|
|
13195
|
+
})
|
|
13196
|
+
]
|
|
13197
|
+
})];
|
|
13198
|
+
}
|
|
13199
|
+
/**
|
|
13200
|
+
* Patch Query.prototype.stream method for streaming query support
|
|
13201
|
+
*/
|
|
13202
|
+
_patchQueryFile(QueryClass) {
|
|
13203
|
+
logger.debug(`[MysqlInstrumentation] Patching Query class (file-based)`);
|
|
13204
|
+
if (this.isModulePatched(QueryClass)) {
|
|
13205
|
+
logger.debug(`[MysqlInstrumentation] Query class already patched, skipping`);
|
|
13206
|
+
return QueryClass;
|
|
13207
|
+
}
|
|
13208
|
+
if (QueryClass.prototype && QueryClass.prototype.stream) {
|
|
13209
|
+
if (!isWrapped$1(QueryClass.prototype.stream)) {
|
|
13210
|
+
this._wrap(QueryClass.prototype, "stream", this._getStreamPatchFn());
|
|
13211
|
+
logger.debug(`[MysqlInstrumentation] Wrapped Query.prototype.stream`);
|
|
13212
|
+
}
|
|
13213
|
+
}
|
|
13214
|
+
this.markModuleAsPatched(QueryClass);
|
|
13215
|
+
logger.debug(`[MysqlInstrumentation] Query class patching complete`);
|
|
13216
|
+
return QueryClass;
|
|
13217
|
+
}
|
|
13218
|
+
/**
|
|
13219
|
+
* Patch Connection.prototype methods at the file level
|
|
13220
|
+
* This ensures ALL connection instances have patched methods
|
|
13221
|
+
*/
|
|
13222
|
+
_patchConnectionFile(ConnectionClass) {
|
|
13223
|
+
logger.debug(`[MysqlInstrumentation] Patching Connection class (file-based)`);
|
|
13224
|
+
if (this.isModulePatched(ConnectionClass)) {
|
|
13225
|
+
logger.debug(`[MysqlInstrumentation] Connection class already patched, skipping`);
|
|
13226
|
+
return ConnectionClass;
|
|
13227
|
+
}
|
|
13228
|
+
if (ConnectionClass.createQuery) {
|
|
13229
|
+
this.createQuery = ConnectionClass.createQuery;
|
|
13230
|
+
logger.debug(`[MysqlInstrumentation] Stored Connection.createQuery method`);
|
|
13231
|
+
}
|
|
13232
|
+
if (ConnectionClass.prototype && ConnectionClass.prototype.query) {
|
|
13233
|
+
if (!isWrapped$1(ConnectionClass.prototype.query)) {
|
|
13234
|
+
this._wrap(ConnectionClass.prototype, "query", this._getQueryPatchFn());
|
|
13235
|
+
logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.query`);
|
|
13236
|
+
}
|
|
13237
|
+
}
|
|
13238
|
+
if (ConnectionClass.prototype && ConnectionClass.prototype.connect) {
|
|
13239
|
+
if (!isWrapped$1(ConnectionClass.prototype.connect)) {
|
|
13240
|
+
this._wrap(ConnectionClass.prototype, "connect", this._getConnectPatchFn());
|
|
13241
|
+
logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.connect`);
|
|
13242
|
+
}
|
|
13243
|
+
}
|
|
13244
|
+
if (ConnectionClass.prototype && ConnectionClass.prototype.beginTransaction) {
|
|
13245
|
+
if (!isWrapped$1(ConnectionClass.prototype.beginTransaction)) {
|
|
13246
|
+
this._wrap(ConnectionClass.prototype, "beginTransaction", this._getBeginTransactionPatchFn());
|
|
13247
|
+
logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.beginTransaction`);
|
|
13248
|
+
}
|
|
13249
|
+
}
|
|
13250
|
+
if (ConnectionClass.prototype && ConnectionClass.prototype.commit) {
|
|
13251
|
+
if (!isWrapped$1(ConnectionClass.prototype.commit)) {
|
|
13252
|
+
this._wrap(ConnectionClass.prototype, "commit", this._getCommitPatchFn());
|
|
13253
|
+
logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.commit`);
|
|
13254
|
+
}
|
|
13255
|
+
}
|
|
13256
|
+
if (ConnectionClass.prototype && ConnectionClass.prototype.rollback) {
|
|
13257
|
+
if (!isWrapped$1(ConnectionClass.prototype.rollback)) {
|
|
13258
|
+
this._wrap(ConnectionClass.prototype, "rollback", this._getRollbackPatchFn());
|
|
13259
|
+
logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.rollback`);
|
|
13260
|
+
}
|
|
13261
|
+
}
|
|
13262
|
+
if (ConnectionClass.prototype && ConnectionClass.prototype.ping) {
|
|
13263
|
+
if (!isWrapped$1(ConnectionClass.prototype.ping)) {
|
|
13264
|
+
this._wrap(ConnectionClass.prototype, "ping", this._getPingPatchFn());
|
|
13265
|
+
logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.ping`);
|
|
13266
|
+
}
|
|
13267
|
+
}
|
|
13268
|
+
if (ConnectionClass.prototype && ConnectionClass.prototype.end) {
|
|
13269
|
+
if (!isWrapped$1(ConnectionClass.prototype.end)) {
|
|
13270
|
+
this._wrap(ConnectionClass.prototype, "end", this._getEndPatchFn());
|
|
13271
|
+
logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.end`);
|
|
13272
|
+
}
|
|
13273
|
+
}
|
|
13274
|
+
if (ConnectionClass.prototype && ConnectionClass.prototype.changeUser) {
|
|
13275
|
+
if (!isWrapped$1(ConnectionClass.prototype.changeUser)) {
|
|
13276
|
+
this._wrap(ConnectionClass.prototype, "changeUser", this._getChangeUserPatchFn());
|
|
13277
|
+
logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.changeUser`);
|
|
13278
|
+
}
|
|
13279
|
+
}
|
|
13280
|
+
if (ConnectionClass.prototype && ConnectionClass.prototype.pause) {
|
|
13281
|
+
if (!isWrapped$1(ConnectionClass.prototype.pause)) {
|
|
13282
|
+
this._wrap(ConnectionClass.prototype, "pause", this._getPausePatchFn());
|
|
13283
|
+
logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.pause`);
|
|
13284
|
+
}
|
|
13285
|
+
}
|
|
13286
|
+
if (ConnectionClass.prototype && ConnectionClass.prototype.resume) {
|
|
13287
|
+
if (!isWrapped$1(ConnectionClass.prototype.resume)) {
|
|
13288
|
+
this._wrap(ConnectionClass.prototype, "resume", this._getResumePatchFn());
|
|
13289
|
+
logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.resume`);
|
|
13290
|
+
}
|
|
13291
|
+
}
|
|
13292
|
+
this.markModuleAsPatched(ConnectionClass);
|
|
13293
|
+
logger.debug(`[MysqlInstrumentation] Connection class patching complete`);
|
|
13294
|
+
return ConnectionClass;
|
|
13295
|
+
}
|
|
13296
|
+
/**
|
|
13297
|
+
* Patch Pool.prototype methods at the file level
|
|
13298
|
+
*/
|
|
13299
|
+
_patchPoolFile(PoolClass) {
|
|
13300
|
+
logger.debug(`[MysqlInstrumentation] Patching Pool class (file-based)`);
|
|
13301
|
+
if (this.isModulePatched(PoolClass)) {
|
|
13302
|
+
logger.debug(`[MysqlInstrumentation] Pool class already patched, skipping`);
|
|
13303
|
+
return PoolClass;
|
|
13304
|
+
}
|
|
13305
|
+
if (PoolClass.prototype && PoolClass.prototype.query) {
|
|
13306
|
+
if (!isWrapped$1(PoolClass.prototype.query)) {
|
|
13307
|
+
this._wrap(PoolClass.prototype, "query", this._getQueryPatchFn());
|
|
13308
|
+
logger.debug(`[MysqlInstrumentation] Wrapped Pool.prototype.query`);
|
|
13309
|
+
}
|
|
13310
|
+
}
|
|
13311
|
+
if (PoolClass.prototype && PoolClass.prototype.getConnection) {
|
|
13312
|
+
if (!isWrapped$1(PoolClass.prototype.getConnection)) {
|
|
13313
|
+
this._wrap(PoolClass.prototype, "getConnection", this._getPoolGetConnectionPatchFn());
|
|
13314
|
+
logger.debug(`[MysqlInstrumentation] Wrapped Pool.prototype.getConnection`);
|
|
13315
|
+
}
|
|
13316
|
+
}
|
|
13317
|
+
if (PoolClass.prototype && PoolClass.prototype.end) {
|
|
13318
|
+
if (!isWrapped$1(PoolClass.prototype.end)) {
|
|
13319
|
+
this._wrap(PoolClass.prototype, "end", this._getPoolEndPatchFn());
|
|
13320
|
+
logger.debug(`[MysqlInstrumentation] Wrapped Pool.prototype.end`);
|
|
13321
|
+
}
|
|
13322
|
+
}
|
|
13323
|
+
this.markModuleAsPatched(PoolClass);
|
|
13324
|
+
logger.debug(`[MysqlInstrumentation] Pool class patching complete`);
|
|
13325
|
+
return PoolClass;
|
|
13326
|
+
}
|
|
13327
|
+
/**
|
|
13328
|
+
* Get wrapper function for query method (prototype-level patching)
|
|
13329
|
+
*/
|
|
13330
|
+
_getQueryPatchFn() {
|
|
13331
|
+
const self = this;
|
|
13332
|
+
return (originalQuery) => {
|
|
13333
|
+
return function query(...args) {
|
|
13334
|
+
let sql;
|
|
13335
|
+
let values;
|
|
13336
|
+
let callback;
|
|
13337
|
+
let options = {};
|
|
13338
|
+
if (self.createQuery) try {
|
|
13339
|
+
const queryObj = self.createQuery(...args);
|
|
13340
|
+
sql = queryObj.sql;
|
|
13341
|
+
values = queryObj.values;
|
|
13342
|
+
options = { nestTables: queryObj.nestTables };
|
|
13343
|
+
callback = args.find((arg) => typeof arg === "function");
|
|
13344
|
+
} catch (error) {
|
|
13345
|
+
logger.debug(`[MysqlInstrumentation] Error using createQuery, falling back to manual parsing:`, error);
|
|
13346
|
+
({sql, values, callback, options} = self._parseQueryArgs(args));
|
|
13347
|
+
}
|
|
13348
|
+
else ({sql, values, callback, options} = self._parseQueryArgs(args));
|
|
13349
|
+
const inputValue = {
|
|
13350
|
+
sql,
|
|
13351
|
+
values,
|
|
13352
|
+
options: options.nestTables ? { nestTables: options.nestTables } : void 0
|
|
13353
|
+
};
|
|
13354
|
+
const isEventEmitterMode = !callback;
|
|
13355
|
+
if (self.mode === TuskDriftMode.REPLAY) {
|
|
13356
|
+
const stackTrace = captureStackTrace(["MysqlInstrumentation"]);
|
|
13357
|
+
return handleReplayMode({
|
|
13358
|
+
noOpRequestHandler: () => {
|
|
13359
|
+
if (isEventEmitterMode) return self.queryMock.handleNoOpReplayQuery({
|
|
13360
|
+
sql,
|
|
13361
|
+
values,
|
|
13362
|
+
callback,
|
|
13363
|
+
options
|
|
13364
|
+
});
|
|
13365
|
+
},
|
|
13366
|
+
isServerRequest: false,
|
|
13367
|
+
replayModeHandler: () => {
|
|
13368
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(this, args), {
|
|
13369
|
+
name: "mysql.query",
|
|
13370
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
13371
|
+
submodule: "query",
|
|
13372
|
+
packageType: PackageType.MYSQL,
|
|
13373
|
+
packageName: "mysql",
|
|
13374
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
13375
|
+
inputValue,
|
|
13376
|
+
isPreAppStart: false
|
|
13377
|
+
}, (spanInfo) => {
|
|
13378
|
+
const queryEmitter = self.queryMock.handleReplayQuery({
|
|
13379
|
+
sql,
|
|
13380
|
+
values,
|
|
13381
|
+
callback,
|
|
13382
|
+
options
|
|
13383
|
+
}, inputValue, spanInfo, stackTrace);
|
|
13384
|
+
if (queryEmitter && typeof queryEmitter === "object") queryEmitter.stream = function(streamOptions) {
|
|
13385
|
+
return self._createReplayStreamForQuery(inputValue, spanInfo, stackTrace, queryEmitter, streamOptions);
|
|
13386
|
+
};
|
|
13387
|
+
return queryEmitter;
|
|
13388
|
+
});
|
|
13389
|
+
}
|
|
13390
|
+
});
|
|
13391
|
+
} else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
|
|
13392
|
+
originalFunctionCall: () => originalQuery.apply(this, args),
|
|
13393
|
+
recordModeHandler: ({ isPreAppStart }) => {
|
|
13394
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(this, args), {
|
|
13395
|
+
name: "mysql.query",
|
|
13396
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
13397
|
+
submodule: "query",
|
|
13398
|
+
packageType: PackageType.MYSQL,
|
|
13399
|
+
packageName: "mysql",
|
|
13400
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
13401
|
+
inputValue,
|
|
13402
|
+
isPreAppStart
|
|
13403
|
+
}, (spanInfo) => {
|
|
13404
|
+
return self._handleRecordQuery(spanInfo, originalQuery, this, args, callback, isEventEmitterMode);
|
|
13405
|
+
});
|
|
13406
|
+
},
|
|
13407
|
+
spanKind: import_src$23.SpanKind.CLIENT
|
|
13408
|
+
});
|
|
13409
|
+
else return originalQuery.apply(this, args);
|
|
13410
|
+
};
|
|
13411
|
+
};
|
|
13412
|
+
}
|
|
13413
|
+
/**
|
|
13414
|
+
* Get wrapper function for connect method
|
|
13415
|
+
*/
|
|
13416
|
+
_getConnectPatchFn() {
|
|
13417
|
+
const self = this;
|
|
13418
|
+
return (originalConnect) => {
|
|
13419
|
+
return function connect(callback) {
|
|
13420
|
+
if (self.mode === TuskDriftMode.REPLAY) {
|
|
13421
|
+
const connectionContext = this;
|
|
13422
|
+
return handleReplayMode({
|
|
13423
|
+
noOpRequestHandler: () => {
|
|
13424
|
+
if (callback) setImmediate(() => callback(null));
|
|
13425
|
+
setImmediate(() => connectionContext.emit("connect"));
|
|
13426
|
+
},
|
|
13427
|
+
isServerRequest: false,
|
|
13428
|
+
replayModeHandler: () => {
|
|
13429
|
+
if (callback) setImmediate(() => callback(null));
|
|
13430
|
+
setImmediate(() => connectionContext.emit("connect"));
|
|
13431
|
+
}
|
|
13432
|
+
});
|
|
13433
|
+
} else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
|
|
13434
|
+
originalFunctionCall: () => originalConnect.apply(this, arguments),
|
|
13435
|
+
recordModeHandler: ({ isPreAppStart }) => {
|
|
13436
|
+
return originalConnect.apply(this, arguments);
|
|
13437
|
+
},
|
|
13438
|
+
spanKind: import_src$23.SpanKind.CLIENT
|
|
13439
|
+
});
|
|
13440
|
+
else return originalConnect.apply(this, arguments);
|
|
13441
|
+
};
|
|
13442
|
+
};
|
|
13443
|
+
}
|
|
13444
|
+
/**
|
|
13445
|
+
* Get wrapper function for beginTransaction method
|
|
13446
|
+
*/
|
|
13447
|
+
_getBeginTransactionPatchFn() {
|
|
13448
|
+
const self = this;
|
|
13449
|
+
return (originalBeginTransaction) => {
|
|
13450
|
+
return function beginTransaction(callback) {
|
|
13451
|
+
const inputValue = { query: "BEGIN" };
|
|
13452
|
+
if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
|
|
13453
|
+
noOpRequestHandler: () => {
|
|
13454
|
+
if (callback) setImmediate(() => callback(null));
|
|
13455
|
+
},
|
|
13456
|
+
isServerRequest: false,
|
|
13457
|
+
replayModeHandler: () => {
|
|
13458
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalBeginTransaction.apply(this, arguments), {
|
|
13459
|
+
name: "mysql.beginTransaction",
|
|
13460
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
13461
|
+
submodule: "transaction",
|
|
13462
|
+
packageType: PackageType.MYSQL,
|
|
13463
|
+
packageName: "mysql",
|
|
13464
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
13465
|
+
inputValue,
|
|
13466
|
+
isPreAppStart: false
|
|
13467
|
+
}, (spanInfo) => {
|
|
13468
|
+
return self._handleReplayTransaction(inputValue, callback);
|
|
13469
|
+
});
|
|
13470
|
+
}
|
|
13471
|
+
});
|
|
13472
|
+
else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
|
|
13473
|
+
originalFunctionCall: () => originalBeginTransaction.apply(this, arguments),
|
|
13474
|
+
recordModeHandler: ({ isPreAppStart }) => {
|
|
13475
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalBeginTransaction.apply(this, arguments), {
|
|
13476
|
+
name: "mysql.beginTransaction",
|
|
13477
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
13478
|
+
submodule: "transaction",
|
|
13479
|
+
packageType: PackageType.MYSQL,
|
|
13480
|
+
packageName: "mysql",
|
|
13481
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
13482
|
+
inputValue,
|
|
13483
|
+
isPreAppStart
|
|
13484
|
+
}, (spanInfo) => {
|
|
13485
|
+
return self._handleRecordTransaction(spanInfo, originalBeginTransaction, this, arguments, callback);
|
|
13486
|
+
});
|
|
13487
|
+
},
|
|
13488
|
+
spanKind: import_src$23.SpanKind.CLIENT
|
|
13489
|
+
});
|
|
13490
|
+
else return originalBeginTransaction.apply(this, arguments);
|
|
13491
|
+
};
|
|
13492
|
+
};
|
|
13493
|
+
}
|
|
13494
|
+
/**
|
|
13495
|
+
* Get wrapper function for commit method
|
|
13496
|
+
*/
|
|
13497
|
+
_getCommitPatchFn() {
|
|
13498
|
+
const self = this;
|
|
13499
|
+
return (originalCommit) => {
|
|
13500
|
+
return function commit(callback) {
|
|
13501
|
+
const inputValue = { query: "COMMIT" };
|
|
13502
|
+
if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
|
|
13503
|
+
noOpRequestHandler: () => {
|
|
13504
|
+
if (callback) setImmediate(() => callback(null));
|
|
13505
|
+
},
|
|
13506
|
+
isServerRequest: false,
|
|
13507
|
+
replayModeHandler: () => {
|
|
13508
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalCommit.apply(this, arguments), {
|
|
13509
|
+
name: "mysql.commit",
|
|
13510
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
13511
|
+
submodule: "transaction",
|
|
13512
|
+
packageType: PackageType.MYSQL,
|
|
13513
|
+
packageName: "mysql",
|
|
13514
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
13515
|
+
inputValue,
|
|
13516
|
+
isPreAppStart: false
|
|
13517
|
+
}, (spanInfo) => {
|
|
13518
|
+
return self._handleReplayTransaction(inputValue, callback);
|
|
13519
|
+
});
|
|
13520
|
+
}
|
|
13521
|
+
});
|
|
13522
|
+
else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
|
|
13523
|
+
originalFunctionCall: () => originalCommit.apply(this, arguments),
|
|
13524
|
+
recordModeHandler: ({ isPreAppStart }) => {
|
|
13525
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalCommit.apply(this, arguments), {
|
|
13526
|
+
name: "mysql.commit",
|
|
13527
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
13528
|
+
submodule: "transaction",
|
|
13529
|
+
packageType: PackageType.MYSQL,
|
|
13530
|
+
packageName: "mysql",
|
|
13531
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
13532
|
+
inputValue,
|
|
13533
|
+
isPreAppStart
|
|
13534
|
+
}, (spanInfo) => {
|
|
13535
|
+
return self._handleRecordTransaction(spanInfo, originalCommit, this, arguments, callback);
|
|
13536
|
+
});
|
|
13537
|
+
},
|
|
13538
|
+
spanKind: import_src$23.SpanKind.CLIENT
|
|
13539
|
+
});
|
|
13540
|
+
else return originalCommit.apply(this, arguments);
|
|
13541
|
+
};
|
|
13542
|
+
};
|
|
13543
|
+
}
|
|
13544
|
+
/**
|
|
13545
|
+
* Get wrapper function for rollback method
|
|
13546
|
+
*/
|
|
13547
|
+
_getRollbackPatchFn() {
|
|
13548
|
+
const self = this;
|
|
13549
|
+
return (originalRollback) => {
|
|
13550
|
+
return function rollback(callback) {
|
|
13551
|
+
const inputValue = { query: "ROLLBACK" };
|
|
13552
|
+
if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
|
|
13553
|
+
noOpRequestHandler: () => {
|
|
13554
|
+
if (callback) setImmediate(() => callback(null));
|
|
13555
|
+
},
|
|
13556
|
+
isServerRequest: false,
|
|
13557
|
+
replayModeHandler: () => {
|
|
13558
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalRollback.apply(this, arguments), {
|
|
13559
|
+
name: "mysql.rollback",
|
|
13560
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
13561
|
+
submodule: "transaction",
|
|
13562
|
+
packageType: PackageType.MYSQL,
|
|
13563
|
+
packageName: "mysql",
|
|
13564
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
13565
|
+
inputValue,
|
|
13566
|
+
isPreAppStart: false
|
|
13567
|
+
}, (spanInfo) => {
|
|
13568
|
+
return self._handleReplayTransaction(inputValue, callback);
|
|
13569
|
+
});
|
|
13570
|
+
}
|
|
13571
|
+
});
|
|
13572
|
+
else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
|
|
13573
|
+
originalFunctionCall: () => originalRollback.apply(this, arguments),
|
|
13574
|
+
recordModeHandler: ({ isPreAppStart }) => {
|
|
13575
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalRollback.apply(this, arguments), {
|
|
13576
|
+
name: "mysql.rollback",
|
|
13577
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
13578
|
+
submodule: "transaction",
|
|
13579
|
+
packageType: PackageType.MYSQL,
|
|
13580
|
+
packageName: "mysql",
|
|
13581
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
13582
|
+
inputValue,
|
|
13583
|
+
isPreAppStart
|
|
13584
|
+
}, (spanInfo) => {
|
|
13585
|
+
return self._handleRecordTransaction(spanInfo, originalRollback, this, arguments, callback);
|
|
13586
|
+
});
|
|
13587
|
+
},
|
|
13588
|
+
spanKind: import_src$23.SpanKind.CLIENT
|
|
13589
|
+
});
|
|
13590
|
+
else return originalRollback.apply(this, arguments);
|
|
13591
|
+
};
|
|
13592
|
+
};
|
|
13593
|
+
}
|
|
13594
|
+
/**
|
|
13595
|
+
* Get wrapper function for ping method
|
|
13596
|
+
*/
|
|
13597
|
+
_getPingPatchFn() {
|
|
13598
|
+
const self = this;
|
|
13599
|
+
return (originalPing) => {
|
|
13600
|
+
return function ping(callback) {
|
|
13601
|
+
if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
|
|
13602
|
+
noOpRequestHandler: () => {
|
|
13603
|
+
if (callback) setImmediate(() => callback(null));
|
|
13604
|
+
},
|
|
13605
|
+
isServerRequest: false,
|
|
13606
|
+
replayModeHandler: () => {
|
|
13607
|
+
if (callback) setImmediate(() => callback(null));
|
|
13608
|
+
}
|
|
13609
|
+
});
|
|
13610
|
+
else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
|
|
13611
|
+
originalFunctionCall: () => originalPing.apply(this, arguments),
|
|
13612
|
+
recordModeHandler: ({ isPreAppStart }) => {
|
|
13613
|
+
return originalPing.apply(this, arguments);
|
|
13614
|
+
},
|
|
13615
|
+
spanKind: import_src$23.SpanKind.CLIENT
|
|
13616
|
+
});
|
|
13617
|
+
else return originalPing.apply(this, arguments);
|
|
13618
|
+
};
|
|
13619
|
+
};
|
|
13620
|
+
}
|
|
13621
|
+
/**
|
|
13622
|
+
* Get wrapper function for end method
|
|
13623
|
+
*/
|
|
13624
|
+
_getEndPatchFn() {
|
|
13625
|
+
const self = this;
|
|
13626
|
+
return (originalEnd) => {
|
|
13627
|
+
return function end(callback) {
|
|
13628
|
+
if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
|
|
13629
|
+
noOpRequestHandler: () => {
|
|
13630
|
+
if (callback) setImmediate(() => callback(null));
|
|
13631
|
+
setImmediate(() => this.emit("end"));
|
|
13632
|
+
},
|
|
13633
|
+
isServerRequest: false,
|
|
13634
|
+
replayModeHandler: () => {
|
|
13635
|
+
if (callback) setImmediate(() => callback(null));
|
|
13636
|
+
setImmediate(() => this.emit("end"));
|
|
13637
|
+
}
|
|
13638
|
+
});
|
|
13639
|
+
else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
|
|
13640
|
+
originalFunctionCall: () => originalEnd.apply(this, arguments),
|
|
13641
|
+
recordModeHandler: ({ isPreAppStart }) => {
|
|
13642
|
+
return originalEnd.apply(this, arguments);
|
|
13643
|
+
},
|
|
13644
|
+
spanKind: import_src$23.SpanKind.CLIENT
|
|
13645
|
+
});
|
|
13646
|
+
else return originalEnd.apply(this, arguments);
|
|
13647
|
+
};
|
|
13648
|
+
};
|
|
13649
|
+
}
|
|
13650
|
+
/**
|
|
13651
|
+
* Get wrapper function for changeUser method
|
|
13652
|
+
*/
|
|
13653
|
+
_getChangeUserPatchFn() {
|
|
13654
|
+
const self = this;
|
|
13655
|
+
return (originalChangeUser) => {
|
|
13656
|
+
return function changeUser(options, callback) {
|
|
13657
|
+
let userCallback = callback;
|
|
13658
|
+
if (typeof options === "function") userCallback = options;
|
|
13659
|
+
if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
|
|
13660
|
+
noOpRequestHandler: () => {
|
|
13661
|
+
if (userCallback) setImmediate(() => userCallback(null));
|
|
13662
|
+
},
|
|
13663
|
+
isServerRequest: false,
|
|
13664
|
+
replayModeHandler: () => {
|
|
13665
|
+
if (userCallback) setImmediate(() => userCallback(null));
|
|
13666
|
+
}
|
|
13667
|
+
});
|
|
13668
|
+
else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
|
|
13669
|
+
originalFunctionCall: () => originalChangeUser.apply(this, arguments),
|
|
13670
|
+
recordModeHandler: ({ isPreAppStart }) => {
|
|
13671
|
+
return originalChangeUser.apply(this, arguments);
|
|
13672
|
+
},
|
|
13673
|
+
spanKind: import_src$23.SpanKind.CLIENT
|
|
13674
|
+
});
|
|
13675
|
+
else return originalChangeUser.apply(this, arguments);
|
|
13676
|
+
};
|
|
13677
|
+
};
|
|
13678
|
+
}
|
|
13679
|
+
/**
|
|
13680
|
+
* Get wrapper function for pause method
|
|
13681
|
+
*/
|
|
13682
|
+
_getPausePatchFn() {
|
|
13683
|
+
const self = this;
|
|
13684
|
+
return (originalPause) => {
|
|
13685
|
+
return function pause() {
|
|
13686
|
+
if (self.mode === TuskDriftMode.REPLAY) return;
|
|
13687
|
+
else if (self.mode === TuskDriftMode.RECORD) return originalPause.apply(this, arguments);
|
|
13688
|
+
else return originalPause.apply(this, arguments);
|
|
13689
|
+
};
|
|
13690
|
+
};
|
|
13691
|
+
}
|
|
13692
|
+
/**
|
|
13693
|
+
* Get wrapper function for resume method
|
|
13694
|
+
*/
|
|
13695
|
+
_getResumePatchFn() {
|
|
13696
|
+
const self = this;
|
|
13697
|
+
return (originalResume) => {
|
|
13698
|
+
return function resume() {
|
|
13699
|
+
if (self.mode === TuskDriftMode.REPLAY) return;
|
|
13700
|
+
else if (self.mode === TuskDriftMode.RECORD) return originalResume.apply(this, arguments);
|
|
13701
|
+
else return originalResume.apply(this, arguments);
|
|
13702
|
+
};
|
|
13703
|
+
};
|
|
13704
|
+
}
|
|
13705
|
+
/**
|
|
13706
|
+
* Get wrapper function for Pool.end method
|
|
13707
|
+
*/
|
|
13708
|
+
_getPoolEndPatchFn() {
|
|
13709
|
+
const self = this;
|
|
13710
|
+
return (originalEnd) => {
|
|
13711
|
+
return function end(callback) {
|
|
13712
|
+
if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
|
|
13713
|
+
noOpRequestHandler: () => {
|
|
13714
|
+
if (callback) setImmediate(() => callback(null));
|
|
13715
|
+
},
|
|
13716
|
+
isServerRequest: false,
|
|
13717
|
+
replayModeHandler: () => {
|
|
13718
|
+
if (callback) setImmediate(() => callback(null));
|
|
13719
|
+
}
|
|
13720
|
+
});
|
|
13721
|
+
else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
|
|
13722
|
+
originalFunctionCall: () => originalEnd.apply(this, arguments),
|
|
13723
|
+
recordModeHandler: ({ isPreAppStart }) => {
|
|
13724
|
+
return originalEnd.apply(this, arguments);
|
|
13725
|
+
},
|
|
13726
|
+
spanKind: import_src$23.SpanKind.CLIENT
|
|
13727
|
+
});
|
|
13728
|
+
else return originalEnd.apply(this, arguments);
|
|
13729
|
+
};
|
|
13730
|
+
};
|
|
13731
|
+
}
|
|
13732
|
+
/**
|
|
13733
|
+
* Get wrapper function for Pool.getConnection method
|
|
13734
|
+
*/
|
|
13735
|
+
_getPoolGetConnectionPatchFn() {
|
|
13736
|
+
const self = this;
|
|
13737
|
+
return (originalGetConnection) => {
|
|
13738
|
+
return function getConnection(callback) {
|
|
13739
|
+
const inputValue = { clientType: "pool" };
|
|
13740
|
+
if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
|
|
13741
|
+
noOpRequestHandler: () => {
|
|
13742
|
+
return self._handleNoOpReplayGetConnection(callback);
|
|
13743
|
+
},
|
|
13744
|
+
isServerRequest: false,
|
|
13745
|
+
replayModeHandler: () => {
|
|
13746
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalGetConnection.apply(this, [callback]), {
|
|
13747
|
+
name: `mysql.pool.getConnection`,
|
|
13748
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
13749
|
+
submodule: "getConnection",
|
|
13750
|
+
packageName: "mysql",
|
|
13751
|
+
packageType: PackageType.MYSQL,
|
|
13752
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
13753
|
+
inputValue,
|
|
13754
|
+
isPreAppStart: false
|
|
13755
|
+
}, (spanInfo) => {
|
|
13756
|
+
return self._handleReplayPoolGetConnection(spanInfo, callback);
|
|
13757
|
+
});
|
|
13758
|
+
}
|
|
13759
|
+
});
|
|
13760
|
+
else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
|
|
13761
|
+
originalFunctionCall: () => originalGetConnection.apply(this, [callback]),
|
|
13762
|
+
recordModeHandler: ({ isPreAppStart }) => {
|
|
13763
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalGetConnection.apply(this, [callback]), {
|
|
13764
|
+
name: `mysql.pool.getConnection`,
|
|
13765
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
13766
|
+
submodule: "getConnection",
|
|
13767
|
+
packageName: "mysql",
|
|
13768
|
+
packageType: PackageType.MYSQL,
|
|
13769
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
13770
|
+
inputValue,
|
|
13771
|
+
isPreAppStart
|
|
13772
|
+
}, (spanInfo) => {
|
|
13773
|
+
return self._handleRecordPoolGetConnectionInSpan(spanInfo, originalGetConnection, callback, this);
|
|
13774
|
+
});
|
|
13775
|
+
},
|
|
13776
|
+
spanKind: import_src$23.SpanKind.CLIENT
|
|
13777
|
+
});
|
|
13778
|
+
else return originalGetConnection.apply(this, [callback]);
|
|
13779
|
+
};
|
|
13780
|
+
};
|
|
13781
|
+
}
|
|
13782
|
+
_patchQueryMethod(connection) {
|
|
13783
|
+
const self = this;
|
|
13784
|
+
return (originalQuery) => {
|
|
13785
|
+
return function query(...args) {
|
|
13786
|
+
let sql;
|
|
13787
|
+
let values;
|
|
13788
|
+
let callback;
|
|
13789
|
+
let options = {};
|
|
13790
|
+
if (self.createQuery) try {
|
|
13791
|
+
const queryObj = self.createQuery(...args);
|
|
13792
|
+
sql = queryObj.sql;
|
|
13793
|
+
values = queryObj.values;
|
|
13794
|
+
options = { nestTables: queryObj.nestTables };
|
|
13795
|
+
callback = args.find((arg) => typeof arg === "function");
|
|
13796
|
+
} catch (error) {
|
|
13797
|
+
logger.debug(`[MysqlInstrumentation] Error using createQuery, falling back to manual parsing:`, error);
|
|
13798
|
+
({sql, values, callback, options} = self._parseQueryArgs(args));
|
|
13799
|
+
}
|
|
13800
|
+
else ({sql, values, callback, options} = self._parseQueryArgs(args));
|
|
13801
|
+
const inputValue = {
|
|
13802
|
+
sql,
|
|
13803
|
+
values,
|
|
13804
|
+
options: options.nestTables ? { nestTables: options.nestTables } : void 0
|
|
13805
|
+
};
|
|
13806
|
+
const isEventEmitterMode = !callback;
|
|
13807
|
+
if (self.mode === TuskDriftMode.REPLAY) {
|
|
13808
|
+
const stackTrace = captureStackTrace(["MysqlInstrumentation"]);
|
|
13809
|
+
return handleReplayMode({
|
|
13810
|
+
noOpRequestHandler: () => {
|
|
13811
|
+
if (isEventEmitterMode) return new events.EventEmitter();
|
|
13812
|
+
},
|
|
13813
|
+
isServerRequest: false,
|
|
13814
|
+
replayModeHandler: () => {
|
|
13815
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(connection, args), {
|
|
13816
|
+
name: "mysql.query",
|
|
13817
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
13818
|
+
submodule: "query",
|
|
13819
|
+
packageType: PackageType.MYSQL,
|
|
13820
|
+
packageName: "mysql",
|
|
13821
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
13822
|
+
inputValue,
|
|
13823
|
+
isPreAppStart: false
|
|
13824
|
+
}, (spanInfo) => {
|
|
13825
|
+
const queryEmitter = self.queryMock.handleReplayQuery({
|
|
13826
|
+
sql: inputValue.sql,
|
|
13827
|
+
values: inputValue.values,
|
|
13828
|
+
callback,
|
|
13829
|
+
options: inputValue.options
|
|
13830
|
+
}, inputValue, spanInfo, stackTrace);
|
|
13831
|
+
if (queryEmitter && typeof queryEmitter === "object") queryEmitter.stream = function(streamOptions) {
|
|
13832
|
+
return self._createReplayStreamForQuery(inputValue, spanInfo, stackTrace, queryEmitter, streamOptions);
|
|
13833
|
+
};
|
|
13834
|
+
return queryEmitter;
|
|
13835
|
+
});
|
|
13836
|
+
}
|
|
13837
|
+
});
|
|
13838
|
+
} else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
|
|
13839
|
+
originalFunctionCall: () => originalQuery.apply(connection, args),
|
|
13840
|
+
recordModeHandler: ({ isPreAppStart }) => {
|
|
13841
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(connection, args), {
|
|
13842
|
+
name: "mysql.query",
|
|
13843
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
13844
|
+
submodule: "query",
|
|
13845
|
+
packageType: PackageType.MYSQL,
|
|
13846
|
+
packageName: "mysql",
|
|
13847
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
13848
|
+
inputValue,
|
|
13849
|
+
isPreAppStart
|
|
13850
|
+
}, (spanInfo) => {
|
|
13851
|
+
return self._handleRecordQuery(spanInfo, originalQuery, connection, args, callback, isEventEmitterMode);
|
|
13852
|
+
});
|
|
13853
|
+
},
|
|
13854
|
+
spanKind: import_src$23.SpanKind.CLIENT
|
|
13855
|
+
});
|
|
13856
|
+
else return originalQuery.apply(connection, args);
|
|
13857
|
+
};
|
|
13858
|
+
};
|
|
13859
|
+
}
|
|
13860
|
+
_handleRecordQuery(spanInfo, originalQuery, connection, args, callback, isEventEmitterMode) {
|
|
13861
|
+
if (isEventEmitterMode) {
|
|
13862
|
+
const queryEmitter = originalQuery.apply(connection, args);
|
|
13863
|
+
const results = [];
|
|
13864
|
+
const fields = [];
|
|
13865
|
+
let error = null;
|
|
13866
|
+
let queryIndex = 0;
|
|
13867
|
+
queryEmitter.on("error", (err) => {
|
|
13868
|
+
error = err;
|
|
13869
|
+
queryIndex = queryEmitter._index || queryIndex;
|
|
13870
|
+
logger.debug(`[MysqlInstrumentation] Query error: ${err.message}`);
|
|
13871
|
+
}).on("fields", (fieldPackets, index) => {
|
|
13872
|
+
fields[index] = fieldPackets;
|
|
13873
|
+
}).on("result", (row, index) => {
|
|
13874
|
+
queryIndex = index;
|
|
13875
|
+
if (!results[index]) if (isMysqlOkPacket(row)) results[index] = row;
|
|
13876
|
+
else results[index] = [];
|
|
13877
|
+
if (Array.isArray(results[index])) results[index].push(row);
|
|
13878
|
+
}).on("end", () => {
|
|
13879
|
+
const finalQueryCount = this._getQueryCount(queryEmitter) || queryIndex + 1;
|
|
13880
|
+
const outputValue = finalQueryCount > 1 ? {
|
|
13881
|
+
results,
|
|
13882
|
+
fields,
|
|
13883
|
+
queryCount: finalQueryCount,
|
|
13884
|
+
errQueryIndex: error ? queryIndex : void 0
|
|
13885
|
+
} : {
|
|
13886
|
+
results: results[0],
|
|
13887
|
+
fields: fields[0],
|
|
13888
|
+
queryCount: finalQueryCount
|
|
13889
|
+
};
|
|
13890
|
+
if (error) try {
|
|
13891
|
+
SpanUtils.endSpan(spanInfo.span, {
|
|
13892
|
+
code: import_src$23.SpanStatusCode.ERROR,
|
|
13893
|
+
message: error.message
|
|
13894
|
+
});
|
|
13895
|
+
} catch (error$1) {
|
|
13896
|
+
logger.error(`[MysqlInstrumentation] error ending span:`, error$1);
|
|
13897
|
+
}
|
|
13898
|
+
else try {
|
|
13899
|
+
SpanUtils.addSpanAttributes(spanInfo.span, { outputValue });
|
|
13900
|
+
SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
|
|
13901
|
+
} catch (error$1) {
|
|
13902
|
+
logger.error(`[MysqlInstrumentation] error ending span:`, error$1);
|
|
13903
|
+
}
|
|
13904
|
+
logger.debug(`[MysqlInstrumentation] Query completed`);
|
|
13905
|
+
});
|
|
13906
|
+
return queryEmitter;
|
|
13907
|
+
} else {
|
|
13908
|
+
const originalCallback = callback;
|
|
13909
|
+
const callbackIndex = args.findIndex((arg) => typeof arg === "function");
|
|
13910
|
+
args[callbackIndex] = function(err, results, fields) {
|
|
13911
|
+
if (err) try {
|
|
13912
|
+
SpanUtils.endSpan(spanInfo.span, {
|
|
13913
|
+
code: import_src$23.SpanStatusCode.ERROR,
|
|
13914
|
+
message: err.message
|
|
13915
|
+
});
|
|
13916
|
+
} catch (error) {
|
|
13917
|
+
logger.error(`[MysqlInstrumentation] error ending span:`, error);
|
|
13918
|
+
}
|
|
13919
|
+
else try {
|
|
13920
|
+
const outputValue = {
|
|
13921
|
+
results,
|
|
13922
|
+
fields
|
|
13923
|
+
};
|
|
13924
|
+
SpanUtils.addSpanAttributes(spanInfo.span, { outputValue });
|
|
13925
|
+
SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
|
|
13926
|
+
} catch (error) {
|
|
13927
|
+
logger.error(`[MysqlInstrumentation] error ending span:`, error);
|
|
13928
|
+
}
|
|
13929
|
+
logger.debug(`[MysqlInstrumentation] Query completed`);
|
|
13930
|
+
return originalCallback.apply(this, arguments);
|
|
13931
|
+
};
|
|
13932
|
+
return originalQuery.apply(connection, args);
|
|
13933
|
+
}
|
|
13934
|
+
}
|
|
13935
|
+
_patchConnect(connection) {
|
|
13936
|
+
const self = this;
|
|
13937
|
+
return (originalConnect) => {
|
|
13938
|
+
return function connect(callback) {
|
|
13939
|
+
if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
|
|
13940
|
+
noOpRequestHandler: () => {
|
|
13941
|
+
if (callback) setImmediate(() => callback(null));
|
|
13942
|
+
},
|
|
13943
|
+
isServerRequest: false,
|
|
13944
|
+
replayModeHandler: () => {
|
|
13945
|
+
if (callback) setImmediate(() => callback(null));
|
|
13946
|
+
}
|
|
13947
|
+
});
|
|
13948
|
+
else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
|
|
13949
|
+
originalFunctionCall: () => originalConnect.apply(connection, arguments),
|
|
13950
|
+
recordModeHandler: ({ isPreAppStart }) => {
|
|
13951
|
+
return originalConnect.apply(connection, arguments);
|
|
13952
|
+
},
|
|
13953
|
+
spanKind: import_src$23.SpanKind.CLIENT
|
|
13954
|
+
});
|
|
13955
|
+
else return originalConnect.apply(connection, arguments);
|
|
13956
|
+
};
|
|
13957
|
+
};
|
|
13958
|
+
}
|
|
13959
|
+
_patchBeginTransaction(connection) {
|
|
13960
|
+
const self = this;
|
|
13961
|
+
return (originalBeginTransaction) => {
|
|
13962
|
+
return function beginTransaction(callback) {
|
|
13963
|
+
const inputValue = { query: "BEGIN" };
|
|
13964
|
+
if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
|
|
13965
|
+
noOpRequestHandler: () => {
|
|
13966
|
+
if (callback) setImmediate(() => callback(null));
|
|
13967
|
+
},
|
|
13968
|
+
isServerRequest: false,
|
|
13969
|
+
replayModeHandler: () => {
|
|
13970
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalBeginTransaction.apply(connection, arguments), {
|
|
13971
|
+
name: "mysql.beginTransaction",
|
|
13972
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
13973
|
+
submodule: "transaction",
|
|
13974
|
+
packageType: PackageType.MYSQL,
|
|
13975
|
+
packageName: "mysql",
|
|
13976
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
13977
|
+
inputValue,
|
|
13978
|
+
isPreAppStart: false
|
|
13979
|
+
}, (spanInfo) => {
|
|
13980
|
+
return self._handleReplayTransaction(inputValue, callback);
|
|
13981
|
+
});
|
|
13982
|
+
}
|
|
13983
|
+
});
|
|
13984
|
+
else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
|
|
13985
|
+
originalFunctionCall: () => originalBeginTransaction.apply(connection, arguments),
|
|
13986
|
+
recordModeHandler: ({ isPreAppStart }) => {
|
|
13987
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalBeginTransaction.apply(connection, arguments), {
|
|
13988
|
+
name: "mysql.beginTransaction",
|
|
13989
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
13990
|
+
submodule: "transaction",
|
|
13991
|
+
packageType: PackageType.MYSQL,
|
|
13992
|
+
packageName: "mysql",
|
|
13993
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
13994
|
+
inputValue,
|
|
13995
|
+
isPreAppStart
|
|
13996
|
+
}, (spanInfo) => {
|
|
13997
|
+
return self._handleRecordTransaction(spanInfo, originalBeginTransaction, connection, arguments, callback);
|
|
13998
|
+
});
|
|
13999
|
+
},
|
|
14000
|
+
spanKind: import_src$23.SpanKind.CLIENT
|
|
14001
|
+
});
|
|
14002
|
+
else return originalBeginTransaction.apply(connection, arguments);
|
|
14003
|
+
};
|
|
14004
|
+
};
|
|
14005
|
+
}
|
|
14006
|
+
_patchCommit(connection) {
|
|
14007
|
+
const self = this;
|
|
14008
|
+
return (originalCommit) => {
|
|
14009
|
+
return function commit(callback) {
|
|
14010
|
+
const inputValue = { query: "COMMIT" };
|
|
14011
|
+
if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
|
|
14012
|
+
noOpRequestHandler: () => {
|
|
14013
|
+
if (callback) setImmediate(() => callback(null));
|
|
14014
|
+
},
|
|
14015
|
+
isServerRequest: false,
|
|
14016
|
+
replayModeHandler: () => {
|
|
14017
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalCommit.apply(connection, arguments), {
|
|
14018
|
+
name: "mysql.commit",
|
|
14019
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
14020
|
+
submodule: "transaction",
|
|
14021
|
+
packageType: PackageType.MYSQL,
|
|
14022
|
+
packageName: "mysql",
|
|
14023
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
14024
|
+
inputValue,
|
|
14025
|
+
isPreAppStart: false
|
|
14026
|
+
}, (spanInfo) => {
|
|
14027
|
+
return self._handleReplayTransaction(inputValue, callback);
|
|
14028
|
+
});
|
|
14029
|
+
}
|
|
14030
|
+
});
|
|
14031
|
+
else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
|
|
14032
|
+
originalFunctionCall: () => originalCommit.apply(connection, arguments),
|
|
14033
|
+
recordModeHandler: ({ isPreAppStart }) => {
|
|
14034
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalCommit.apply(connection, arguments), {
|
|
14035
|
+
name: "mysql.commit",
|
|
14036
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
14037
|
+
submodule: "transaction",
|
|
14038
|
+
packageType: PackageType.MYSQL,
|
|
14039
|
+
packageName: "mysql",
|
|
14040
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
14041
|
+
inputValue,
|
|
14042
|
+
isPreAppStart
|
|
14043
|
+
}, (spanInfo) => {
|
|
14044
|
+
return self._handleRecordTransaction(spanInfo, originalCommit, connection, arguments, callback);
|
|
14045
|
+
});
|
|
14046
|
+
},
|
|
14047
|
+
spanKind: import_src$23.SpanKind.CLIENT
|
|
14048
|
+
});
|
|
14049
|
+
else return originalCommit.apply(connection, arguments);
|
|
14050
|
+
};
|
|
14051
|
+
};
|
|
14052
|
+
}
|
|
14053
|
+
_patchRollback(connection) {
|
|
14054
|
+
const self = this;
|
|
14055
|
+
return (originalRollback) => {
|
|
14056
|
+
return function rollback(callback) {
|
|
14057
|
+
const inputValue = { query: "ROLLBACK" };
|
|
14058
|
+
if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
|
|
14059
|
+
noOpRequestHandler: () => {
|
|
14060
|
+
if (callback) setImmediate(() => callback(null));
|
|
14061
|
+
},
|
|
14062
|
+
isServerRequest: false,
|
|
14063
|
+
replayModeHandler: () => {
|
|
14064
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalRollback.apply(connection, arguments), {
|
|
14065
|
+
name: "mysql.rollback",
|
|
14066
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
14067
|
+
submodule: "transaction",
|
|
14068
|
+
packageType: PackageType.MYSQL,
|
|
14069
|
+
packageName: "mysql",
|
|
14070
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
14071
|
+
inputValue,
|
|
14072
|
+
isPreAppStart: false
|
|
14073
|
+
}, (spanInfo) => {
|
|
14074
|
+
return self._handleReplayTransaction(inputValue, callback);
|
|
14075
|
+
});
|
|
14076
|
+
}
|
|
14077
|
+
});
|
|
14078
|
+
else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
|
|
14079
|
+
originalFunctionCall: () => originalRollback.apply(connection, arguments),
|
|
14080
|
+
recordModeHandler: ({ isPreAppStart }) => {
|
|
14081
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalRollback.apply(connection, arguments), {
|
|
14082
|
+
name: "mysql.rollback",
|
|
14083
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
14084
|
+
submodule: "transaction",
|
|
14085
|
+
packageType: PackageType.MYSQL,
|
|
14086
|
+
packageName: "mysql",
|
|
14087
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
14088
|
+
inputValue,
|
|
14089
|
+
isPreAppStart
|
|
14090
|
+
}, (spanInfo) => {
|
|
14091
|
+
return self._handleRecordTransaction(spanInfo, originalRollback, connection, arguments, callback);
|
|
14092
|
+
});
|
|
14093
|
+
},
|
|
14094
|
+
spanKind: import_src$23.SpanKind.CLIENT
|
|
14095
|
+
});
|
|
14096
|
+
else return originalRollback.apply(connection, arguments);
|
|
14097
|
+
};
|
|
14098
|
+
};
|
|
12760
14099
|
}
|
|
12761
|
-
|
|
12762
|
-
try {
|
|
12763
|
-
const result =
|
|
14100
|
+
_handleRecordTransaction(spanInfo, originalFunction, connection, args, callback) {
|
|
14101
|
+
if (!callback) try {
|
|
14102
|
+
const result = originalFunction.apply(connection, args);
|
|
12764
14103
|
try {
|
|
12765
|
-
|
|
12766
|
-
this._addOutputAttributesToSpan(spanInfo, result);
|
|
14104
|
+
SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: { status: "success" } });
|
|
12767
14105
|
SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
|
|
12768
14106
|
} catch (error) {
|
|
12769
|
-
logger.error(`[
|
|
14107
|
+
logger.error(`[MysqlInstrumentation] error adding span attributes:`, error);
|
|
12770
14108
|
}
|
|
12771
14109
|
return result;
|
|
12772
14110
|
} catch (error) {
|
|
12773
14111
|
try {
|
|
12774
|
-
logger.debug(`[PostgresInstrumentation] Postgres query error: ${error.message} (${SpanUtils.getTraceInfo()})`);
|
|
12775
14112
|
SpanUtils.endSpan(spanInfo.span, {
|
|
12776
14113
|
code: import_src$23.SpanStatusCode.ERROR,
|
|
12777
14114
|
message: error.message
|
|
12778
14115
|
});
|
|
12779
|
-
} catch (
|
|
12780
|
-
logger.error(`[
|
|
14116
|
+
} catch (error$1) {
|
|
14117
|
+
logger.error(`[MysqlInstrumentation] error ending span:`, error$1);
|
|
12781
14118
|
}
|
|
12782
14119
|
throw error;
|
|
12783
14120
|
}
|
|
12784
|
-
|
|
12785
|
-
|
|
12786
|
-
|
|
12787
|
-
|
|
12788
|
-
|
|
12789
|
-
|
|
12790
|
-
|
|
12791
|
-
|
|
12792
|
-
|
|
12793
|
-
|
|
12794
|
-
|
|
12795
|
-
|
|
12796
|
-
|
|
12797
|
-
|
|
12798
|
-
|
|
12799
|
-
|
|
12800
|
-
|
|
12801
|
-
|
|
12802
|
-
|
|
12803
|
-
|
|
12804
|
-
|
|
14121
|
+
const argsArray = Array.from(args);
|
|
14122
|
+
const callbackIndex = argsArray.findIndex((arg) => typeof arg === "function");
|
|
14123
|
+
if (callbackIndex !== -1) {
|
|
14124
|
+
const originalCallback = callback;
|
|
14125
|
+
argsArray[callbackIndex] = function(err) {
|
|
14126
|
+
if (err) try {
|
|
14127
|
+
SpanUtils.endSpan(spanInfo.span, {
|
|
14128
|
+
code: import_src$23.SpanStatusCode.ERROR,
|
|
14129
|
+
message: err.message
|
|
14130
|
+
});
|
|
14131
|
+
} catch (error) {
|
|
14132
|
+
logger.error(`[MysqlInstrumentation] error ending span:`, error);
|
|
14133
|
+
}
|
|
14134
|
+
else try {
|
|
14135
|
+
SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: { status: "success" } });
|
|
14136
|
+
SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
|
|
14137
|
+
} catch (error) {
|
|
14138
|
+
logger.error(`[MysqlInstrumentation] error ending span:`, error);
|
|
14139
|
+
}
|
|
14140
|
+
logger.debug(`[MysqlInstrumentation] Transaction completed`);
|
|
14141
|
+
return originalCallback.apply(this, arguments);
|
|
14142
|
+
};
|
|
14143
|
+
argsArray[callbackIndex] = import_src$23.context.bind(spanInfo.context, argsArray[callbackIndex]);
|
|
12805
14144
|
}
|
|
12806
|
-
|
|
12807
|
-
const processedResult = this.convertPostgresTypes(mockData.result);
|
|
12808
|
-
logger.debug(`[PostgresInstrumentation] Sql query processed result: ${JSON.stringify(processedResult)}`);
|
|
12809
|
-
const isResultObject = processedResult && typeof processedResult === "object" && "rows" in processedResult;
|
|
12810
|
-
const rows = isResultObject ? processedResult.rows || [] : processedResult || [];
|
|
12811
|
-
return Object.assign(rows, {
|
|
12812
|
-
command: isResultObject ? processedResult.command : void 0,
|
|
12813
|
-
count: isResultObject ? processedResult.count : void 0
|
|
12814
|
-
});
|
|
14145
|
+
return originalFunction.apply(connection, argsArray);
|
|
12815
14146
|
}
|
|
12816
|
-
async
|
|
12817
|
-
logger.debug(`[
|
|
12818
|
-
|
|
12819
|
-
|
|
12820
|
-
traceId: spanInfo.traceId,
|
|
12821
|
-
spanId: spanInfo.spanId,
|
|
12822
|
-
name,
|
|
12823
|
-
inputValue,
|
|
12824
|
-
packageName: "postgres",
|
|
12825
|
-
instrumentationName: this.INSTRUMENTATION_NAME,
|
|
12826
|
-
submoduleName: submodule,
|
|
12827
|
-
kind: import_src$23.SpanKind.CLIENT,
|
|
12828
|
-
stackTrace
|
|
12829
|
-
},
|
|
12830
|
-
tuskDrift: this.tuskDrift
|
|
14147
|
+
async _handleReplayTransaction(inputValue, callback) {
|
|
14148
|
+
logger.debug(`[MysqlInstrumentation] Replaying MySQL transaction: ${inputValue.query}`);
|
|
14149
|
+
if (callback) setImmediate(() => {
|
|
14150
|
+
callback(null);
|
|
12831
14151
|
});
|
|
12832
|
-
if (!mockData) {
|
|
12833
|
-
const queryText = inputValue.query || "UNKNOWN_QUERY";
|
|
12834
|
-
logger.warn(`[PostgresInstrumentation] No mock data found for Postgres unsafe query: ${queryText}`);
|
|
12835
|
-
throw new Error(`[PostgresInstrumentation] No matching mock found for Postgres unsafe query: ${queryText}`);
|
|
12836
|
-
}
|
|
12837
|
-
logger.debug(`[PostgresInstrumentation] Found mock data for Postgres unsafe query: ${JSON.stringify(mockData)}`);
|
|
12838
|
-
const processedResult = this.convertPostgresTypes(mockData.result);
|
|
12839
|
-
logger.debug(`[PostgresInstrumentation] Unsafe query processed result: ${JSON.stringify(processedResult)}`);
|
|
12840
|
-
return processedResult;
|
|
12841
14152
|
}
|
|
12842
|
-
|
|
12843
|
-
|
|
12844
|
-
|
|
12845
|
-
|
|
12846
|
-
|
|
12847
|
-
|
|
12848
|
-
|
|
12849
|
-
|
|
12850
|
-
|
|
12851
|
-
|
|
12852
|
-
|
|
12853
|
-
|
|
12854
|
-
|
|
12855
|
-
|
|
12856
|
-
|
|
12857
|
-
|
|
12858
|
-
|
|
12859
|
-
|
|
12860
|
-
|
|
12861
|
-
|
|
12862
|
-
|
|
12863
|
-
|
|
12864
|
-
|
|
12865
|
-
|
|
12866
|
-
|
|
12867
|
-
|
|
14153
|
+
_handleRecordPoolGetConnectionInSpan(spanInfo, originalGetConnection, callback, context$6) {
|
|
14154
|
+
const self = this;
|
|
14155
|
+
if (callback) {
|
|
14156
|
+
const wrappedCallback = (error, connection) => {
|
|
14157
|
+
if (error) {
|
|
14158
|
+
logger.debug(`[MysqlInstrumentation] MySQL Pool getConnection error: ${error.message} (${SpanUtils.getTraceInfo()})`);
|
|
14159
|
+
SpanUtils.endSpan(spanInfo.span, {
|
|
14160
|
+
code: import_src$23.SpanStatusCode.ERROR,
|
|
14161
|
+
message: error.message
|
|
14162
|
+
});
|
|
14163
|
+
} else {
|
|
14164
|
+
logger.debug(`[MysqlInstrumentation] MySQL Pool getConnection completed successfully (${SpanUtils.getTraceInfo()})`);
|
|
14165
|
+
if (connection) {
|
|
14166
|
+
self._wrap(connection, "query", self._patchQueryMethod(connection));
|
|
14167
|
+
self._wrap(connection, "connect", self._patchConnect(connection));
|
|
14168
|
+
self._wrap(connection, "beginTransaction", self._patchBeginTransaction(connection));
|
|
14169
|
+
self._wrap(connection, "commit", self._patchCommit(connection));
|
|
14170
|
+
self._wrap(connection, "rollback", self._patchRollback(connection));
|
|
14171
|
+
}
|
|
14172
|
+
SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: {
|
|
14173
|
+
connected: true,
|
|
14174
|
+
hasConnection: !!connection
|
|
14175
|
+
} });
|
|
14176
|
+
SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
|
|
14177
|
+
}
|
|
14178
|
+
return callback(error, connection);
|
|
14179
|
+
};
|
|
14180
|
+
return originalGetConnection.call(context$6, wrappedCallback);
|
|
14181
|
+
} else try {
|
|
14182
|
+
const result = originalGetConnection.call(context$6);
|
|
14183
|
+
SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: {
|
|
14184
|
+
connected: true,
|
|
14185
|
+
hasConnection: true
|
|
14186
|
+
} });
|
|
14187
|
+
SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
|
|
14188
|
+
return result;
|
|
14189
|
+
} catch (error) {
|
|
14190
|
+
SpanUtils.endSpan(spanInfo.span, {
|
|
14191
|
+
code: import_src$23.SpanStatusCode.ERROR,
|
|
14192
|
+
message: error.message
|
|
12868
14193
|
});
|
|
12869
|
-
|
|
14194
|
+
throw error;
|
|
14195
|
+
}
|
|
12870
14196
|
}
|
|
12871
|
-
|
|
12872
|
-
|
|
12873
|
-
|
|
12874
|
-
|
|
12875
|
-
|
|
12876
|
-
if (!isPostgresOutputValueType(result)) {
|
|
12877
|
-
logger.error(`[PostgresInstrumentation] output value is not of type PostgresOutputValueType: ${JSON.stringify(result)}`);
|
|
14197
|
+
_handleNoOpReplayGetConnection(callback) {
|
|
14198
|
+
logger.debug(`[MysqlInstrumentation] Background getConnection detected, returning mock connection`);
|
|
14199
|
+
const mockConnection = new TdMysqlConnectionMock(this, "pool");
|
|
14200
|
+
if (callback) {
|
|
14201
|
+
process.nextTick(() => callback(null, mockConnection));
|
|
12878
14202
|
return;
|
|
12879
14203
|
}
|
|
12880
|
-
|
|
12881
|
-
|
|
12882
|
-
|
|
12883
|
-
|
|
12884
|
-
|
|
12885
|
-
|
|
14204
|
+
return mockConnection;
|
|
14205
|
+
}
|
|
14206
|
+
_handleReplayPoolGetConnection(spanInfo, callback) {
|
|
14207
|
+
logger.debug(`[MysqlInstrumentation] Replaying MySQL Pool getConnection`);
|
|
14208
|
+
const mockConnection = new TdMysqlConnectionMock(this, "pool", spanInfo);
|
|
14209
|
+
if (callback) {
|
|
14210
|
+
process.nextTick(() => callback(null, mockConnection));
|
|
12886
14211
|
return;
|
|
12887
14212
|
}
|
|
14213
|
+
return mockConnection;
|
|
12888
14214
|
}
|
|
12889
|
-
|
|
12890
|
-
|
|
12891
|
-
|
|
12892
|
-
|
|
12893
|
-
|
|
12894
|
-
|
|
12895
|
-
|
|
12896
|
-
|
|
12897
|
-
|
|
12898
|
-
|
|
12899
|
-
|
|
12900
|
-
|
|
12901
|
-
|
|
12902
|
-
|
|
12903
|
-
|
|
12904
|
-
|
|
14215
|
+
/**
|
|
14216
|
+
* Handle replay of a query from a mock connection (used by TdMysqlConnectionMock)
|
|
14217
|
+
* Returns an EventEmitter synchronously for streaming support
|
|
14218
|
+
*/
|
|
14219
|
+
handleReplayQueryFromMock(spanInfo, inputValue, callback) {
|
|
14220
|
+
const stackTrace = captureStackTrace(["TdMysqlConnectionMock"]);
|
|
14221
|
+
return this.queryMock.handleReplayQuery({
|
|
14222
|
+
sql: inputValue.sql,
|
|
14223
|
+
values: inputValue.values,
|
|
14224
|
+
callback,
|
|
14225
|
+
options: inputValue.options
|
|
14226
|
+
}, inputValue, spanInfo, stackTrace);
|
|
14227
|
+
}
|
|
14228
|
+
/**
|
|
14229
|
+
* Get wrapper function for Query.stream method
|
|
14230
|
+
*/
|
|
14231
|
+
_getStreamPatchFn() {
|
|
14232
|
+
const self = this;
|
|
14233
|
+
return (originalStream) => {
|
|
14234
|
+
return function stream$1(streamOptions) {
|
|
14235
|
+
const queryInstance = this;
|
|
14236
|
+
const sql = queryInstance.sql;
|
|
14237
|
+
const values = queryInstance.values;
|
|
14238
|
+
const nestTables = queryInstance.nestTables;
|
|
14239
|
+
const inputValue = {
|
|
14240
|
+
sql,
|
|
14241
|
+
values,
|
|
14242
|
+
streamOptions,
|
|
14243
|
+
options: nestTables ? { nestTables } : void 0
|
|
14244
|
+
};
|
|
14245
|
+
if (self.mode === TuskDriftMode.REPLAY) {
|
|
14246
|
+
const stackTrace = captureStackTrace(["MysqlInstrumentation"]);
|
|
14247
|
+
return handleReplayMode({
|
|
14248
|
+
noOpRequestHandler: () => {
|
|
14249
|
+
return new stream.Readable({
|
|
14250
|
+
objectMode: true,
|
|
14251
|
+
read() {
|
|
14252
|
+
this.push(null);
|
|
14253
|
+
}
|
|
14254
|
+
});
|
|
14255
|
+
},
|
|
14256
|
+
isServerRequest: false,
|
|
14257
|
+
replayModeHandler: () => {
|
|
14258
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalStream.apply(queryInstance, arguments), {
|
|
14259
|
+
name: "mysql.stream",
|
|
14260
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
14261
|
+
submodule: "stream",
|
|
14262
|
+
packageType: PackageType.MYSQL,
|
|
14263
|
+
packageName: "mysql",
|
|
14264
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
14265
|
+
inputValue,
|
|
14266
|
+
isPreAppStart: false
|
|
14267
|
+
}, (spanInfo) => {
|
|
14268
|
+
return self._handleReplayStream(inputValue, spanInfo, stackTrace, queryInstance);
|
|
14269
|
+
});
|
|
14270
|
+
}
|
|
14271
|
+
});
|
|
14272
|
+
} else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
|
|
14273
|
+
originalFunctionCall: () => originalStream.apply(queryInstance, arguments),
|
|
14274
|
+
recordModeHandler: ({ isPreAppStart }) => {
|
|
14275
|
+
return SpanUtils.createAndExecuteSpan(self.mode, () => originalStream.apply(queryInstance, arguments), {
|
|
14276
|
+
name: "mysql.stream",
|
|
14277
|
+
kind: import_src$23.SpanKind.CLIENT,
|
|
14278
|
+
submodule: "stream",
|
|
14279
|
+
packageType: PackageType.MYSQL,
|
|
14280
|
+
packageName: "mysql",
|
|
14281
|
+
instrumentationName: self.INSTRUMENTATION_NAME,
|
|
14282
|
+
inputValue,
|
|
14283
|
+
isPreAppStart
|
|
14284
|
+
}, (spanInfo) => {
|
|
14285
|
+
return self._handleRecordStream(spanInfo, originalStream, queryInstance, streamOptions);
|
|
14286
|
+
});
|
|
14287
|
+
},
|
|
14288
|
+
spanKind: import_src$23.SpanKind.CLIENT
|
|
14289
|
+
});
|
|
14290
|
+
else return originalStream.apply(queryInstance, arguments);
|
|
12905
14291
|
};
|
|
14292
|
+
};
|
|
14293
|
+
}
|
|
14294
|
+
/**
|
|
14295
|
+
* Helper to get query count from Query instance
|
|
14296
|
+
*/
|
|
14297
|
+
_getQueryCount(queryInstance) {
|
|
14298
|
+
return queryInstance?._index || 0;
|
|
14299
|
+
}
|
|
14300
|
+
/**
|
|
14301
|
+
* Parse query arguments manually (fallback when createQuery is not available)
|
|
14302
|
+
*/
|
|
14303
|
+
_parseQueryArgs(args) {
|
|
14304
|
+
let sql;
|
|
14305
|
+
let values;
|
|
14306
|
+
let callback;
|
|
14307
|
+
let options = {};
|
|
14308
|
+
if (typeof args[0] === "string") {
|
|
14309
|
+
sql = args[0];
|
|
14310
|
+
if (typeof args[1] === "function") callback = args[1];
|
|
14311
|
+
else if (Array.isArray(args[1])) {
|
|
14312
|
+
values = args[1];
|
|
14313
|
+
callback = args[2];
|
|
14314
|
+
}
|
|
14315
|
+
} else if (typeof args[0] === "object") {
|
|
14316
|
+
options = args[0];
|
|
14317
|
+
sql = options.sql;
|
|
14318
|
+
values = options.values;
|
|
14319
|
+
if (typeof args[1] === "function") callback = args[1];
|
|
14320
|
+
else if (Array.isArray(args[1])) {
|
|
14321
|
+
values = args[1];
|
|
14322
|
+
callback = args[2];
|
|
14323
|
+
}
|
|
12906
14324
|
} else {
|
|
12907
|
-
|
|
12908
|
-
|
|
14325
|
+
sql = "";
|
|
14326
|
+
logger.debug(`[MysqlInstrumentation] Unknown query signature:`, args);
|
|
12909
14327
|
}
|
|
12910
|
-
|
|
14328
|
+
return {
|
|
14329
|
+
sql,
|
|
14330
|
+
values,
|
|
14331
|
+
callback,
|
|
14332
|
+
options
|
|
14333
|
+
};
|
|
14334
|
+
}
|
|
14335
|
+
/**
|
|
14336
|
+
* Handle record mode for stream operations
|
|
14337
|
+
*/
|
|
14338
|
+
_handleRecordStream(spanInfo, originalStream, queryInstance, streamOptions) {
|
|
14339
|
+
const streamInstance = originalStream.apply(queryInstance, [streamOptions]);
|
|
14340
|
+
const results = [];
|
|
14341
|
+
const fields = [];
|
|
14342
|
+
let error = null;
|
|
14343
|
+
let errQueryIndex;
|
|
14344
|
+
queryInstance.on("error", (err) => {
|
|
14345
|
+
error = err;
|
|
14346
|
+
errQueryIndex = queryInstance._index;
|
|
14347
|
+
}).on("fields", (fieldPackets, index) => {
|
|
14348
|
+
fields[index] = fieldPackets;
|
|
14349
|
+
}).on("result", (row, index) => {
|
|
14350
|
+
if (isMysqlOkPacket(row)) {
|
|
14351
|
+
results[index] = row;
|
|
14352
|
+
return;
|
|
14353
|
+
}
|
|
14354
|
+
if (!results[index]) results[index] = [];
|
|
14355
|
+
if (Array.isArray(results[index])) results[index].push(row);
|
|
14356
|
+
}).on("end", () => {
|
|
14357
|
+
const queryCount = this._getQueryCount(queryInstance);
|
|
14358
|
+
const isMultiStatementQuery = queryCount > 1;
|
|
14359
|
+
if (error) try {
|
|
14360
|
+
SpanUtils.endSpan(spanInfo.span, {
|
|
14361
|
+
code: import_src$23.SpanStatusCode.ERROR,
|
|
14362
|
+
message: error.message
|
|
14363
|
+
});
|
|
14364
|
+
} catch (err) {
|
|
14365
|
+
logger.error(`[MysqlInstrumentation] error ending span:`, err);
|
|
14366
|
+
}
|
|
14367
|
+
else try {
|
|
14368
|
+
const outputValue = isMultiStatementQuery ? {
|
|
14369
|
+
results,
|
|
14370
|
+
fields,
|
|
14371
|
+
queryCount,
|
|
14372
|
+
errQueryIndex
|
|
14373
|
+
} : {
|
|
14374
|
+
results: results[0],
|
|
14375
|
+
fields: fields[0],
|
|
14376
|
+
queryCount
|
|
14377
|
+
};
|
|
14378
|
+
SpanUtils.addSpanAttributes(spanInfo.span, { outputValue });
|
|
14379
|
+
SpanUtils.endSpan(spanInfo.span, { code: import_src$23.SpanStatusCode.OK });
|
|
14380
|
+
} catch (err) {
|
|
14381
|
+
logger.error(`[MysqlInstrumentation] error ending span:`, err);
|
|
14382
|
+
}
|
|
14383
|
+
logger.debug(`[MysqlInstrumentation] Stream query completed`);
|
|
14384
|
+
});
|
|
14385
|
+
return streamInstance;
|
|
14386
|
+
}
|
|
14387
|
+
/**
|
|
14388
|
+
* Create a replay stream for query.stream() calls
|
|
14389
|
+
* This is called when user calls query.stream() on a query object
|
|
14390
|
+
*/
|
|
14391
|
+
_createReplayStreamForQuery(inputValue, spanInfo, stackTrace, queryEmitter, streamOptions) {
|
|
14392
|
+
logger.debug(`[MysqlInstrumentation] Creating replay stream for query.stream()`);
|
|
14393
|
+
const readableStream = new stream.Readable({
|
|
14394
|
+
objectMode: true,
|
|
14395
|
+
read() {}
|
|
14396
|
+
});
|
|
14397
|
+
queryEmitter.on("fields", (fields, index) => {
|
|
14398
|
+
logger.debug(`[MysqlInstrumentation] Stream received fields`);
|
|
14399
|
+
});
|
|
14400
|
+
queryEmitter.on("result", (row, index) => {
|
|
14401
|
+
readableStream.push(row);
|
|
14402
|
+
});
|
|
14403
|
+
queryEmitter.on("error", (err) => {
|
|
14404
|
+
readableStream.destroy(err);
|
|
14405
|
+
});
|
|
14406
|
+
queryEmitter.on("end", () => {
|
|
14407
|
+
readableStream.push(null);
|
|
14408
|
+
});
|
|
14409
|
+
return readableStream;
|
|
14410
|
+
}
|
|
14411
|
+
/**
|
|
14412
|
+
* Handle replay mode for stream operations
|
|
14413
|
+
*/
|
|
14414
|
+
_handleReplayStream(inputValue, spanInfo, stackTrace, queryInstance) {
|
|
14415
|
+
logger.debug(`[MysqlInstrumentation] Replaying MySQL stream query`);
|
|
14416
|
+
const emitter = this.queryMock.handleReplayQuery({
|
|
14417
|
+
sql: inputValue.sql,
|
|
14418
|
+
values: inputValue.values,
|
|
14419
|
+
callback: void 0,
|
|
14420
|
+
options: inputValue.options
|
|
14421
|
+
}, inputValue, spanInfo, stackTrace);
|
|
14422
|
+
const readableStream = new stream.Readable({
|
|
14423
|
+
objectMode: true,
|
|
14424
|
+
read() {}
|
|
14425
|
+
});
|
|
14426
|
+
emitter.on("fields", (fields, index) => {
|
|
14427
|
+
queryInstance.emit("fields", fields, index);
|
|
14428
|
+
});
|
|
14429
|
+
emitter.on("result", (row, index) => {
|
|
14430
|
+
readableStream.push(row);
|
|
14431
|
+
queryInstance.emit("result", row, index);
|
|
14432
|
+
});
|
|
14433
|
+
emitter.on("error", (err) => {
|
|
14434
|
+
readableStream.destroy(err);
|
|
14435
|
+
queryInstance.emit("error", err);
|
|
14436
|
+
});
|
|
14437
|
+
emitter.on("end", () => {
|
|
14438
|
+
readableStream.push(null);
|
|
14439
|
+
queryInstance.emit("end");
|
|
14440
|
+
});
|
|
14441
|
+
return readableStream;
|
|
12911
14442
|
}
|
|
12912
14443
|
_wrap(target, propertyName, wrapper) {
|
|
12913
14444
|
wrap(target, propertyName, wrapper);
|
|
@@ -13775,7 +15306,7 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
|
|
|
13775
15306
|
};
|
|
13776
15307
|
};
|
|
13777
15308
|
}
|
|
13778
|
-
_handleSimpleCallbackMethod(spanInfo, originalMethod, callback, context$
|
|
15309
|
+
_handleSimpleCallbackMethod(spanInfo, originalMethod, callback, context$6) {
|
|
13779
15310
|
if (callback) {
|
|
13780
15311
|
const wrappedCallback = (error) => {
|
|
13781
15312
|
if (error) {
|
|
@@ -13799,9 +15330,9 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
|
|
|
13799
15330
|
}
|
|
13800
15331
|
return callback(error);
|
|
13801
15332
|
};
|
|
13802
|
-
return originalMethod.call(context$
|
|
15333
|
+
return originalMethod.call(context$6, wrappedCallback);
|
|
13803
15334
|
} else {
|
|
13804
|
-
const result = originalMethod.call(context$
|
|
15335
|
+
const result = originalMethod.call(context$6);
|
|
13805
15336
|
if (result && typeof result.then === "function") return result.then(() => {
|
|
13806
15337
|
logger.debug(`[Mysql2Instrumentation] MySQL2 method completed successfully (${SpanUtils.getTraceInfo()})`);
|
|
13807
15338
|
try {
|
|
@@ -13853,7 +15384,7 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
|
|
|
13853
15384
|
};
|
|
13854
15385
|
return null;
|
|
13855
15386
|
}
|
|
13856
|
-
_handleRecordQueryInSpan(spanInfo, originalQuery, queryConfig, args, context$
|
|
15387
|
+
_handleRecordQueryInSpan(spanInfo, originalQuery, queryConfig, args, context$6) {
|
|
13857
15388
|
if (!!queryConfig.callback) {
|
|
13858
15389
|
const originalCallback = queryConfig.callback;
|
|
13859
15390
|
const wrappedCallback = (error, results, fields) => {
|
|
@@ -13891,9 +15422,9 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
|
|
|
13891
15422
|
} catch (error) {
|
|
13892
15423
|
logger.error(`[Mysql2Instrumentation] error replacing callback:`, error, args);
|
|
13893
15424
|
}
|
|
13894
|
-
return originalQuery.apply(context$
|
|
15425
|
+
return originalQuery.apply(context$6, args);
|
|
13895
15426
|
} else {
|
|
13896
|
-
const result = originalQuery.apply(context$
|
|
15427
|
+
const result = originalQuery.apply(context$6, args);
|
|
13897
15428
|
if (result && typeof result.on === "function") {
|
|
13898
15429
|
const streamResults = [];
|
|
13899
15430
|
let streamFields = null;
|
|
@@ -13930,7 +15461,7 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
|
|
|
13930
15461
|
handleNoOpReplayQuery(queryConfig) {
|
|
13931
15462
|
return this.queryMock.handleNoOpReplayQuery(queryConfig);
|
|
13932
15463
|
}
|
|
13933
|
-
_handleRecordPoolGetConnectionInSpan(spanInfo, originalGetConnection, callback, context$
|
|
15464
|
+
_handleRecordPoolGetConnectionInSpan(spanInfo, originalGetConnection, callback, context$6) {
|
|
13934
15465
|
if (callback) {
|
|
13935
15466
|
const wrappedCallback = (error, connection) => {
|
|
13936
15467
|
if (error) {
|
|
@@ -13957,8 +15488,8 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
|
|
|
13957
15488
|
}
|
|
13958
15489
|
return callback(error, connection);
|
|
13959
15490
|
};
|
|
13960
|
-
return originalGetConnection.call(context$
|
|
13961
|
-
} else return originalGetConnection.call(context$
|
|
15491
|
+
return originalGetConnection.call(context$6, wrappedCallback);
|
|
15492
|
+
} else return originalGetConnection.call(context$6).then((connection) => {
|
|
13962
15493
|
logger.debug(`[Mysql2Instrumentation] MySQL2 Pool getConnection completed successfully (${SpanUtils.getTraceInfo()})`);
|
|
13963
15494
|
try {
|
|
13964
15495
|
SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: {
|
|
@@ -14438,7 +15969,7 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
|
|
|
14438
15969
|
else if (args.length >= 4 && typeof args[2] === "object") config.options = args[2];
|
|
14439
15970
|
return config;
|
|
14440
15971
|
}
|
|
14441
|
-
_handleRecordVerifyInSpan(spanInfo, originalVerify, verifyConfig, args, context$
|
|
15972
|
+
_handleRecordVerifyInSpan(spanInfo, originalVerify, verifyConfig, args, context$6) {
|
|
14442
15973
|
if (!!verifyConfig.callback) {
|
|
14443
15974
|
const originalCallback = verifyConfig.callback;
|
|
14444
15975
|
const wrappedCallback = (error, decoded) => {
|
|
@@ -14467,7 +15998,7 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
|
|
|
14467
15998
|
logger.error(`[JsonwebtokenInstrumentation] error replacing callback:`, error, args);
|
|
14468
15999
|
}
|
|
14469
16000
|
try {
|
|
14470
|
-
return originalVerify.apply(context$
|
|
16001
|
+
return originalVerify.apply(context$6, args);
|
|
14471
16002
|
} catch (error) {
|
|
14472
16003
|
try {
|
|
14473
16004
|
logger.debug(`[JsonwebtokenInstrumentation] JWT verify sync error: ${error.message} (${SpanUtils.getTraceInfo()})`);
|
|
@@ -14482,7 +16013,7 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
|
|
|
14482
16013
|
throw error;
|
|
14483
16014
|
}
|
|
14484
16015
|
} else try {
|
|
14485
|
-
const result = originalVerify.apply(context$
|
|
16016
|
+
const result = originalVerify.apply(context$6, args);
|
|
14486
16017
|
try {
|
|
14487
16018
|
logger.debug(`[JsonwebtokenInstrumentation] JWT verify completed successfully (${SpanUtils.getTraceInfo()})`);
|
|
14488
16019
|
this._addOutputAttributesToSpan(spanInfo, result);
|
|
@@ -14505,7 +16036,7 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
|
|
|
14505
16036
|
throw error;
|
|
14506
16037
|
}
|
|
14507
16038
|
}
|
|
14508
|
-
_handleRecordSignInSpan(spanInfo, originalSign, signConfig, args, context$
|
|
16039
|
+
_handleRecordSignInSpan(spanInfo, originalSign, signConfig, args, context$6) {
|
|
14509
16040
|
if (!!signConfig.callback) {
|
|
14510
16041
|
const originalCallback = signConfig.callback;
|
|
14511
16042
|
const wrappedCallback = (error, token) => {
|
|
@@ -14533,9 +16064,9 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
|
|
|
14533
16064
|
} catch (error) {
|
|
14534
16065
|
logger.error(`[JsonwebtokenInstrumentation] error replacing callback:`, error, args);
|
|
14535
16066
|
}
|
|
14536
|
-
return originalSign.apply(context$
|
|
16067
|
+
return originalSign.apply(context$6, args);
|
|
14537
16068
|
} else try {
|
|
14538
|
-
const result = originalSign.apply(context$
|
|
16069
|
+
const result = originalSign.apply(context$6, args);
|
|
14539
16070
|
try {
|
|
14540
16071
|
logger.debug(`[JsonwebtokenInstrumentation] JWT sign completed successfully (${SpanUtils.getTraceInfo()})`);
|
|
14541
16072
|
this._addOutputAttributesToSpan(spanInfo, result);
|
|
@@ -16590,7 +18121,7 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
|
|
|
16590
18121
|
options
|
|
16591
18122
|
};
|
|
16592
18123
|
}
|
|
16593
|
-
_handleRecordUnaryRequest(spanInfo, original, context$
|
|
18124
|
+
_handleRecordUnaryRequest(spanInfo, original, context$6, parsedParams, callback) {
|
|
16594
18125
|
let isResponseReceived = false;
|
|
16595
18126
|
let isStatusEmitted = false;
|
|
16596
18127
|
let hasErrorOccurred = false;
|
|
@@ -16661,7 +18192,7 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
|
|
|
16661
18192
|
parsedParams.options,
|
|
16662
18193
|
patchedCallback
|
|
16663
18194
|
];
|
|
16664
|
-
const result = original.apply(context$
|
|
18195
|
+
const result = original.apply(context$6, inputArgs);
|
|
16665
18196
|
result.on("metadata", (initialMetadata) => {
|
|
16666
18197
|
responseMetadataInitial = serializeGrpcMetadata(initialMetadata);
|
|
16667
18198
|
});
|
|
@@ -16755,7 +18286,7 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
|
|
|
16755
18286
|
});
|
|
16756
18287
|
return emitter;
|
|
16757
18288
|
}
|
|
16758
|
-
_handleRecordServerStreamRequest(spanInfo, original, context$
|
|
18289
|
+
_handleRecordServerStreamRequest(spanInfo, original, context$6, parsedParams) {
|
|
16759
18290
|
let hasErrorOccurred = false;
|
|
16760
18291
|
let isSpanCompleted = false;
|
|
16761
18292
|
let streamResponses = [];
|
|
@@ -16783,7 +18314,7 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
|
|
|
16783
18314
|
parsedParams.metadata,
|
|
16784
18315
|
parsedParams.options
|
|
16785
18316
|
];
|
|
16786
|
-
const stream$1 = original.apply(context$
|
|
18317
|
+
const stream$1 = original.apply(context$6, inputArgs);
|
|
16787
18318
|
stream$1.on("data", (data) => {
|
|
16788
18319
|
try {
|
|
16789
18320
|
const { readableBody, bufferMap, jsonableStringMap } = serializeGrpcPayload(data);
|
|
@@ -17272,8 +18803,8 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
|
|
|
17272
18803
|
};
|
|
17273
18804
|
};
|
|
17274
18805
|
}
|
|
17275
|
-
async _handleRecordDocumentGet(spanInfo, originalGet, context$
|
|
17276
|
-
const snapshot = await originalGet.call(context$
|
|
18806
|
+
async _handleRecordDocumentGet(spanInfo, originalGet, context$6) {
|
|
18807
|
+
const snapshot = await originalGet.call(context$6);
|
|
17277
18808
|
const documentResult = {
|
|
17278
18809
|
id: snapshot.id,
|
|
17279
18810
|
path: snapshot.ref.path,
|
|
@@ -17551,8 +19082,8 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
|
|
|
17551
19082
|
};
|
|
17552
19083
|
};
|
|
17553
19084
|
}
|
|
17554
|
-
async _handleRecordDocumentWrite(spanInfo, originalWrite, context$
|
|
17555
|
-
const writeResult = await originalWrite.apply(context$
|
|
19085
|
+
async _handleRecordDocumentWrite(spanInfo, originalWrite, context$6, ...args) {
|
|
19086
|
+
const writeResult = await originalWrite.apply(context$6, args);
|
|
17556
19087
|
const result = { writeTime: writeResult.writeTime ? {
|
|
17557
19088
|
seconds: writeResult.writeTime.seconds,
|
|
17558
19089
|
nanoseconds: writeResult.writeTime.nanoseconds
|
|
@@ -17644,8 +19175,8 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
|
|
|
17644
19175
|
};
|
|
17645
19176
|
};
|
|
17646
19177
|
}
|
|
17647
|
-
async _handleRecordCollectionAdd(spanInfo, originalAdd, context$
|
|
17648
|
-
const docRef = await originalAdd.call(context$
|
|
19178
|
+
async _handleRecordCollectionAdd(spanInfo, originalAdd, context$6, data) {
|
|
19179
|
+
const docRef = await originalAdd.call(context$6, data);
|
|
17649
19180
|
const result = {
|
|
17650
19181
|
id: docRef.id,
|
|
17651
19182
|
path: docRef.path
|
|
@@ -17826,8 +19357,8 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
|
|
|
17826
19357
|
};
|
|
17827
19358
|
};
|
|
17828
19359
|
}
|
|
17829
|
-
async _handleRecordQueryGet(spanInfo, originalGet, context$
|
|
17830
|
-
const querySnapshot = await originalGet.call(context$
|
|
19360
|
+
async _handleRecordQueryGet(spanInfo, originalGet, context$6) {
|
|
19361
|
+
const querySnapshot = await originalGet.call(context$6);
|
|
17831
19362
|
const queryResult = {
|
|
17832
19363
|
docs: querySnapshot.docs.map((doc) => ({
|
|
17833
19364
|
id: doc.id,
|
|
@@ -18532,16 +20063,16 @@ var require_suppress_tracing = /* @__PURE__ */ __commonJS({ "node_modules/@opent
|
|
|
18532
20063
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18533
20064
|
exports.isTracingSuppressed = exports.unsuppressTracing = exports.suppressTracing = void 0;
|
|
18534
20065
|
const SUPPRESS_TRACING_KEY = (0, require_src$7().createContextKey)("OpenTelemetry SDK Context Key SUPPRESS_TRACING");
|
|
18535
|
-
function suppressTracing(context$
|
|
18536
|
-
return context$
|
|
20066
|
+
function suppressTracing(context$6) {
|
|
20067
|
+
return context$6.setValue(SUPPRESS_TRACING_KEY, true);
|
|
18537
20068
|
}
|
|
18538
20069
|
exports.suppressTracing = suppressTracing;
|
|
18539
|
-
function unsuppressTracing(context$
|
|
18540
|
-
return context$
|
|
20070
|
+
function unsuppressTracing(context$6) {
|
|
20071
|
+
return context$6.deleteValue(SUPPRESS_TRACING_KEY);
|
|
18541
20072
|
}
|
|
18542
20073
|
exports.unsuppressTracing = unsuppressTracing;
|
|
18543
|
-
function isTracingSuppressed(context$
|
|
18544
|
-
return context$
|
|
20074
|
+
function isTracingSuppressed(context$6) {
|
|
20075
|
+
return context$6.getValue(SUPPRESS_TRACING_KEY) === true;
|
|
18545
20076
|
}
|
|
18546
20077
|
exports.isTracingSuppressed = isTracingSuppressed;
|
|
18547
20078
|
}) });
|
|
@@ -18632,21 +20163,21 @@ var require_W3CBaggagePropagator = /* @__PURE__ */ __commonJS({ "node_modules/@o
|
|
|
18632
20163
|
* https://w3c.github.io/baggage/
|
|
18633
20164
|
*/
|
|
18634
20165
|
var W3CBaggagePropagator = class {
|
|
18635
|
-
inject(context$
|
|
18636
|
-
const baggage = api_1$33.propagation.getBaggage(context$
|
|
18637
|
-
if (!baggage || (0, suppress_tracing_1$3.isTracingSuppressed)(context$
|
|
20166
|
+
inject(context$6, carrier, setter) {
|
|
20167
|
+
const baggage = api_1$33.propagation.getBaggage(context$6);
|
|
20168
|
+
if (!baggage || (0, suppress_tracing_1$3.isTracingSuppressed)(context$6)) return;
|
|
18638
20169
|
const keyPairs = (0, utils_1$4.getKeyPairs)(baggage).filter((pair) => {
|
|
18639
20170
|
return pair.length <= constants_1$4.BAGGAGE_MAX_PER_NAME_VALUE_PAIRS;
|
|
18640
20171
|
}).slice(0, constants_1$4.BAGGAGE_MAX_NAME_VALUE_PAIRS);
|
|
18641
20172
|
const headerValue = (0, utils_1$4.serializeKeyPairs)(keyPairs);
|
|
18642
20173
|
if (headerValue.length > 0) setter.set(carrier, constants_1$4.BAGGAGE_HEADER, headerValue);
|
|
18643
20174
|
}
|
|
18644
|
-
extract(context$
|
|
20175
|
+
extract(context$6, carrier, getter) {
|
|
18645
20176
|
const headerValue = getter.get(carrier, constants_1$4.BAGGAGE_HEADER);
|
|
18646
20177
|
const baggageString = Array.isArray(headerValue) ? headerValue.join(constants_1$4.BAGGAGE_ITEMS_SEPARATOR) : headerValue;
|
|
18647
|
-
if (!baggageString) return context$
|
|
20178
|
+
if (!baggageString) return context$6;
|
|
18648
20179
|
const baggage = {};
|
|
18649
|
-
if (baggageString.length === 0) return context$
|
|
20180
|
+
if (baggageString.length === 0) return context$6;
|
|
18650
20181
|
baggageString.split(constants_1$4.BAGGAGE_ITEMS_SEPARATOR).forEach((entry) => {
|
|
18651
20182
|
const keyPair = (0, utils_1$4.parsePairKeyValue)(entry);
|
|
18652
20183
|
if (keyPair) {
|
|
@@ -18655,8 +20186,8 @@ var require_W3CBaggagePropagator = /* @__PURE__ */ __commonJS({ "node_modules/@o
|
|
|
18655
20186
|
baggage[keyPair.key] = baggageEntry;
|
|
18656
20187
|
}
|
|
18657
20188
|
});
|
|
18658
|
-
if (Object.entries(baggage).length === 0) return context$
|
|
18659
|
-
return api_1$33.propagation.setBaggage(context$
|
|
20189
|
+
if (Object.entries(baggage).length === 0) return context$6;
|
|
20190
|
+
return api_1$33.propagation.setBaggage(context$6, api_1$33.propagation.createBaggage(baggage));
|
|
18660
20191
|
}
|
|
18661
20192
|
fields() {
|
|
18662
20193
|
return [constants_1$4.BAGGAGE_HEADER];
|
|
@@ -21476,9 +23007,9 @@ var require_composite = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetr
|
|
|
21476
23007
|
* @param context Context to inject
|
|
21477
23008
|
* @param carrier Carrier into which context will be injected
|
|
21478
23009
|
*/
|
|
21479
|
-
inject(context$
|
|
23010
|
+
inject(context$6, carrier, setter) {
|
|
21480
23011
|
for (const propagator of this._propagators) try {
|
|
21481
|
-
propagator.inject(context$
|
|
23012
|
+
propagator.inject(context$6, carrier, setter);
|
|
21482
23013
|
} catch (err) {
|
|
21483
23014
|
api_1$29.diag.warn(`Failed to inject with ${propagator.constructor.name}. Err: ${err.message}`);
|
|
21484
23015
|
}
|
|
@@ -21492,7 +23023,7 @@ var require_composite = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetr
|
|
|
21492
23023
|
* @param context Context to add values to
|
|
21493
23024
|
* @param carrier Carrier from which to extract context
|
|
21494
23025
|
*/
|
|
21495
|
-
extract(context$
|
|
23026
|
+
extract(context$6, carrier, getter) {
|
|
21496
23027
|
return this._propagators.reduce((ctx, propagator) => {
|
|
21497
23028
|
try {
|
|
21498
23029
|
return propagator.extract(ctx, carrier, getter);
|
|
@@ -21500,7 +23031,7 @@ var require_composite = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetr
|
|
|
21500
23031
|
api_1$29.diag.warn(`Failed to extract with ${propagator.constructor.name}. Err: ${err.message}`);
|
|
21501
23032
|
}
|
|
21502
23033
|
return ctx;
|
|
21503
|
-
}, context$
|
|
23034
|
+
}, context$6);
|
|
21504
23035
|
}
|
|
21505
23036
|
fields() {
|
|
21506
23037
|
return this._fields.slice();
|
|
@@ -21652,27 +23183,27 @@ var require_W3CTraceContextPropagator = /* @__PURE__ */ __commonJS({ "node_modul
|
|
|
21652
23183
|
* https://www.w3.org/TR/trace-context/
|
|
21653
23184
|
*/
|
|
21654
23185
|
var W3CTraceContextPropagator = class {
|
|
21655
|
-
inject(context$
|
|
21656
|
-
const spanContext = api_1$28.trace.getSpanContext(context$
|
|
21657
|
-
if (!spanContext || (0, suppress_tracing_1$2.isTracingSuppressed)(context$
|
|
23186
|
+
inject(context$6, carrier, setter) {
|
|
23187
|
+
const spanContext = api_1$28.trace.getSpanContext(context$6);
|
|
23188
|
+
if (!spanContext || (0, suppress_tracing_1$2.isTracingSuppressed)(context$6) || !(0, api_1$28.isSpanContextValid)(spanContext)) return;
|
|
21658
23189
|
const traceParent = `${VERSION}-${spanContext.traceId}-${spanContext.spanId}-0${Number(spanContext.traceFlags || api_1$28.TraceFlags.NONE).toString(16)}`;
|
|
21659
23190
|
setter.set(carrier, exports.TRACE_PARENT_HEADER, traceParent);
|
|
21660
23191
|
if (spanContext.traceState) setter.set(carrier, exports.TRACE_STATE_HEADER, spanContext.traceState.serialize());
|
|
21661
23192
|
}
|
|
21662
|
-
extract(context$
|
|
23193
|
+
extract(context$6, carrier, getter) {
|
|
21663
23194
|
const traceParentHeader = getter.get(carrier, exports.TRACE_PARENT_HEADER);
|
|
21664
|
-
if (!traceParentHeader) return context$
|
|
23195
|
+
if (!traceParentHeader) return context$6;
|
|
21665
23196
|
const traceParent = Array.isArray(traceParentHeader) ? traceParentHeader[0] : traceParentHeader;
|
|
21666
|
-
if (typeof traceParent !== "string") return context$
|
|
23197
|
+
if (typeof traceParent !== "string") return context$6;
|
|
21667
23198
|
const spanContext = parseTraceParent(traceParent);
|
|
21668
|
-
if (!spanContext) return context$
|
|
23199
|
+
if (!spanContext) return context$6;
|
|
21669
23200
|
spanContext.isRemote = true;
|
|
21670
23201
|
const traceStateHeader = getter.get(carrier, exports.TRACE_STATE_HEADER);
|
|
21671
23202
|
if (traceStateHeader) {
|
|
21672
23203
|
const state = Array.isArray(traceStateHeader) ? traceStateHeader.join(",") : traceStateHeader;
|
|
21673
23204
|
spanContext.traceState = new TraceState_1$1.TraceState(typeof state === "string" ? state : void 0);
|
|
21674
23205
|
}
|
|
21675
|
-
return api_1$28.trace.setSpanContext(context$
|
|
23206
|
+
return api_1$28.trace.setSpanContext(context$6, spanContext);
|
|
21676
23207
|
}
|
|
21677
23208
|
fields() {
|
|
21678
23209
|
return [exports.TRACE_PARENT_HEADER, exports.TRACE_STATE_HEADER];
|
|
@@ -21690,16 +23221,16 @@ var require_rpc_metadata = /* @__PURE__ */ __commonJS({ "node_modules/@opentelem
|
|
|
21690
23221
|
(function(RPCType) {
|
|
21691
23222
|
RPCType["HTTP"] = "http";
|
|
21692
23223
|
})(exports.RPCType || (exports.RPCType = {}));
|
|
21693
|
-
function setRPCMetadata(context$
|
|
21694
|
-
return context$
|
|
23224
|
+
function setRPCMetadata(context$6, meta) {
|
|
23225
|
+
return context$6.setValue(RPC_METADATA_KEY, meta);
|
|
21695
23226
|
}
|
|
21696
23227
|
exports.setRPCMetadata = setRPCMetadata;
|
|
21697
|
-
function deleteRPCMetadata(context$
|
|
21698
|
-
return context$
|
|
23228
|
+
function deleteRPCMetadata(context$6) {
|
|
23229
|
+
return context$6.deleteValue(RPC_METADATA_KEY);
|
|
21699
23230
|
}
|
|
21700
23231
|
exports.deleteRPCMetadata = deleteRPCMetadata;
|
|
21701
|
-
function getRPCMetadata(context$
|
|
21702
|
-
return context$
|
|
23232
|
+
function getRPCMetadata(context$6) {
|
|
23233
|
+
return context$6.getValue(RPC_METADATA_KEY);
|
|
21703
23234
|
}
|
|
21704
23235
|
exports.getRPCMetadata = getRPCMetadata;
|
|
21705
23236
|
}) });
|
|
@@ -21773,15 +23304,15 @@ var require_ParentBasedSampler$1 = /* @__PURE__ */ __commonJS({ "node_modules/@o
|
|
|
21773
23304
|
this._localParentSampled = (_c = config.localParentSampled) !== null && _c !== void 0 ? _c : new AlwaysOnSampler_1$4.AlwaysOnSampler();
|
|
21774
23305
|
this._localParentNotSampled = (_d = config.localParentNotSampled) !== null && _d !== void 0 ? _d : new AlwaysOffSampler_1$4.AlwaysOffSampler();
|
|
21775
23306
|
}
|
|
21776
|
-
shouldSample(context$
|
|
21777
|
-
const parentContext = api_1$25.trace.getSpanContext(context$
|
|
21778
|
-
if (!parentContext || !(0, api_1$25.isSpanContextValid)(parentContext)) return this._root.shouldSample(context$
|
|
23307
|
+
shouldSample(context$6, traceId, spanName, spanKind, attributes, links) {
|
|
23308
|
+
const parentContext = api_1$25.trace.getSpanContext(context$6);
|
|
23309
|
+
if (!parentContext || !(0, api_1$25.isSpanContextValid)(parentContext)) return this._root.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
|
|
21779
23310
|
if (parentContext.isRemote) {
|
|
21780
|
-
if (parentContext.traceFlags & api_1$25.TraceFlags.SAMPLED) return this._remoteParentSampled.shouldSample(context$
|
|
21781
|
-
return this._remoteParentNotSampled.shouldSample(context$
|
|
23311
|
+
if (parentContext.traceFlags & api_1$25.TraceFlags.SAMPLED) return this._remoteParentSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
|
|
23312
|
+
return this._remoteParentNotSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
|
|
21782
23313
|
}
|
|
21783
|
-
if (parentContext.traceFlags & api_1$25.TraceFlags.SAMPLED) return this._localParentSampled.shouldSample(context$
|
|
21784
|
-
return this._localParentNotSampled.shouldSample(context$
|
|
23314
|
+
if (parentContext.traceFlags & api_1$25.TraceFlags.SAMPLED) return this._localParentSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
|
|
23315
|
+
return this._localParentNotSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
|
|
21785
23316
|
}
|
|
21786
23317
|
toString() {
|
|
21787
23318
|
return `ParentBased{root=${this._root.toString()}, remoteParentSampled=${this._remoteParentSampled.toString()}, remoteParentNotSampled=${this._remoteParentNotSampled.toString()}, localParentSampled=${this._localParentSampled.toString()}, localParentNotSampled=${this._localParentNotSampled.toString()}}`;
|
|
@@ -21806,7 +23337,7 @@ var require_TraceIdRatioBasedSampler$1 = /* @__PURE__ */ __commonJS({ "node_modu
|
|
|
21806
23337
|
this._ratio = this._normalize(_ratio);
|
|
21807
23338
|
this._upperBound = Math.floor(this._ratio * 4294967295);
|
|
21808
23339
|
}
|
|
21809
|
-
shouldSample(context$
|
|
23340
|
+
shouldSample(context$6, traceId) {
|
|
21810
23341
|
return { decision: (0, api_1$24.isValidTraceId)(traceId) && this._accumulate(traceId) < this._upperBound ? api_1$24.SamplingDecision.RECORD_AND_SAMPLED : api_1$24.SamplingDecision.NOT_RECORD };
|
|
21811
23342
|
}
|
|
21812
23343
|
toString() {
|
|
@@ -23392,15 +24923,15 @@ var require_AbstractAsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "nod
|
|
|
23392
24923
|
* @param target a function or event emitter. When target or one of its callbacks is called,
|
|
23393
24924
|
* the provided context will be used as the active context for the duration of the call.
|
|
23394
24925
|
*/
|
|
23395
|
-
bind(context$
|
|
23396
|
-
if (target instanceof events_1.EventEmitter) return this._bindEventEmitter(context$
|
|
23397
|
-
if (typeof target === "function") return this._bindFunction(context$
|
|
24926
|
+
bind(context$6, target) {
|
|
24927
|
+
if (target instanceof events_1.EventEmitter) return this._bindEventEmitter(context$6, target);
|
|
24928
|
+
if (typeof target === "function") return this._bindFunction(context$6, target);
|
|
23398
24929
|
return target;
|
|
23399
24930
|
}
|
|
23400
|
-
_bindFunction(context$
|
|
24931
|
+
_bindFunction(context$6, target) {
|
|
23401
24932
|
const manager = this;
|
|
23402
24933
|
const contextWrapper = function(...args) {
|
|
23403
|
-
return manager.with(context$
|
|
24934
|
+
return manager.with(context$6, () => target.apply(this, args));
|
|
23404
24935
|
};
|
|
23405
24936
|
Object.defineProperty(contextWrapper, "length", {
|
|
23406
24937
|
enumerable: false,
|
|
@@ -23421,12 +24952,12 @@ var require_AbstractAsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "nod
|
|
|
23421
24952
|
* @param context the context we want to bind
|
|
23422
24953
|
* @param ee EventEmitter an instance of EventEmitter to patch
|
|
23423
24954
|
*/
|
|
23424
|
-
_bindEventEmitter(context$
|
|
24955
|
+
_bindEventEmitter(context$6, ee) {
|
|
23425
24956
|
if (this._getPatchMap(ee) !== void 0) return ee;
|
|
23426
24957
|
this._createPatchMap(ee);
|
|
23427
24958
|
ADD_LISTENER_METHODS.forEach((methodName) => {
|
|
23428
24959
|
if (ee[methodName] === void 0) return;
|
|
23429
|
-
ee[methodName] = this._patchAddListener(ee, ee[methodName], context$
|
|
24960
|
+
ee[methodName] = this._patchAddListener(ee, ee[methodName], context$6);
|
|
23430
24961
|
});
|
|
23431
24962
|
if (typeof ee.removeListener === "function") ee.removeListener = this._patchRemoveListener(ee, ee.removeListener);
|
|
23432
24963
|
if (typeof ee.off === "function") ee.off = this._patchRemoveListener(ee, ee.off);
|
|
@@ -23473,7 +25004,7 @@ var require_AbstractAsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "nod
|
|
|
23473
25004
|
* @param original reference to the patched method
|
|
23474
25005
|
* @param [context] context to propagate when calling listeners
|
|
23475
25006
|
*/
|
|
23476
|
-
_patchAddListener(ee, original, context$
|
|
25007
|
+
_patchAddListener(ee, original, context$6) {
|
|
23477
25008
|
const contextManager = this;
|
|
23478
25009
|
return function(event, listener) {
|
|
23479
25010
|
/**
|
|
@@ -23492,7 +25023,7 @@ var require_AbstractAsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "nod
|
|
|
23492
25023
|
listeners = /* @__PURE__ */ new WeakMap();
|
|
23493
25024
|
map[event] = listeners;
|
|
23494
25025
|
}
|
|
23495
|
-
const patchedListener = contextManager.bind(context$
|
|
25026
|
+
const patchedListener = contextManager.bind(context$6, listener);
|
|
23496
25027
|
listeners.set(listener, patchedListener);
|
|
23497
25028
|
/**
|
|
23498
25029
|
* See comment at the start of this function for the explanation of this property.
|
|
@@ -23542,8 +25073,8 @@ var require_AsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "node_module
|
|
|
23542
25073
|
var _a;
|
|
23543
25074
|
return (_a = this._stack[this._stack.length - 1]) !== null && _a !== void 0 ? _a : api_1$22.ROOT_CONTEXT;
|
|
23544
25075
|
}
|
|
23545
|
-
with(context$
|
|
23546
|
-
this._enterContext(context$
|
|
25076
|
+
with(context$6, fn, thisArg, ...args) {
|
|
25077
|
+
this._enterContext(context$6);
|
|
23547
25078
|
try {
|
|
23548
25079
|
return fn.call(thisArg, ...args);
|
|
23549
25080
|
} finally {
|
|
@@ -23568,8 +25099,8 @@ var require_AsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "node_module
|
|
|
23568
25099
|
*/
|
|
23569
25100
|
_init(uid, type) {
|
|
23570
25101
|
if (type === "TIMERWRAP") return;
|
|
23571
|
-
const context$
|
|
23572
|
-
if (context$
|
|
25102
|
+
const context$6 = this._stack[this._stack.length - 1];
|
|
25103
|
+
if (context$6 !== void 0) this._contexts.set(uid, context$6);
|
|
23573
25104
|
}
|
|
23574
25105
|
/**
|
|
23575
25106
|
* Destroy hook will be called when a given context is no longer used so we can
|
|
@@ -23584,8 +25115,8 @@ var require_AsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "node_module
|
|
|
23584
25115
|
* @param uid uid of the async context
|
|
23585
25116
|
*/
|
|
23586
25117
|
_before(uid) {
|
|
23587
|
-
const context$
|
|
23588
|
-
if (context$
|
|
25118
|
+
const context$6 = this._contexts.get(uid);
|
|
25119
|
+
if (context$6 !== void 0) this._enterContext(context$6);
|
|
23589
25120
|
}
|
|
23590
25121
|
/**
|
|
23591
25122
|
* After hook is called just after completing the execution of a async context.
|
|
@@ -23596,8 +25127,8 @@ var require_AsyncHooksContextManager = /* @__PURE__ */ __commonJS({ "node_module
|
|
|
23596
25127
|
/**
|
|
23597
25128
|
* Set the given context as active
|
|
23598
25129
|
*/
|
|
23599
|
-
_enterContext(context$
|
|
23600
|
-
this._stack.push(context$
|
|
25130
|
+
_enterContext(context$6) {
|
|
25131
|
+
this._stack.push(context$6);
|
|
23601
25132
|
}
|
|
23602
25133
|
/**
|
|
23603
25134
|
* Remove the context at the root of the stack
|
|
@@ -23626,9 +25157,9 @@ var require_AsyncLocalStorageContextManager = /* @__PURE__ */ __commonJS({ "node
|
|
|
23626
25157
|
var _a;
|
|
23627
25158
|
return (_a = this._asyncLocalStorage.getStore()) !== null && _a !== void 0 ? _a : api_1$21.ROOT_CONTEXT;
|
|
23628
25159
|
}
|
|
23629
|
-
with(context$
|
|
25160
|
+
with(context$6, fn, thisArg, ...args) {
|
|
23630
25161
|
const cb = thisArg == null ? fn : fn.bind(thisArg);
|
|
23631
|
-
return this._asyncLocalStorage.run(context$
|
|
25162
|
+
return this._asyncLocalStorage.run(context$6, cb, ...args);
|
|
23632
25163
|
}
|
|
23633
25164
|
enable() {
|
|
23634
25165
|
return this;
|
|
@@ -23741,30 +25272,30 @@ var require_B3MultiPropagator = /* @__PURE__ */ __commonJS({ "node_modules/@open
|
|
|
23741
25272
|
* Based on: https://github.com/openzipkin/b3-propagation
|
|
23742
25273
|
*/
|
|
23743
25274
|
var B3MultiPropagator = class {
|
|
23744
|
-
inject(context$
|
|
23745
|
-
const spanContext = api_1$19.trace.getSpanContext(context$
|
|
23746
|
-
if (!spanContext || !(0, api_1$19.isSpanContextValid)(spanContext) || (0, core_1$16.isTracingSuppressed)(context$
|
|
23747
|
-
const debug = context$
|
|
25275
|
+
inject(context$6, carrier, setter) {
|
|
25276
|
+
const spanContext = api_1$19.trace.getSpanContext(context$6);
|
|
25277
|
+
if (!spanContext || !(0, api_1$19.isSpanContextValid)(spanContext) || (0, core_1$16.isTracingSuppressed)(context$6)) return;
|
|
25278
|
+
const debug = context$6.getValue(common_1$1.B3_DEBUG_FLAG_KEY);
|
|
23748
25279
|
setter.set(carrier, constants_1$3.X_B3_TRACE_ID, spanContext.traceId);
|
|
23749
25280
|
setter.set(carrier, constants_1$3.X_B3_SPAN_ID, spanContext.spanId);
|
|
23750
25281
|
if (debug === "1") setter.set(carrier, constants_1$3.X_B3_FLAGS, debug);
|
|
23751
25282
|
else if (spanContext.traceFlags !== void 0) setter.set(carrier, constants_1$3.X_B3_SAMPLED, (api_1$19.TraceFlags.SAMPLED & spanContext.traceFlags) === api_1$19.TraceFlags.SAMPLED ? "1" : "0");
|
|
23752
25283
|
}
|
|
23753
|
-
extract(context$
|
|
25284
|
+
extract(context$6, carrier, getter) {
|
|
23754
25285
|
const traceId = getTraceId(carrier, getter);
|
|
23755
25286
|
const spanId = getSpanId(carrier, getter);
|
|
23756
25287
|
const traceFlags = getTraceFlags(carrier, getter);
|
|
23757
25288
|
const debug = getDebug(carrier, getter);
|
|
23758
25289
|
if ((0, api_1$19.isValidTraceId)(traceId) && (0, api_1$19.isValidSpanId)(spanId) && isValidSampledValue(traceFlags)) {
|
|
23759
|
-
context$
|
|
23760
|
-
return api_1$19.trace.setSpanContext(context$
|
|
25290
|
+
context$6 = context$6.setValue(common_1$1.B3_DEBUG_FLAG_KEY, debug);
|
|
25291
|
+
return api_1$19.trace.setSpanContext(context$6, {
|
|
23761
25292
|
traceId,
|
|
23762
25293
|
spanId,
|
|
23763
25294
|
isRemote: true,
|
|
23764
25295
|
traceFlags
|
|
23765
25296
|
});
|
|
23766
25297
|
}
|
|
23767
|
-
return context$
|
|
25298
|
+
return context$6;
|
|
23768
25299
|
}
|
|
23769
25300
|
fields() {
|
|
23770
25301
|
return [
|
|
@@ -23804,25 +25335,25 @@ var require_B3SinglePropagator = /* @__PURE__ */ __commonJS({ "node_modules/@ope
|
|
|
23804
25335
|
* Based on: https://github.com/openzipkin/b3-propagation
|
|
23805
25336
|
*/
|
|
23806
25337
|
var B3SinglePropagator = class {
|
|
23807
|
-
inject(context$
|
|
23808
|
-
const spanContext = api_1$18.trace.getSpanContext(context$
|
|
23809
|
-
if (!spanContext || !(0, api_1$18.isSpanContextValid)(spanContext) || (0, core_1$15.isTracingSuppressed)(context$
|
|
23810
|
-
const samplingState = context$
|
|
25338
|
+
inject(context$6, carrier, setter) {
|
|
25339
|
+
const spanContext = api_1$18.trace.getSpanContext(context$6);
|
|
25340
|
+
if (!spanContext || !(0, api_1$18.isSpanContextValid)(spanContext) || (0, core_1$15.isTracingSuppressed)(context$6)) return;
|
|
25341
|
+
const samplingState = context$6.getValue(common_1.B3_DEBUG_FLAG_KEY) || spanContext.traceFlags & 1;
|
|
23811
25342
|
const value = `${spanContext.traceId}-${spanContext.spanId}-${samplingState}`;
|
|
23812
25343
|
setter.set(carrier, constants_1$2.B3_CONTEXT_HEADER, value);
|
|
23813
25344
|
}
|
|
23814
|
-
extract(context$
|
|
25345
|
+
extract(context$6, carrier, getter) {
|
|
23815
25346
|
const header = getter.get(carrier, constants_1$2.B3_CONTEXT_HEADER);
|
|
23816
25347
|
const b3Context = Array.isArray(header) ? header[0] : header;
|
|
23817
|
-
if (typeof b3Context !== "string") return context$
|
|
25348
|
+
if (typeof b3Context !== "string") return context$6;
|
|
23818
25349
|
const match = b3Context.match(B3_CONTEXT_REGEX);
|
|
23819
|
-
if (!match) return context$
|
|
25350
|
+
if (!match) return context$6;
|
|
23820
25351
|
const [, extractedTraceId, spanId, samplingState] = match;
|
|
23821
25352
|
const traceId = convertToTraceId128(extractedTraceId);
|
|
23822
|
-
if (!(0, api_1$18.isValidTraceId)(traceId) || !(0, api_1$18.isValidSpanId)(spanId)) return context$
|
|
25353
|
+
if (!(0, api_1$18.isValidTraceId)(traceId) || !(0, api_1$18.isValidSpanId)(spanId)) return context$6;
|
|
23823
25354
|
const traceFlags = convertToTraceFlags(samplingState);
|
|
23824
|
-
if (samplingState === DEBUG_STATE) context$
|
|
23825
|
-
return api_1$18.trace.setSpanContext(context$
|
|
25355
|
+
if (samplingState === DEBUG_STATE) context$6 = context$6.setValue(common_1.B3_DEBUG_FLAG_KEY, samplingState);
|
|
25356
|
+
return api_1$18.trace.setSpanContext(context$6, {
|
|
23826
25357
|
traceId,
|
|
23827
25358
|
spanId,
|
|
23828
25359
|
isRemote: true,
|
|
@@ -23876,14 +25407,14 @@ var require_B3Propagator = /* @__PURE__ */ __commonJS({ "node_modules/@opentelem
|
|
|
23876
25407
|
this._fields = this._b3SinglePropagator.fields();
|
|
23877
25408
|
}
|
|
23878
25409
|
}
|
|
23879
|
-
inject(context$
|
|
23880
|
-
if ((0, core_1$14.isTracingSuppressed)(context$
|
|
23881
|
-
this._inject(context$
|
|
25410
|
+
inject(context$6, carrier, setter) {
|
|
25411
|
+
if ((0, core_1$14.isTracingSuppressed)(context$6)) return;
|
|
25412
|
+
this._inject(context$6, carrier, setter);
|
|
23882
25413
|
}
|
|
23883
|
-
extract(context$
|
|
25414
|
+
extract(context$6, carrier, getter) {
|
|
23884
25415
|
const header = getter.get(carrier, constants_1$1.B3_CONTEXT_HEADER);
|
|
23885
|
-
if (Array.isArray(header) ? header[0] : header) return this._b3SinglePropagator.extract(context$
|
|
23886
|
-
else return this._b3MultiPropagator.extract(context$
|
|
25416
|
+
if (Array.isArray(header) ? header[0] : header) return this._b3SinglePropagator.extract(context$6, carrier, getter);
|
|
25417
|
+
else return this._b3MultiPropagator.extract(context$6, carrier, getter);
|
|
23887
25418
|
}
|
|
23888
25419
|
fields() {
|
|
23889
25420
|
return this._fields;
|
|
@@ -25945,7 +27476,7 @@ var require_Span = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/sdk
|
|
|
25945
27476
|
*
|
|
25946
27477
|
* @deprecated calling Span constructor directly is not supported. Please use tracer.startSpan.
|
|
25947
27478
|
* */
|
|
25948
|
-
constructor(parentTracer, context$
|
|
27479
|
+
constructor(parentTracer, context$6, spanName, spanContext, kind, parentSpanId, links = [], startTime, _deprecatedClock, attributes) {
|
|
25949
27480
|
this.attributes = {};
|
|
25950
27481
|
this.links = [];
|
|
25951
27482
|
this.events = [];
|
|
@@ -25972,7 +27503,7 @@ var require_Span = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/sdk
|
|
|
25972
27503
|
this._attributeValueLengthLimit = this._spanLimits.attributeValueLengthLimit || 0;
|
|
25973
27504
|
if (attributes != null) this.setAttributes(attributes);
|
|
25974
27505
|
this._spanProcessor = parentTracer.getActiveSpanProcessor();
|
|
25975
|
-
this._spanProcessor.onStart(this, context$
|
|
27506
|
+
this._spanProcessor.onStart(this, context$6);
|
|
25976
27507
|
}
|
|
25977
27508
|
spanContext() {
|
|
25978
27509
|
return this._spanContext;
|
|
@@ -26227,15 +27758,15 @@ var require_ParentBasedSampler = /* @__PURE__ */ __commonJS({ "node_modules/@ope
|
|
|
26227
27758
|
this._localParentSampled = (_c = config.localParentSampled) !== null && _c !== void 0 ? _c : new AlwaysOnSampler_1$2.AlwaysOnSampler();
|
|
26228
27759
|
this._localParentNotSampled = (_d = config.localParentNotSampled) !== null && _d !== void 0 ? _d : new AlwaysOffSampler_1$2.AlwaysOffSampler();
|
|
26229
27760
|
}
|
|
26230
|
-
shouldSample(context$
|
|
26231
|
-
const parentContext = api_1$16.trace.getSpanContext(context$
|
|
26232
|
-
if (!parentContext || !(0, api_1$16.isSpanContextValid)(parentContext)) return this._root.shouldSample(context$
|
|
27761
|
+
shouldSample(context$6, traceId, spanName, spanKind, attributes, links) {
|
|
27762
|
+
const parentContext = api_1$16.trace.getSpanContext(context$6);
|
|
27763
|
+
if (!parentContext || !(0, api_1$16.isSpanContextValid)(parentContext)) return this._root.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
|
|
26233
27764
|
if (parentContext.isRemote) {
|
|
26234
|
-
if (parentContext.traceFlags & api_1$16.TraceFlags.SAMPLED) return this._remoteParentSampled.shouldSample(context$
|
|
26235
|
-
return this._remoteParentNotSampled.shouldSample(context$
|
|
27765
|
+
if (parentContext.traceFlags & api_1$16.TraceFlags.SAMPLED) return this._remoteParentSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
|
|
27766
|
+
return this._remoteParentNotSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
|
|
26236
27767
|
}
|
|
26237
|
-
if (parentContext.traceFlags & api_1$16.TraceFlags.SAMPLED) return this._localParentSampled.shouldSample(context$
|
|
26238
|
-
return this._localParentNotSampled.shouldSample(context$
|
|
27768
|
+
if (parentContext.traceFlags & api_1$16.TraceFlags.SAMPLED) return this._localParentSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
|
|
27769
|
+
return this._localParentNotSampled.shouldSample(context$6, traceId, spanName, spanKind, attributes, links);
|
|
26239
27770
|
}
|
|
26240
27771
|
toString() {
|
|
26241
27772
|
return `ParentBased{root=${this._root.toString()}, remoteParentSampled=${this._remoteParentSampled.toString()}, remoteParentNotSampled=${this._remoteParentNotSampled.toString()}, localParentSampled=${this._localParentSampled.toString()}, localParentNotSampled=${this._localParentNotSampled.toString()}}`;
|
|
@@ -26258,7 +27789,7 @@ var require_TraceIdRatioBasedSampler = /* @__PURE__ */ __commonJS({ "node_module
|
|
|
26258
27789
|
this._ratio = this._normalize(_ratio);
|
|
26259
27790
|
this._upperBound = Math.floor(this._ratio * 4294967295);
|
|
26260
27791
|
}
|
|
26261
|
-
shouldSample(context$
|
|
27792
|
+
shouldSample(context$6, traceId) {
|
|
26262
27793
|
return { decision: (0, api_1$15.isValidTraceId)(traceId) && this._accumulate(traceId) < this._upperBound ? Sampler_1$1.SamplingDecision.RECORD_AND_SAMPLED : Sampler_1$1.SamplingDecision.NOT_RECORD };
|
|
26263
27794
|
}
|
|
26264
27795
|
toString() {
|
|
@@ -26660,11 +28191,11 @@ var require_Tracer = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/s
|
|
|
26660
28191
|
* Starts a new Span or returns the default NoopSpan based on the sampling
|
|
26661
28192
|
* decision.
|
|
26662
28193
|
*/
|
|
26663
|
-
startSpan(name, options = {}, context$
|
|
28194
|
+
startSpan(name, options = {}, context$6 = api.context.active()) {
|
|
26664
28195
|
var _a, _b, _c;
|
|
26665
|
-
if (options.root) context$
|
|
26666
|
-
const parentSpan = api.trace.getSpan(context$
|
|
26667
|
-
if ((0, core_1$8.isTracingSuppressed)(context$
|
|
28196
|
+
if (options.root) context$6 = api.trace.deleteSpan(context$6);
|
|
28197
|
+
const parentSpan = api.trace.getSpan(context$6);
|
|
28198
|
+
if ((0, core_1$8.isTracingSuppressed)(context$6)) {
|
|
26668
28199
|
api.diag.debug("Instrumentation suppressed, returning Noop Span");
|
|
26669
28200
|
return api.trace.wrapSpanContext(api.INVALID_SPAN_CONTEXT);
|
|
26670
28201
|
}
|
|
@@ -26687,7 +28218,7 @@ var require_Tracer = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/s
|
|
|
26687
28218
|
};
|
|
26688
28219
|
});
|
|
26689
28220
|
const attributes = (0, core_1$8.sanitizeAttributes)(options.attributes);
|
|
26690
|
-
const samplingResult = this._sampler.shouldSample(context$
|
|
28221
|
+
const samplingResult = this._sampler.shouldSample(context$6, traceId, name, spanKind, attributes, links);
|
|
26691
28222
|
traceState = (_c = samplingResult.traceState) !== null && _c !== void 0 ? _c : traceState;
|
|
26692
28223
|
const traceFlags = samplingResult.decision === api.SamplingDecision.RECORD_AND_SAMPLED ? api.TraceFlags.SAMPLED : api.TraceFlags.NONE;
|
|
26693
28224
|
const spanContext = {
|
|
@@ -26701,7 +28232,7 @@ var require_Tracer = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/s
|
|
|
26701
28232
|
return api.trace.wrapSpanContext(spanContext);
|
|
26702
28233
|
}
|
|
26703
28234
|
const initAttributes = (0, core_1$8.sanitizeAttributes)(Object.assign(attributes, samplingResult.attributes));
|
|
26704
|
-
return new Span_1$1.Span(this, context$
|
|
28235
|
+
return new Span_1$1.Span(this, context$6, name, spanContext, spanKind, parentSpanId, links, options.startTime, void 0, initAttributes);
|
|
26705
28236
|
}
|
|
26706
28237
|
startActiveSpan(name, arg2, arg3, arg4) {
|
|
26707
28238
|
let opts;
|
|
@@ -29748,8 +31279,8 @@ var require_MultiSpanProcessor = /* @__PURE__ */ __commonJS({ "node_modules/@ope
|
|
|
29748
31279
|
});
|
|
29749
31280
|
});
|
|
29750
31281
|
}
|
|
29751
|
-
onStart(span, context$
|
|
29752
|
-
for (const spanProcessor of this._spanProcessors) spanProcessor.onStart(span, context$
|
|
31282
|
+
onStart(span, context$6) {
|
|
31283
|
+
for (const spanProcessor of this._spanProcessors) spanProcessor.onStart(span, context$6);
|
|
29753
31284
|
}
|
|
29754
31285
|
onEnd(span) {
|
|
29755
31286
|
for (const spanProcessor of this._spanProcessors) spanProcessor.onEnd(span);
|
|
@@ -30255,16 +31786,16 @@ var require_JaegerPropagator = /* @__PURE__ */ __commonJS({ "node_modules/@opent
|
|
|
30255
31786
|
this._jaegerBaggageHeaderPrefix = (config === null || config === void 0 ? void 0 : config.customBaggageHeaderPrefix) || exports.UBER_BAGGAGE_HEADER_PREFIX;
|
|
30256
31787
|
}
|
|
30257
31788
|
}
|
|
30258
|
-
inject(context$
|
|
30259
|
-
const spanContext = api_1.trace.getSpanContext(context$
|
|
30260
|
-
const baggage = api_1.propagation.getBaggage(context$
|
|
30261
|
-
if (spanContext && (0, core_1.isTracingSuppressed)(context$
|
|
31789
|
+
inject(context$6, carrier, setter) {
|
|
31790
|
+
const spanContext = api_1.trace.getSpanContext(context$6);
|
|
31791
|
+
const baggage = api_1.propagation.getBaggage(context$6);
|
|
31792
|
+
if (spanContext && (0, core_1.isTracingSuppressed)(context$6) === false) {
|
|
30262
31793
|
const traceFlags = `0${(spanContext.traceFlags || api_1.TraceFlags.NONE).toString(16)}`;
|
|
30263
31794
|
setter.set(carrier, this._jaegerTraceHeader, `${spanContext.traceId}:${spanContext.spanId}:0:${traceFlags}`);
|
|
30264
31795
|
}
|
|
30265
31796
|
if (baggage) for (const [key, entry] of baggage.getAllEntries()) setter.set(carrier, `${this._jaegerBaggageHeaderPrefix}-${key}`, encodeURIComponent(entry.value));
|
|
30266
31797
|
}
|
|
30267
|
-
extract(context$
|
|
31798
|
+
extract(context$6, carrier, getter) {
|
|
30268
31799
|
var _a;
|
|
30269
31800
|
const uberTraceIdHeader = getter.get(carrier, this._jaegerTraceHeader);
|
|
30270
31801
|
const uberTraceId = Array.isArray(uberTraceIdHeader) ? uberTraceIdHeader[0] : uberTraceIdHeader;
|
|
@@ -30275,13 +31806,13 @@ var require_JaegerPropagator = /* @__PURE__ */ __commonJS({ "node_modules/@opent
|
|
|
30275
31806
|
value: Array.isArray(value) ? value[0] : value
|
|
30276
31807
|
};
|
|
30277
31808
|
});
|
|
30278
|
-
let newContext = context$
|
|
31809
|
+
let newContext = context$6;
|
|
30279
31810
|
if (typeof uberTraceId === "string") {
|
|
30280
31811
|
const spanContext = deserializeSpanContext(uberTraceId);
|
|
30281
31812
|
if (spanContext) newContext = api_1.trace.setSpanContext(newContext, spanContext);
|
|
30282
31813
|
}
|
|
30283
31814
|
if (baggageValues.length === 0) return newContext;
|
|
30284
|
-
let currentBaggage = (_a = api_1.propagation.getBaggage(context$
|
|
31815
|
+
let currentBaggage = (_a = api_1.propagation.getBaggage(context$6)) !== null && _a !== void 0 ? _a : api_1.propagation.createBaggage();
|
|
30285
31816
|
for (const baggageEntry of baggageValues) {
|
|
30286
31817
|
if (baggageEntry.value === void 0) continue;
|
|
30287
31818
|
currentBaggage = currentBaggage.setEntry(baggageEntry.key, { value: decodeURIComponent(baggageEntry.value) });
|
|
@@ -30484,7 +32015,7 @@ var require_src = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/sdk-
|
|
|
30484
32015
|
//#endregion
|
|
30485
32016
|
//#region package.json
|
|
30486
32017
|
var import_src$1 = /* @__PURE__ */ __toESM(require_src(), 1);
|
|
30487
|
-
var version = "0.1.
|
|
32018
|
+
var version = "0.1.15";
|
|
30488
32019
|
|
|
30489
32020
|
//#endregion
|
|
30490
32021
|
//#region src/version.ts
|
|
@@ -32333,6 +33864,10 @@ var TuskDriftCore = class TuskDriftCore {
|
|
|
32333
33864
|
enabled: true,
|
|
32334
33865
|
mode: this.mode
|
|
32335
33866
|
});
|
|
33867
|
+
new MysqlInstrumentation({
|
|
33868
|
+
enabled: true,
|
|
33869
|
+
mode: this.mode
|
|
33870
|
+
});
|
|
32336
33871
|
}
|
|
32337
33872
|
initializeTracing({ baseDirectory }) {
|
|
32338
33873
|
const serviceName = this.config.service?.name || "unknown";
|