@use-tusk/drift-node-sdk 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -229,17 +229,28 @@ function withTuskDrift(nextConfig = {}, options = {}) {
229
229
  if (webpackOptions.isServer) {
230
230
  const originalExternals = webpackConfig.externals;
231
231
  const coreExternals = ["require-in-the-middle", "jsonpath"];
232
+ const externalsMapping = {};
233
+ try {
234
+ const sdkPath = require.resolve("@use-tusk/drift-node-sdk");
235
+ const sdkNodeModules = require("path").resolve(sdkPath, "../..", "node_modules");
236
+ for (const pkg of coreExternals) {
237
+ const pkgPath = require("path").join(sdkNodeModules, pkg);
238
+ externalsMapping[pkg] = `commonjs ${pkgPath}`;
239
+ debugLog(debug, `Mapped external ${pkg} -> ${pkgPath}`);
240
+ }
241
+ } catch (e) {
242
+ warn(suppressAllWarnings || false, `Could not resolve SDK path, falling back to regular externals: ${e instanceof Error ? e.message : String(e)}`);
243
+ for (const pkg of coreExternals) externalsMapping[pkg] = `commonjs ${pkg}`;
244
+ }
232
245
  if (!originalExternals) {
233
- webpackConfig.externals = coreExternals;
234
- debugLog(debug, "Created new externals array with core packages");
246
+ webpackConfig.externals = [externalsMapping];
247
+ debugLog(debug, "Created new externals with SDK paths");
235
248
  } else if (Array.isArray(originalExternals)) {
236
- for (const pkg of coreExternals) if (!originalExternals.includes(pkg)) {
237
- originalExternals.push(pkg);
238
- debugLog(debug, `Added ${pkg} to webpack externals`);
239
- }
249
+ originalExternals.push(externalsMapping);
250
+ debugLog(debug, "Added SDK paths to existing externals array");
240
251
  } else {
241
- webpackConfig.externals = [originalExternals, ...coreExternals];
242
- debugLog(debug, "Wrapped existing externals with core packages");
252
+ webpackConfig.externals = [originalExternals, externalsMapping];
253
+ debugLog(debug, "Wrapped existing externals with SDK paths");
243
254
  }
244
255
  }
245
256
  if (typeof config.webpack === "function") return config.webpack(webpackConfig, webpackOptions);
@@ -275,7 +286,7 @@ var TdInstrumentationAbstract = class {
275
286
 
276
287
  //#endregion
277
288
  //#region package.json
278
- var version = "0.1.8";
289
+ var version = "0.1.10";
279
290
 
280
291
  //#endregion
281
292
  //#region src/version.ts
@@ -1217,6 +1228,7 @@ async function httpBodyEncoder({ bodyBuffer, contentEncoding }) {
1217
1228
  * @returns The corresponding DecodedType enum value
1218
1229
  */
1219
1230
  function getDecodedType(contentType) {
1231
+ if (!contentType) return;
1220
1232
  const contentTypeString = Array.isArray(contentType) && contentType.length > 0 ? contentType[0] : contentType;
1221
1233
  if (!contentTypeString || typeof contentTypeString !== "string") {
1222
1234
  logger.debug(`Invalid Content-Type header: ${contentType}`);
@@ -1225,22 +1237,7 @@ function getDecodedType(contentType) {
1225
1237
  const mainType = contentTypeString.toLowerCase().split(";")[0].trim();
1226
1238
  return CONTENT_TYPE_MAPPING[mainType];
1227
1239
  }
1228
- const STATIC_ASSET_TYPES = new Set([
1229
- __use_tusk_drift_schemas_core_json_schema.DecodedType.HTML,
1230
- __use_tusk_drift_schemas_core_json_schema.DecodedType.CSS,
1231
- __use_tusk_drift_schemas_core_json_schema.DecodedType.JAVASCRIPT,
1232
- __use_tusk_drift_schemas_core_json_schema.DecodedType.JPEG,
1233
- __use_tusk_drift_schemas_core_json_schema.DecodedType.PNG,
1234
- __use_tusk_drift_schemas_core_json_schema.DecodedType.GIF,
1235
- __use_tusk_drift_schemas_core_json_schema.DecodedType.WEBP,
1236
- __use_tusk_drift_schemas_core_json_schema.DecodedType.SVG,
1237
- __use_tusk_drift_schemas_core_json_schema.DecodedType.PDF,
1238
- __use_tusk_drift_schemas_core_json_schema.DecodedType.AUDIO,
1239
- __use_tusk_drift_schemas_core_json_schema.DecodedType.VIDEO,
1240
- __use_tusk_drift_schemas_core_json_schema.DecodedType.BINARY,
1241
- __use_tusk_drift_schemas_core_json_schema.DecodedType.ZIP,
1242
- __use_tusk_drift_schemas_core_json_schema.DecodedType.GZIP
1243
- ]);
1240
+ const ACCEPTABLE_CONTENT_TYPES = new Set([__use_tusk_drift_schemas_core_json_schema.DecodedType.JSON, __use_tusk_drift_schemas_core_json_schema.DecodedType.PLAIN_TEXT]);
1244
1241
 
1245
1242
  //#endregion
1246
1243
  //#region src/instrumentation/libraries/http/mocks/TdHttpMockSocket.ts
@@ -1867,6 +1864,24 @@ var TdMockClientRequest = class TdMockClientRequest extends events.EventEmitter
1867
1864
  async startPlayback() {
1868
1865
  this.playbackStarted = true;
1869
1866
  try {
1867
+ if (!this.spanInfo) {
1868
+ logger.debug(`[TdMockClientRequest] Background request detected (no spanInfo), returning 200 OK without mock lookup`);
1869
+ const emptyResponse = {
1870
+ statusCode: 200,
1871
+ statusMessage: "OK",
1872
+ headers: {},
1873
+ httpVersion: "1.1",
1874
+ httpVersionMajor: 1,
1875
+ httpVersionMinor: 1,
1876
+ complete: true,
1877
+ readable: false
1878
+ };
1879
+ this.emit("finish");
1880
+ process.nextTick(() => {
1881
+ this.playResponse(emptyResponse);
1882
+ });
1883
+ return;
1884
+ }
1870
1885
  const rawInputValue = {
1871
1886
  method: this.method || "GET",
1872
1887
  path: this.path,
@@ -1904,7 +1919,10 @@ var TdMockClientRequest = class TdMockClientRequest extends events.EventEmitter
1904
1919
  headers: { matchImportance: 0 }
1905
1920
  }
1906
1921
  });
1907
- if (!mockData) throw new Error(`No matching mock found for ${this.method} ${this.path}`);
1922
+ if (!mockData) {
1923
+ logger.warn(`[TdMockClientRequest] No mock data found for ${this.method} ${this.path}`);
1924
+ throw new Error(`[TdMockClientRequest] No matching mock found for ${this.method} ${this.path}`);
1925
+ }
1908
1926
  this.emit("finish");
1909
1927
  process.nextTick(() => {
1910
1928
  this.playResponse(mockData.result);
@@ -2090,11 +2108,19 @@ function handleRecordMode({ originalFunctionCall, recordModeHandler, spanKind })
2090
2108
  /**
2091
2109
  * Utility function that abstracts the common replay mode pattern of checking if the app is ready
2092
2110
  *
2093
- * Currently just calls the replayModeHandler, but we might add some logic here in the future.
2111
+ * If this is a background request (app is ready and no parent span), calls the backgroundRequestHandler.
2112
+ * Otherwise, calls the replayModeHandler.
2094
2113
  * @param replayModeHandler - Function that handles the replay mode logic when app is ready
2095
- * @returns The result from either originalFunctionCall or replayModeHandler
2114
+ * @param noOpRequestHandler - Function to handle no-op requests, called for background requests
2115
+ * @returns The result from either noOpRequestHandler or replayModeHandler
2096
2116
  */
2097
- function handleReplayMode({ replayModeHandler }) {
2117
+ function handleReplayMode({ replayModeHandler, noOpRequestHandler, isServerRequest }) {
2118
+ const isAppReady = TuskDriftCore.getInstance().isAppReady();
2119
+ const currentSpanInfo = SpanUtils.getCurrentSpanInfo();
2120
+ if (isAppReady && !currentSpanInfo && !isServerRequest) {
2121
+ logger.debug(`[ModeUtils] Handling no-op request`);
2122
+ return noOpRequestHandler();
2123
+ }
2098
2124
  return replayModeHandler();
2099
2125
  }
2100
2126
 
@@ -2613,52 +2639,58 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
2613
2639
  logger.debug(`[HttpInstrumentation] Dropping inbound request due to transforms: ${method} ${url}`);
2614
2640
  return originalHandler.call(this);
2615
2641
  }
2616
- if (this.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
2617
- if (req.headers["accept-encoding"]) delete req.headers["accept-encoding"];
2618
- const fullUrl = `${spanProtocol}://${req.headers.host || "localhost"}${url}`;
2619
- const inputValue = {
2620
- method,
2621
- url: fullUrl,
2622
- target,
2623
- headers: req.headers,
2624
- httpVersion: req.httpVersion,
2625
- remoteAddress: req.socket?.remoteAddress,
2626
- remotePort: req.socket?.remotePort
2627
- };
2628
- const replayTraceId = this.replayHooks.extractTraceIdFromHeaders(req);
2629
- if (!replayTraceId) {
2630
- logger.debug(`[HttpInstrumentation] No trace id found in headers`, req.headers);
2631
- return originalHandler.call(this);
2632
- }
2633
- logger.debug(`[HttpInstrumentation] Setting replay trace id`, replayTraceId);
2634
- const envVars = this.replayHooks.extractEnvVarsFromHeaders(req);
2635
- if (envVars) EnvVarTracker.setEnvVars(replayTraceId, envVars);
2636
- const ctxWithReplayTraceId = SpanUtils.setCurrentReplayTraceId(replayTraceId);
2637
- if (!ctxWithReplayTraceId) throw new Error("Error setting current replay trace id");
2638
- return __opentelemetry_api.context.with(ctxWithReplayTraceId, () => {
2639
- return SpanUtils.createAndExecuteSpan(this.mode, () => originalHandler.call(this), {
2640
- name: `${target}`,
2641
- kind: __opentelemetry_api.SpanKind.SERVER,
2642
- packageName: spanProtocol,
2643
- submodule: method,
2644
- packageType: __use_tusk_drift_schemas_core_span.PackageType.HTTP,
2645
- instrumentationName: this.INSTRUMENTATION_NAME,
2646
- inputValue,
2647
- inputSchemaMerges: { headers: { matchImportance: 0 } },
2648
- isPreAppStart: false
2649
- }, (spanInfo) => {
2650
- return this._handleInboundRequestInSpan({
2651
- req,
2652
- res,
2653
- originalHandler,
2654
- spanInfo,
2642
+ if (this.mode === TuskDriftMode.REPLAY) return handleReplayMode({
2643
+ noOpRequestHandler: () => {
2644
+ throw new Error(`[HttpInstrumentation] Should never call noOpRequestHandler for server requests`);
2645
+ },
2646
+ isServerRequest: true,
2647
+ replayModeHandler: () => {
2648
+ if (req.headers["accept-encoding"]) delete req.headers["accept-encoding"];
2649
+ const fullUrl = `${spanProtocol}://${req.headers.host || "localhost"}${url}`;
2650
+ const inputValue = {
2651
+ method,
2652
+ url: fullUrl,
2653
+ target,
2654
+ headers: req.headers,
2655
+ httpVersion: req.httpVersion,
2656
+ remoteAddress: req.socket?.remoteAddress,
2657
+ remotePort: req.socket?.remotePort
2658
+ };
2659
+ const replayTraceId = this.replayHooks.extractTraceIdFromHeaders(req);
2660
+ if (!replayTraceId) {
2661
+ logger.debug(`[HttpInstrumentation] No trace id found in headers`, req.headers);
2662
+ return originalHandler.call(this);
2663
+ }
2664
+ logger.debug(`[HttpInstrumentation] Setting replay trace id`, replayTraceId);
2665
+ const envVars = this.replayHooks.extractEnvVarsFromHeaders(req);
2666
+ if (envVars) EnvVarTracker.setEnvVars(replayTraceId, envVars);
2667
+ const ctxWithReplayTraceId = SpanUtils.setCurrentReplayTraceId(replayTraceId);
2668
+ if (!ctxWithReplayTraceId) throw new Error("Error setting current replay trace id");
2669
+ return __opentelemetry_api.context.with(ctxWithReplayTraceId, () => {
2670
+ return SpanUtils.createAndExecuteSpan(this.mode, () => originalHandler.call(this), {
2671
+ name: `${target}`,
2672
+ kind: __opentelemetry_api.SpanKind.SERVER,
2673
+ packageName: spanProtocol,
2674
+ submodule: method,
2675
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.HTTP,
2676
+ instrumentationName: this.INSTRUMENTATION_NAME,
2655
2677
  inputValue,
2656
- schemaMerges: { headers: { matchImportance: 0 } },
2657
- protocol: spanProtocol
2678
+ inputSchemaMerges: { headers: { matchImportance: 0 } },
2679
+ isPreAppStart: false
2680
+ }, (spanInfo) => {
2681
+ return this._handleInboundRequestInSpan({
2682
+ req,
2683
+ res,
2684
+ originalHandler,
2685
+ spanInfo,
2686
+ inputValue,
2687
+ schemaMerges: { headers: { matchImportance: 0 } },
2688
+ protocol: spanProtocol
2689
+ });
2658
2690
  });
2659
2691
  });
2660
- });
2661
- } });
2692
+ }
2693
+ });
2662
2694
  else if (this.mode === TuskDriftMode.RECORD) {
2663
2695
  if (method.toUpperCase() === "OPTIONS" || !!req.headers["access-control-request-method"]) return originalHandler.call(this);
2664
2696
  logger.debug(`[HttpInstrumentation] Creating server span for ${method} ${url}`);
@@ -2785,9 +2817,9 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
2785
2817
  } : { code: __opentelemetry_api.SpanStatusCode.OK };
2786
2818
  SpanUtils.setStatus(spanInfo.span, status);
2787
2819
  const decodedType = getDecodedType(outputValue.headers?.["content-type"] || "");
2788
- if (decodedType && STATIC_ASSET_TYPES.has(decodedType)) {
2820
+ if (decodedType && !ACCEPTABLE_CONTENT_TYPES.has(decodedType)) {
2789
2821
  TraceBlockingManager.getInstance().blockTrace(spanInfo.traceId);
2790
- logger.debug(`[HttpInstrumentation] Blocking trace ${spanInfo.traceId} because it is an static asset response. Decoded type: ${decodedType}`);
2822
+ logger.debug(`[HttpInstrumentation] Blocking trace ${spanInfo.traceId} because it is not an acceptable decoded type: ${decodedType}`, { acceptableContentTypes: Array.from(ACCEPTABLE_CONTENT_TYPES) });
2791
2823
  }
2792
2824
  SpanUtils.endSpan(spanInfo.span);
2793
2825
  } catch (error) {
@@ -3139,37 +3171,48 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
3139
3171
  const requestProtocol = self._normalizeProtocol(requestOptions.protocol || void 0, protocol);
3140
3172
  if (self.mode === TuskDriftMode.REPLAY) {
3141
3173
  const stackTrace = captureStackTrace(["HttpInstrumentation"]);
3142
- return handleReplayMode({ replayModeHandler: () => {
3143
- const headers = normalizeHeaders(requestOptions.headers || {});
3144
- const inputValue = {
3145
- method,
3146
- path: requestOptions.path || void 0,
3147
- headers,
3148
- protocol: requestProtocol,
3149
- hostname: requestOptions.hostname || requestOptions.host || void 0,
3150
- port: requestOptions.port ? Number(requestOptions.port) : void 0,
3151
- timeout: requestOptions.timeout || void 0
3152
- };
3153
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalRequest.apply(this, args), {
3154
- name: requestOptions.path || `${requestProtocol.toUpperCase()} ${method}`,
3155
- kind: __opentelemetry_api.SpanKind.CLIENT,
3156
- packageName: requestProtocol,
3157
- packageType: __use_tusk_drift_schemas_core_span.PackageType.HTTP,
3158
- instrumentationName: self.INSTRUMENTATION_NAME,
3159
- submodule: method,
3160
- inputValue,
3161
- isPreAppStart: false
3162
- }, (spanInfo) => {
3174
+ return handleReplayMode({
3175
+ noOpRequestHandler: () => {
3163
3176
  return self.replayHooks.handleOutboundReplayRequest({
3164
3177
  method,
3165
3178
  requestOptions,
3166
3179
  protocol: requestProtocol,
3167
- args,
3168
- spanInfo,
3169
- stackTrace
3180
+ args
3170
3181
  });
3171
- });
3172
- } });
3182
+ },
3183
+ isServerRequest: false,
3184
+ replayModeHandler: () => {
3185
+ const headers = normalizeHeaders(requestOptions.headers || {});
3186
+ const inputValue = {
3187
+ method,
3188
+ path: requestOptions.path || void 0,
3189
+ headers,
3190
+ protocol: requestProtocol,
3191
+ hostname: requestOptions.hostname || requestOptions.host || void 0,
3192
+ port: requestOptions.port ? Number(requestOptions.port) : void 0,
3193
+ timeout: requestOptions.timeout || void 0
3194
+ };
3195
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalRequest.apply(this, args), {
3196
+ name: requestOptions.path || `${requestProtocol.toUpperCase()} ${method}`,
3197
+ kind: __opentelemetry_api.SpanKind.CLIENT,
3198
+ packageName: requestProtocol,
3199
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.HTTP,
3200
+ instrumentationName: self.INSTRUMENTATION_NAME,
3201
+ submodule: method,
3202
+ inputValue,
3203
+ isPreAppStart: false
3204
+ }, (spanInfo) => {
3205
+ return self.replayHooks.handleOutboundReplayRequest({
3206
+ method,
3207
+ requestOptions,
3208
+ protocol: requestProtocol,
3209
+ args,
3210
+ spanInfo,
3211
+ stackTrace
3212
+ });
3213
+ });
3214
+ }
3215
+ });
3173
3216
  } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
3174
3217
  originalFunctionCall: () => originalRequest.apply(this, args),
3175
3218
  recordModeHandler: ({ isPreAppStart }) => {
@@ -3221,36 +3264,47 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
3221
3264
  } else requestOptions = args[0] || {};
3222
3265
  const method = "GET";
3223
3266
  const requestProtocol = self._normalizeProtocol(requestOptions.protocol || void 0, protocol);
3224
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
3225
- const headers = normalizeHeaders(requestOptions.headers || {});
3226
- const inputValue = {
3227
- method,
3228
- path: requestOptions.path || void 0,
3229
- headers,
3230
- protocol: requestProtocol,
3231
- hostname: requestOptions.hostname || requestOptions.host || void 0,
3232
- port: requestOptions.port ? Number(requestOptions.port) : void 0,
3233
- timeout: requestOptions.timeout || void 0
3234
- };
3235
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalGet.apply(this, args), {
3236
- name: requestOptions.path || `${requestProtocol.toUpperCase()} ${method}`,
3237
- kind: __opentelemetry_api.SpanKind.CLIENT,
3238
- packageName: requestProtocol,
3239
- packageType: __use_tusk_drift_schemas_core_span.PackageType.HTTP,
3240
- instrumentationName: self.INSTRUMENTATION_NAME,
3241
- submodule: method,
3242
- inputValue,
3243
- isPreAppStart: false
3244
- }, (spanInfo) => {
3267
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
3268
+ noOpRequestHandler: () => {
3245
3269
  return self.replayHooks.handleOutboundReplayRequest({
3246
3270
  method,
3247
3271
  requestOptions,
3248
3272
  protocol: requestProtocol,
3249
- args,
3250
- spanInfo
3273
+ args
3251
3274
  });
3252
- });
3253
- } });
3275
+ },
3276
+ isServerRequest: false,
3277
+ replayModeHandler: () => {
3278
+ const headers = normalizeHeaders(requestOptions.headers || {});
3279
+ const inputValue = {
3280
+ method,
3281
+ path: requestOptions.path || void 0,
3282
+ headers,
3283
+ protocol: requestProtocol,
3284
+ hostname: requestOptions.hostname || requestOptions.host || void 0,
3285
+ port: requestOptions.port ? Number(requestOptions.port) : void 0,
3286
+ timeout: requestOptions.timeout || void 0
3287
+ };
3288
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalGet.apply(this, args), {
3289
+ name: requestOptions.path || `${requestProtocol.toUpperCase()} ${method}`,
3290
+ kind: __opentelemetry_api.SpanKind.CLIENT,
3291
+ packageName: requestProtocol,
3292
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.HTTP,
3293
+ instrumentationName: self.INSTRUMENTATION_NAME,
3294
+ submodule: method,
3295
+ inputValue,
3296
+ isPreAppStart: false
3297
+ }, (spanInfo) => {
3298
+ return self.replayHooks.handleOutboundReplayRequest({
3299
+ method,
3300
+ requestOptions,
3301
+ protocol: requestProtocol,
3302
+ args,
3303
+ spanInfo
3304
+ });
3305
+ });
3306
+ }
3307
+ });
3254
3308
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
3255
3309
  originalFunctionCall: () => originalGet.apply(this, args),
3256
3310
  recordModeHandler: ({ isPreAppStart }) => {
@@ -3646,7 +3700,8 @@ var TdPgClientMock = class extends events.EventEmitter {
3646
3700
  clientType: "client"
3647
3701
  };
3648
3702
  const inputValue = createMockInputValue(rawInputValue);
3649
- return this.pgInstrumentation.handleReplayQuery(queryConfig, inputValue, this.spanInfo, stackTrace);
3703
+ if (this.spanInfo) return this.pgInstrumentation.handleReplayQuery(queryConfig, inputValue, this.spanInfo, stackTrace);
3704
+ else return this.pgInstrumentation.handleNoOpReplayQuery(queryConfig);
3650
3705
  }
3651
3706
  release() {
3652
3707
  this.emit("end");
@@ -3751,22 +3806,28 @@ var PgInstrumentation = class extends TdInstrumentationBase {
3751
3806
  };
3752
3807
  if (self.mode === TuskDriftMode.REPLAY) {
3753
3808
  const stackTrace = captureStackTrace(["PgInstrumentation"]);
3754
- return handleReplayMode({ replayModeHandler: () => {
3755
- const packageName = inputValue.clientType === "pool" ? "pg-pool" : "pg";
3756
- const spanName = inputValue.clientType === "pool" ? "pg-pool.query" : "pg.query";
3757
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(this, args), {
3758
- name: spanName,
3759
- kind: __opentelemetry_api.SpanKind.CLIENT,
3760
- submodule: "query",
3761
- packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
3762
- packageName,
3763
- instrumentationName: self.INSTRUMENTATION_NAME,
3764
- inputValue,
3765
- isPreAppStart: false
3766
- }, (spanInfo) => {
3767
- return self.handleReplayQuery(queryConfig, inputValue, spanInfo, stackTrace);
3768
- });
3769
- } });
3809
+ return handleReplayMode({
3810
+ noOpRequestHandler: () => {
3811
+ return self.handleNoOpReplayQuery(queryConfig);
3812
+ },
3813
+ isServerRequest: false,
3814
+ replayModeHandler: () => {
3815
+ const packageName = inputValue.clientType === "pool" ? "pg-pool" : "pg";
3816
+ const spanName = inputValue.clientType === "pool" ? "pg-pool.query" : "pg.query";
3817
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(this, args), {
3818
+ name: spanName,
3819
+ kind: __opentelemetry_api.SpanKind.CLIENT,
3820
+ submodule: "query",
3821
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
3822
+ packageName,
3823
+ instrumentationName: self.INSTRUMENTATION_NAME,
3824
+ inputValue,
3825
+ isPreAppStart: false
3826
+ }, (spanInfo) => {
3827
+ return self.handleReplayQuery(queryConfig, inputValue, spanInfo, stackTrace);
3828
+ });
3829
+ }
3830
+ });
3770
3831
  } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
3771
3832
  originalFunctionCall: () => originalQuery.apply(this, args),
3772
3833
  recordModeHandler: ({ isPreAppStart }) => {
@@ -3796,20 +3857,29 @@ var PgInstrumentation = class extends TdInstrumentationBase {
3796
3857
  return (originalConnect) => {
3797
3858
  return function connect(callback) {
3798
3859
  const inputValue = { clientType };
3799
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
3800
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
3801
- name: `pg.connect`,
3802
- kind: __opentelemetry_api.SpanKind.CLIENT,
3803
- submodule: "connect",
3804
- packageName: "pg",
3805
- packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
3806
- instrumentationName: self.INSTRUMENTATION_NAME,
3807
- inputValue,
3808
- isPreAppStart: false
3809
- }, (spanInfo) => {
3810
- return self._handleReplayConnect(callback);
3811
- });
3812
- } });
3860
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
3861
+ noOpRequestHandler: () => {
3862
+ if (callback) {
3863
+ process.nextTick(() => callback(null));
3864
+ return;
3865
+ } else return Promise.resolve();
3866
+ },
3867
+ isServerRequest: false,
3868
+ replayModeHandler: () => {
3869
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
3870
+ name: `pg.connect`,
3871
+ kind: __opentelemetry_api.SpanKind.CLIENT,
3872
+ submodule: "connect",
3873
+ packageName: "pg",
3874
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
3875
+ instrumentationName: self.INSTRUMENTATION_NAME,
3876
+ inputValue,
3877
+ isPreAppStart: false
3878
+ }, (spanInfo) => {
3879
+ return self._handleReplayConnect(callback);
3880
+ });
3881
+ }
3882
+ });
3813
3883
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
3814
3884
  originalFunctionCall: () => originalConnect.apply(this, [callback]),
3815
3885
  recordModeHandler: ({ isPreAppStart }) => {
@@ -3913,6 +3983,16 @@ var PgInstrumentation = class extends TdInstrumentationBase {
3913
3983
  throw error;
3914
3984
  });
3915
3985
  }
3986
+ async handleNoOpReplayQuery(queryConfig) {
3987
+ const emptyResult = {
3988
+ rows: [],
3989
+ rowCount: 0
3990
+ };
3991
+ if (queryConfig.callback) {
3992
+ process.nextTick(() => queryConfig.callback(null, emptyResult));
3993
+ return;
3994
+ } else return Promise.resolve(emptyResult);
3995
+ }
3916
3996
  async handleReplayQuery(queryConfig, inputValue, spanInfo, stackTrace) {
3917
3997
  logger.debug(`[PgInstrumentation] Replaying PG query`);
3918
3998
  const packageName = inputValue.clientType === "pool" ? "pg-pool" : "pg";
@@ -3934,10 +4014,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
3934
4014
  if (!mockData) {
3935
4015
  const queryText = queryConfig.text || inputValue.text || "UNKNOWN_QUERY";
3936
4016
  logger.warn(`[PgInstrumentation] No mock data found for PG query: ${queryText}`);
3937
- if (queryConfig.callback) {
3938
- process.nextTick(() => queryConfig.callback(/* @__PURE__ */ new Error("No mock data found")));
3939
- return;
3940
- } else return Promise.reject(/* @__PURE__ */ new Error("No mock data found"));
4017
+ throw new Error(`[PgInstrumentation] No mock data found for PG query: ${queryText}`);
3941
4018
  }
3942
4019
  const processedResult = this.convertPostgresTypes(mockData.result);
3943
4020
  if (queryConfig.callback) {
@@ -4072,20 +4149,30 @@ var PgInstrumentation = class extends TdInstrumentationBase {
4072
4149
  return (originalConnect) => {
4073
4150
  return function connect(callback) {
4074
4151
  const inputValue = { clientType: "pool" };
4075
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
4076
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
4077
- name: `pg-pool.connect`,
4078
- kind: __opentelemetry_api.SpanKind.CLIENT,
4079
- submodule: "connect",
4080
- packageName: "pg-pool",
4081
- packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
4082
- instrumentationName: self.INSTRUMENTATION_NAME,
4083
- inputValue,
4084
- isPreAppStart: false
4085
- }, (spanInfo) => {
4086
- return self._handleReplayPoolConnect(spanInfo, callback);
4087
- });
4088
- } });
4152
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
4153
+ noOpRequestHandler: () => {
4154
+ const mockClient = new TdPgClientMock(self);
4155
+ if (callback) {
4156
+ process.nextTick(() => callback(null, mockClient, () => {}));
4157
+ return;
4158
+ } else return Promise.resolve(mockClient);
4159
+ },
4160
+ isServerRequest: false,
4161
+ replayModeHandler: () => {
4162
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
4163
+ name: `pg-pool.connect`,
4164
+ kind: __opentelemetry_api.SpanKind.CLIENT,
4165
+ submodule: "connect",
4166
+ packageName: "pg-pool",
4167
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
4168
+ instrumentationName: self.INSTRUMENTATION_NAME,
4169
+ inputValue,
4170
+ isPreAppStart: false
4171
+ }, (spanInfo) => {
4172
+ return self._handleReplayPoolConnect(spanInfo, callback);
4173
+ });
4174
+ }
4175
+ });
4089
4176
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
4090
4177
  originalFunctionCall: () => originalConnect.apply(this, [callback]),
4091
4178
  recordModeHandler: ({ isPreAppStart }) => {
@@ -4248,23 +4335,35 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
4248
4335
  connectionString: connectionString ? this._sanitizeConnectionString(connectionString) : void 0,
4249
4336
  options: options ? this._sanitizeConnectionOptions(options) : void 0
4250
4337
  };
4251
- if (this.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
4252
- return SpanUtils.createAndExecuteSpan(this.mode, () => {
4253
- const sqlInstance = originalFunction(...args);
4254
- return this._wrapSqlInstance(sqlInstance);
4255
- }, {
4256
- name: "postgres.connect",
4257
- kind: __opentelemetry_api.SpanKind.CLIENT,
4258
- submodule: "connect",
4259
- packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
4260
- packageName: "postgres",
4261
- instrumentationName: this.INSTRUMENTATION_NAME,
4262
- inputValue,
4263
- isPreAppStart: false
4264
- }, (spanInfo) => {
4265
- return this._handleReplayConnect(spanInfo, originalFunction, args);
4266
- });
4267
- } });
4338
+ if (this.mode === TuskDriftMode.REPLAY) return handleReplayMode({
4339
+ noOpRequestHandler: () => {
4340
+ try {
4341
+ const sqlInstance = originalFunction(...args);
4342
+ return this._wrapSqlInstance(sqlInstance);
4343
+ } catch (error) {
4344
+ logger.debug(`[PostgresInstrumentation] Postgres connection error in replay: ${error.message}`);
4345
+ throw error;
4346
+ }
4347
+ },
4348
+ isServerRequest: false,
4349
+ replayModeHandler: () => {
4350
+ return SpanUtils.createAndExecuteSpan(this.mode, () => {
4351
+ const sqlInstance = originalFunction(...args);
4352
+ return this._wrapSqlInstance(sqlInstance);
4353
+ }, {
4354
+ name: "postgres.connect",
4355
+ kind: __opentelemetry_api.SpanKind.CLIENT,
4356
+ submodule: "connect",
4357
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
4358
+ packageName: "postgres",
4359
+ instrumentationName: this.INSTRUMENTATION_NAME,
4360
+ inputValue,
4361
+ isPreAppStart: false
4362
+ }, (spanInfo) => {
4363
+ return this._handleReplayConnect(originalFunction, args);
4364
+ });
4365
+ }
4366
+ });
4268
4367
  else if (this.mode === TuskDriftMode.RECORD) return handleRecordMode({
4269
4368
  originalFunctionCall: () => {
4270
4369
  const sqlInstance = originalFunction(...args);
@@ -4324,20 +4423,13 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
4324
4423
  }
4325
4424
  return wrappedInstance;
4326
4425
  }
4327
- _handleReplayConnect(spanInfo, originalFunction, args) {
4426
+ _handleReplayConnect(originalFunction, args) {
4328
4427
  logger.debug(`[PostgresInstrumentation] Replaying Postgres connection`);
4329
4428
  try {
4330
4429
  const sqlInstance = originalFunction(...args);
4331
- const wrappedInstance = this._wrapSqlInstance(sqlInstance);
4332
- SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: { connected: true } });
4333
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.OK });
4334
- return wrappedInstance;
4430
+ return this._wrapSqlInstance(sqlInstance);
4335
4431
  } catch (error) {
4336
4432
  logger.debug(`[PostgresInstrumentation] Postgres connection error in replay: ${error.message}`);
4337
- SpanUtils.endSpan(spanInfo.span, {
4338
- code: __opentelemetry_api.SpanStatusCode.ERROR,
4339
- message: error.message
4340
- });
4341
4433
  throw error;
4342
4434
  }
4343
4435
  }
@@ -4397,26 +4489,30 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
4397
4489
  };
4398
4490
  if (this.mode === TuskDriftMode.REPLAY) {
4399
4491
  const stackTrace = captureStackTrace(["PostgresInstrumentation"]);
4400
- return handleReplayMode({ replayModeHandler: () => {
4401
- return SpanUtils.createAndExecuteSpan(this.mode, () => originalSql.call(this, strings, ...values), {
4402
- name: "postgres.query",
4403
- kind: __opentelemetry_api.SpanKind.CLIENT,
4404
- submodule: "query",
4405
- packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
4406
- packageName: "postgres",
4407
- instrumentationName: this.INSTRUMENTATION_NAME,
4408
- inputValue,
4409
- isPreAppStart: false
4410
- }, (spanInfo) => {
4411
- return this.handleReplaySqlQuery({
4412
- inputValue,
4413
- spanInfo,
4414
- submodule: "query",
4492
+ return handleReplayMode({
4493
+ noOpRequestHandler: () => {},
4494
+ isServerRequest: false,
4495
+ replayModeHandler: () => {
4496
+ return SpanUtils.createAndExecuteSpan(this.mode, () => originalSql.call(this, strings, ...values), {
4415
4497
  name: "postgres.query",
4416
- stackTrace
4498
+ kind: __opentelemetry_api.SpanKind.CLIENT,
4499
+ submodule: "query",
4500
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
4501
+ packageName: "postgres",
4502
+ instrumentationName: this.INSTRUMENTATION_NAME,
4503
+ inputValue,
4504
+ isPreAppStart: false
4505
+ }, (spanInfo) => {
4506
+ return this.handleReplaySqlQuery({
4507
+ inputValue,
4508
+ spanInfo,
4509
+ submodule: "query",
4510
+ name: "postgres.query",
4511
+ stackTrace
4512
+ });
4417
4513
  });
4418
- });
4419
- } });
4514
+ }
4515
+ });
4420
4516
  } else if (this.mode === TuskDriftMode.RECORD) return handleRecordMode({
4421
4517
  originalFunctionCall: () => originalSql.call(this, strings, ...values),
4422
4518
  recordModeHandler: ({ isPreAppStart }) => {
@@ -4450,28 +4546,34 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
4450
4546
  };
4451
4547
  if (this.mode === TuskDriftMode.REPLAY) {
4452
4548
  const stackTrace = captureStackTrace(["PostgresInstrumentation"]);
4453
- return handleReplayMode({ replayModeHandler: () => {
4454
- return this._createPendingQueryWrapper(() => {
4455
- return SpanUtils.createAndExecuteSpan(this.mode, () => executeUnsafe(), {
4456
- name: "postgres.unsafe",
4457
- kind: __opentelemetry_api.SpanKind.CLIENT,
4458
- submodule: "unsafe",
4459
- packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
4460
- packageName: "postgres",
4461
- instrumentationName: this.INSTRUMENTATION_NAME,
4462
- inputValue,
4463
- isPreAppStart: false
4464
- }, (spanInfo) => {
4465
- return this.handleReplayUnsafeQuery({
4466
- inputValue,
4467
- spanInfo,
4468
- submodule: "unsafe",
4549
+ return handleReplayMode({
4550
+ noOpRequestHandler: () => {
4551
+ return Promise.resolve(void 0);
4552
+ },
4553
+ isServerRequest: false,
4554
+ replayModeHandler: () => {
4555
+ return this._createPendingQueryWrapper(() => {
4556
+ return SpanUtils.createAndExecuteSpan(this.mode, () => executeUnsafe(), {
4469
4557
  name: "postgres.unsafe",
4470
- stackTrace
4558
+ kind: __opentelemetry_api.SpanKind.CLIENT,
4559
+ submodule: "unsafe",
4560
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
4561
+ packageName: "postgres",
4562
+ instrumentationName: this.INSTRUMENTATION_NAME,
4563
+ inputValue,
4564
+ isPreAppStart: false
4565
+ }, (spanInfo) => {
4566
+ return this.handleReplayUnsafeQuery({
4567
+ inputValue,
4568
+ spanInfo,
4569
+ submodule: "unsafe",
4570
+ name: "postgres.unsafe",
4571
+ stackTrace
4572
+ });
4471
4573
  });
4472
4574
  });
4473
- });
4474
- } });
4575
+ }
4576
+ });
4475
4577
  } else if (this.mode === TuskDriftMode.RECORD) return handleRecordMode({
4476
4578
  originalFunctionCall: executeUnsafe,
4477
4579
  recordModeHandler: ({ isPreAppStart }) => {
@@ -4504,20 +4606,24 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
4504
4606
  };
4505
4607
  if (this.mode === TuskDriftMode.REPLAY) {
4506
4608
  const stackTrace = captureStackTrace(["PostgresInstrumentation"]);
4507
- return handleReplayMode({ replayModeHandler: () => {
4508
- return SpanUtils.createAndExecuteSpan(this.mode, () => executeBegin(), {
4509
- name: "postgres.begin",
4510
- kind: __opentelemetry_api.SpanKind.CLIENT,
4511
- submodule: "transaction",
4512
- packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
4513
- packageName: "postgres",
4514
- instrumentationName: this.INSTRUMENTATION_NAME,
4515
- inputValue,
4516
- isPreAppStart: false
4517
- }, (spanInfo) => {
4518
- return this._handleReplayBeginTransaction(spanInfo, options, stackTrace);
4519
- });
4520
- } });
4609
+ return handleReplayMode({
4610
+ noOpRequestHandler: () => {},
4611
+ isServerRequest: false,
4612
+ replayModeHandler: () => {
4613
+ return SpanUtils.createAndExecuteSpan(this.mode, () => executeBegin(), {
4614
+ name: "postgres.begin",
4615
+ kind: __opentelemetry_api.SpanKind.CLIENT,
4616
+ submodule: "transaction",
4617
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
4618
+ packageName: "postgres",
4619
+ instrumentationName: this.INSTRUMENTATION_NAME,
4620
+ inputValue,
4621
+ isPreAppStart: false
4622
+ }, (spanInfo) => {
4623
+ return this._handleReplayBeginTransaction(spanInfo, options, stackTrace);
4624
+ });
4625
+ }
4626
+ });
4521
4627
  } else if (this.mode === TuskDriftMode.RECORD) return handleRecordMode({
4522
4628
  originalFunctionCall: executeBegin,
4523
4629
  recordModeHandler: ({ isPreAppStart }) => {
@@ -4633,28 +4739,13 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
4633
4739
  });
4634
4740
  if (!mockData) {
4635
4741
  logger.warn(`[PostgresInstrumentation] No mock data found for transaction BEGIN`);
4636
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.OK });
4637
- return;
4742
+ throw new Error(`[PostgresInstrumentation] No matching mock found for transaction BEGIN`);
4638
4743
  }
4639
4744
  logger.debug(`[PostgresInstrumentation] Found mock data for transaction: ${JSON.stringify(mockData)}`);
4640
4745
  const transactionResult = mockData.result;
4641
- if (transactionResult && typeof transactionResult === "object" && "status" in transactionResult && transactionResult.status === "committed") {
4642
- SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: {
4643
- status: "committed",
4644
- result: transactionResult.result
4645
- } });
4646
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.OK });
4647
- return transactionResult.result;
4648
- } else {
4746
+ if (transactionResult && typeof transactionResult === "object" && "status" in transactionResult && transactionResult.status === "committed") return transactionResult.result;
4747
+ else {
4649
4748
  const errorMessage = transactionResult && typeof transactionResult === "object" && "error" in transactionResult && transactionResult.error ? transactionResult.error : "Transaction rolled back";
4650
- SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: {
4651
- status: "rolled_back",
4652
- error: errorMessage
4653
- } });
4654
- SpanUtils.endSpan(spanInfo.span, {
4655
- code: __opentelemetry_api.SpanStatusCode.ERROR,
4656
- message: errorMessage
4657
- });
4658
4749
  throw new Error(errorMessage);
4659
4750
  }
4660
4751
  }
@@ -4701,7 +4792,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
4701
4792
  if (!mockData) {
4702
4793
  const queryText = inputValue.query || "UNKNOWN_QUERY";
4703
4794
  logger.warn(`[PostgresInstrumentation] No mock data found for Postgres sql query: ${queryText}`);
4704
- return;
4795
+ throw new Error(`[PostgresInstrumentation] No matching mock found for Postgres sql query: ${queryText}`);
4705
4796
  }
4706
4797
  logger.debug(`[PostgresInstrumentation] Found mock data for Postgres sql query: ${JSON.stringify(mockData)}`);
4707
4798
  const processedResult = this.convertPostgresTypes(mockData.result);
@@ -4732,7 +4823,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
4732
4823
  if (!mockData) {
4733
4824
  const queryText = inputValue.query || "UNKNOWN_QUERY";
4734
4825
  logger.warn(`[PostgresInstrumentation] No mock data found for Postgres unsafe query: ${queryText}`);
4735
- return;
4826
+ throw new Error(`[PostgresInstrumentation] No matching mock found for Postgres unsafe query: ${queryText}`);
4736
4827
  }
4737
4828
  logger.debug(`[PostgresInstrumentation] Found mock data for Postgres unsafe query: ${JSON.stringify(mockData)}`);
4738
4829
  const processedResult = this.convertPostgresTypes(mockData.result);
@@ -4821,7 +4912,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
4821
4912
  * Extends EventEmitter to properly handle all connection methods and events
4822
4913
  */
4823
4914
  var TdMysql2ConnectionMock = class extends events.EventEmitter {
4824
- constructor(mysql2Instrumentation, spanInfo, clientType = "poolConnection") {
4915
+ constructor(mysql2Instrumentation, clientType = "poolConnection", spanInfo) {
4825
4916
  super();
4826
4917
  this.threadId = null;
4827
4918
  this.config = {
@@ -4857,7 +4948,8 @@ var TdMysql2ConnectionMock = class extends events.EventEmitter {
4857
4948
  clientType: this.clientType
4858
4949
  };
4859
4950
  const inputValue = createMockInputValue(rawInputValue);
4860
- return this.mysql2Instrumentation.handleReplayQuery(queryConfig, inputValue, this.spanInfo, stackTrace);
4951
+ if (this.spanInfo) return this.mysql2Instrumentation.handleReplayQuery(queryConfig, inputValue, this.spanInfo, stackTrace);
4952
+ else return this.mysql2Instrumentation.handleNoOpReplayQuery(queryConfig);
4861
4953
  }
4862
4954
  execute(...args) {
4863
4955
  logger.debug(`[TdMysql2ConnectionMock] Mock connection execute intercepted in REPLAY mode`);
@@ -4881,7 +4973,8 @@ var TdMysql2ConnectionMock = class extends events.EventEmitter {
4881
4973
  clientType: this.clientType
4882
4974
  };
4883
4975
  const inputValue = createMockInputValue(rawInputValue);
4884
- return this.mysql2Instrumentation.handleReplayQuery(queryConfig, inputValue, this.spanInfo, stackTrace);
4976
+ if (this.spanInfo) return this.mysql2Instrumentation.handleReplayQuery(queryConfig, inputValue, this.spanInfo, stackTrace);
4977
+ else return this.mysql2Instrumentation.handleNoOpReplayQuery(queryConfig);
4885
4978
  }
4886
4979
  release() {
4887
4980
  this.emit("end");
@@ -4981,6 +5074,27 @@ var TdMysql2QueryMock = class {
4981
5074
  return this._handleQuery(queryConfig, inputValue, spanInfo, spanName, submoduleName, stackTrace);
4982
5075
  }
4983
5076
  /**
5077
+ * Handle background query requests (outside of trace context)
5078
+ * Returns an EventEmitter that immediately completes with empty results
5079
+ */
5080
+ handleNoOpReplayQuery(queryConfig) {
5081
+ logger.debug(`[Mysql2Instrumentation] Background query detected, returning empty result`);
5082
+ const emitter = new events.EventEmitter();
5083
+ emitter.then = function(onResolve, onReject) {
5084
+ return new Promise((resolve) => {
5085
+ emitter.once("end", () => {
5086
+ resolve([[], []]);
5087
+ });
5088
+ }).then(onResolve, onReject);
5089
+ };
5090
+ process.nextTick(() => {
5091
+ const callback = queryConfig.callback;
5092
+ if (callback) callback(null, [], []);
5093
+ emitter.emit("end");
5094
+ });
5095
+ return emitter;
5096
+ }
5097
+ /**
4984
5098
  * Handle query - always returns an EventEmitter (like mysql2 does)
4985
5099
  * This handles both callback and streaming modes
4986
5100
  * The EventEmitter is also thenable (has a .then() method) to support await/Promise usage
@@ -5005,12 +5119,7 @@ var TdMysql2QueryMock = class {
5005
5119
  if (!mockData) {
5006
5120
  const sql = queryConfig.sql || inputValue.sql || "UNKNOWN_QUERY";
5007
5121
  logger.warn(`[Mysql2Instrumentation] No mock data found for MySQL2 query: ${sql}`);
5008
- const error = /* @__PURE__ */ new Error("No mock data found");
5009
- process.nextTick(() => {
5010
- if (queryConfig.callback) queryConfig.callback(error);
5011
- emitter.emit("error", error);
5012
- });
5013
- return;
5122
+ throw new Error(`[Mysql2Instrumentation] No matching mock found for query: ${sql}`);
5014
5123
  }
5015
5124
  const processedResult = this._convertMysql2Types(mockData.result);
5016
5125
  storedRows = processedResult.rows;
@@ -5335,21 +5444,27 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
5335
5444
  };
5336
5445
  if (self.mode === TuskDriftMode.REPLAY) {
5337
5446
  const stackTrace = captureStackTrace(["Mysql2Instrumentation"]);
5338
- return handleReplayMode({ replayModeHandler: () => {
5339
- const spanName = `mysql2.${clientType}.query`;
5340
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(this, args), {
5341
- name: spanName,
5342
- kind: __opentelemetry_api.SpanKind.CLIENT,
5343
- submodule: "query",
5344
- packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5345
- packageName: "mysql2",
5346
- instrumentationName: self.INSTRUMENTATION_NAME,
5347
- inputValue,
5348
- isPreAppStart: false
5349
- }, (spanInfo) => {
5350
- return self.handleReplayQuery(queryConfig, inputValue, spanInfo, "query", stackTrace);
5351
- });
5352
- } });
5447
+ return handleReplayMode({
5448
+ noOpRequestHandler: () => {
5449
+ return self.queryMock.handleNoOpReplayQuery(queryConfig);
5450
+ },
5451
+ isServerRequest: false,
5452
+ replayModeHandler: () => {
5453
+ const spanName = `mysql2.${clientType}.query`;
5454
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(this, args), {
5455
+ name: spanName,
5456
+ kind: __opentelemetry_api.SpanKind.CLIENT,
5457
+ submodule: "query",
5458
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5459
+ packageName: "mysql2",
5460
+ instrumentationName: self.INSTRUMENTATION_NAME,
5461
+ inputValue,
5462
+ isPreAppStart: false
5463
+ }, (spanInfo) => {
5464
+ return self.handleReplayQuery(queryConfig, inputValue, spanInfo, "query", stackTrace);
5465
+ });
5466
+ }
5467
+ });
5353
5468
  } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
5354
5469
  originalFunctionCall: () => originalQuery.apply(this, args),
5355
5470
  recordModeHandler: ({ isPreAppStart }) => {
@@ -5394,21 +5509,27 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
5394
5509
  };
5395
5510
  if (self.mode === TuskDriftMode.REPLAY) {
5396
5511
  const stackTrace = captureStackTrace(["Mysql2Instrumentation"]);
5397
- return handleReplayMode({ replayModeHandler: () => {
5398
- const spanName = `mysql2.${clientType}.execute`;
5399
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalExecute.apply(this, args), {
5400
- name: spanName,
5401
- kind: __opentelemetry_api.SpanKind.CLIENT,
5402
- submodule: "execute",
5403
- packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5404
- packageName: "mysql2",
5405
- instrumentationName: self.INSTRUMENTATION_NAME,
5406
- inputValue,
5407
- isPreAppStart: false
5408
- }, (spanInfo) => {
5409
- return self.handleReplayQuery(queryConfig, inputValue, spanInfo, "execute", stackTrace);
5410
- });
5411
- } });
5512
+ return handleReplayMode({
5513
+ noOpRequestHandler: () => {
5514
+ return self.queryMock.handleNoOpReplayQuery(queryConfig);
5515
+ },
5516
+ isServerRequest: false,
5517
+ replayModeHandler: () => {
5518
+ const spanName = `mysql2.${clientType}.execute`;
5519
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalExecute.apply(this, args), {
5520
+ name: spanName,
5521
+ kind: __opentelemetry_api.SpanKind.CLIENT,
5522
+ submodule: "execute",
5523
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5524
+ packageName: "mysql2",
5525
+ instrumentationName: self.INSTRUMENTATION_NAME,
5526
+ inputValue,
5527
+ isPreAppStart: false
5528
+ }, (spanInfo) => {
5529
+ return self.handleReplayQuery(queryConfig, inputValue, spanInfo, "execute", stackTrace);
5530
+ });
5531
+ }
5532
+ });
5412
5533
  } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
5413
5534
  originalFunctionCall: () => originalExecute.apply(this, args),
5414
5535
  recordModeHandler: ({ isPreAppStart }) => {
@@ -5437,20 +5558,26 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
5437
5558
  return (originalGetConnection) => {
5438
5559
  return function getConnection(callback) {
5439
5560
  const inputValue = { clientType: "pool" };
5440
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
5441
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalGetConnection.apply(this, [callback]), {
5442
- name: `mysql2.pool.getConnection`,
5443
- kind: __opentelemetry_api.SpanKind.CLIENT,
5444
- submodule: "getConnection",
5445
- packageName: "mysql2",
5446
- packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5447
- instrumentationName: self.INSTRUMENTATION_NAME,
5448
- inputValue,
5449
- isPreAppStart: false
5450
- }, (spanInfo) => {
5451
- return self._handleReplayPoolGetConnection(spanInfo, callback);
5452
- });
5453
- } });
5561
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
5562
+ noOpRequestHandler: () => {
5563
+ return self.handleNoOpReplayGetConnection(callback);
5564
+ },
5565
+ isServerRequest: false,
5566
+ replayModeHandler: () => {
5567
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalGetConnection.apply(this, [callback]), {
5568
+ name: `mysql2.pool.getConnection`,
5569
+ kind: __opentelemetry_api.SpanKind.CLIENT,
5570
+ submodule: "getConnection",
5571
+ packageName: "mysql2",
5572
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5573
+ instrumentationName: self.INSTRUMENTATION_NAME,
5574
+ inputValue,
5575
+ isPreAppStart: false
5576
+ }, (spanInfo) => {
5577
+ return self._handleReplayPoolGetConnection(spanInfo, callback);
5578
+ });
5579
+ }
5580
+ });
5454
5581
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
5455
5582
  originalFunctionCall: () => originalGetConnection.apply(this, [callback]),
5456
5583
  recordModeHandler: ({ isPreAppStart }) => {
@@ -5478,24 +5605,34 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
5478
5605
  return (originalConnect) => {
5479
5606
  return function connect(callback) {
5480
5607
  const inputValue = { clientType };
5481
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
5482
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
5483
- name: `mysql2.${clientType}.connect`,
5484
- kind: __opentelemetry_api.SpanKind.CLIENT,
5485
- submodule: "connect",
5486
- packageName: "mysql2",
5487
- packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5488
- instrumentationName: self.INSTRUMENTATION_NAME,
5489
- inputValue,
5490
- isPreAppStart: false
5491
- }, (spanInfo) => {
5608
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
5609
+ noOpRequestHandler: () => {
5492
5610
  if (callback) {
5493
5611
  process.nextTick(() => callback(null));
5494
5612
  return;
5495
5613
  }
5496
5614
  return Promise.resolve();
5497
- });
5498
- } });
5615
+ },
5616
+ isServerRequest: false,
5617
+ replayModeHandler: () => {
5618
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
5619
+ name: `mysql2.${clientType}.connect`,
5620
+ kind: __opentelemetry_api.SpanKind.CLIENT,
5621
+ submodule: "connect",
5622
+ packageName: "mysql2",
5623
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5624
+ instrumentationName: self.INSTRUMENTATION_NAME,
5625
+ inputValue,
5626
+ isPreAppStart: false
5627
+ }, (spanInfo) => {
5628
+ if (callback) {
5629
+ process.nextTick(() => callback(null));
5630
+ return;
5631
+ }
5632
+ return Promise.resolve();
5633
+ });
5634
+ }
5635
+ });
5499
5636
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
5500
5637
  originalFunctionCall: () => originalConnect.apply(this, [callback]),
5501
5638
  recordModeHandler: ({ isPreAppStart }) => {
@@ -5523,24 +5660,34 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
5523
5660
  return (originalPing) => {
5524
5661
  return function ping(callback) {
5525
5662
  const inputValue = { clientType };
5526
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
5527
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalPing.apply(this, [callback]), {
5528
- name: `mysql2.${clientType}.ping`,
5529
- kind: __opentelemetry_api.SpanKind.CLIENT,
5530
- submodule: "ping",
5531
- packageName: "mysql2",
5532
- packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5533
- instrumentationName: self.INSTRUMENTATION_NAME,
5534
- inputValue,
5535
- isPreAppStart: false
5536
- }, (spanInfo) => {
5663
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
5664
+ noOpRequestHandler: () => {
5537
5665
  if (callback) {
5538
5666
  process.nextTick(() => callback(null));
5539
5667
  return;
5540
5668
  }
5541
5669
  return Promise.resolve();
5542
- });
5543
- } });
5670
+ },
5671
+ isServerRequest: false,
5672
+ replayModeHandler: () => {
5673
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalPing.apply(this, [callback]), {
5674
+ name: `mysql2.${clientType}.ping`,
5675
+ kind: __opentelemetry_api.SpanKind.CLIENT,
5676
+ submodule: "ping",
5677
+ packageName: "mysql2",
5678
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5679
+ instrumentationName: self.INSTRUMENTATION_NAME,
5680
+ inputValue,
5681
+ isPreAppStart: false
5682
+ }, (spanInfo) => {
5683
+ if (callback) {
5684
+ process.nextTick(() => callback(null));
5685
+ return;
5686
+ }
5687
+ return Promise.resolve();
5688
+ });
5689
+ }
5690
+ });
5544
5691
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
5545
5692
  originalFunctionCall: () => originalPing.apply(this, [callback]),
5546
5693
  recordModeHandler: ({ isPreAppStart }) => {
@@ -5568,24 +5715,34 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
5568
5715
  return (originalEnd) => {
5569
5716
  return function end(callback) {
5570
5717
  const inputValue = { clientType };
5571
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
5572
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalEnd.apply(this, [callback]), {
5573
- name: `mysql2.${clientType}.end`,
5574
- kind: __opentelemetry_api.SpanKind.CLIENT,
5575
- submodule: "end",
5576
- packageName: "mysql2",
5577
- packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5578
- instrumentationName: self.INSTRUMENTATION_NAME,
5579
- inputValue,
5580
- isPreAppStart: false
5581
- }, (spanInfo) => {
5718
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
5719
+ noOpRequestHandler: () => {
5582
5720
  if (callback) {
5583
5721
  process.nextTick(() => callback(null));
5584
5722
  return;
5585
5723
  }
5586
5724
  return Promise.resolve();
5587
- });
5588
- } });
5725
+ },
5726
+ isServerRequest: false,
5727
+ replayModeHandler: () => {
5728
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalEnd.apply(this, [callback]), {
5729
+ name: `mysql2.${clientType}.end`,
5730
+ kind: __opentelemetry_api.SpanKind.CLIENT,
5731
+ submodule: "end",
5732
+ packageName: "mysql2",
5733
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5734
+ instrumentationName: self.INSTRUMENTATION_NAME,
5735
+ inputValue,
5736
+ isPreAppStart: false
5737
+ }, (spanInfo) => {
5738
+ if (callback) {
5739
+ process.nextTick(() => callback(null));
5740
+ return;
5741
+ }
5742
+ return Promise.resolve();
5743
+ });
5744
+ }
5745
+ });
5589
5746
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
5590
5747
  originalFunctionCall: () => originalEnd.apply(this, [callback]),
5591
5748
  recordModeHandler: ({ isPreAppStart }) => {
@@ -5760,6 +5917,9 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
5760
5917
  handleReplayQuery(queryConfig, inputValue, spanInfo, submoduleName = "query", stackTrace) {
5761
5918
  return this.queryMock.handleReplayQuery(queryConfig, inputValue, spanInfo, submoduleName, stackTrace);
5762
5919
  }
5920
+ handleNoOpReplayQuery(queryConfig) {
5921
+ return this.queryMock.handleNoOpReplayQuery(queryConfig);
5922
+ }
5763
5923
  _handleRecordPoolGetConnectionInSpan(spanInfo, originalGetConnection, callback, context$4) {
5764
5924
  if (callback) {
5765
5925
  const wrappedCallback = (error, connection) => {
@@ -5813,9 +5973,18 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
5813
5973
  throw error;
5814
5974
  });
5815
5975
  }
5976
+ handleNoOpReplayGetConnection(callback) {
5977
+ logger.debug(`[Mysql2Instrumentation] Background getConnection detected, returning mock connection`);
5978
+ const mockConnection = new TdMysql2ConnectionMock(this, "pool");
5979
+ if (callback) {
5980
+ process.nextTick(() => callback(null, mockConnection));
5981
+ return;
5982
+ }
5983
+ return Promise.resolve(mockConnection);
5984
+ }
5816
5985
  _handleReplayPoolGetConnection(spanInfo, callback) {
5817
5986
  logger.debug(`[Mysql2Instrumentation] Replaying MySQL2 Pool getConnection`);
5818
- const mockConnection = new TdMysql2ConnectionMock(this, spanInfo, "pool");
5987
+ const mockConnection = new TdMysql2ConnectionMock(this, "pool", spanInfo);
5819
5988
  if (callback) {
5820
5989
  process.nextTick(() => callback(null, mockConnection));
5821
5990
  return;
@@ -5874,58 +6043,59 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
5874
6043
  },
5875
6044
  spanKind: __opentelemetry_api.SpanKind.CLIENT
5876
6045
  });
5877
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
5878
- return SpanUtils.createAndExecuteSpan(self.mode, () => new OriginalConnection(...args), {
5879
- name: `mysql2.connection.create`,
5880
- kind: __opentelemetry_api.SpanKind.CLIENT,
5881
- submodule: "connectEvent",
5882
- packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5883
- packageName: "mysql2",
5884
- instrumentationName: self.INSTRUMENTATION_NAME,
5885
- inputValue,
5886
- isPreAppStart: false
5887
- }, (spanInfo) => {
5888
- class MockConnection extends OriginalConnection {
5889
- constructor(...mockConnectionArgs) {
5890
- const clonedArgs = JSON.parse(JSON.stringify(mockConnectionArgs));
5891
- if (clonedArgs[0] && clonedArgs[0].config) {
5892
- clonedArgs[0].config.host = "127.0.0.1";
5893
- clonedArgs[0].config.port = 127;
5894
- } else if (clonedArgs[0]) {
5895
- clonedArgs[0].host = "127.0.0.1";
5896
- clonedArgs[0].port = 127;
6046
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
6047
+ noOpRequestHandler: () => {
6048
+ return new TdMysql2ConnectionMock(self, "connection");
6049
+ },
6050
+ isServerRequest: false,
6051
+ replayModeHandler: () => {
6052
+ return SpanUtils.createAndExecuteSpan(self.mode, () => new OriginalConnection(...args), {
6053
+ name: `mysql2.connection.create`,
6054
+ kind: __opentelemetry_api.SpanKind.CLIENT,
6055
+ submodule: "connectEvent",
6056
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
6057
+ packageName: "mysql2",
6058
+ instrumentationName: self.INSTRUMENTATION_NAME,
6059
+ inputValue,
6060
+ isPreAppStart: false
6061
+ }, (spanInfo) => {
6062
+ class MockConnection extends OriginalConnection {
6063
+ constructor(...mockConnectionArgs) {
6064
+ const clonedArgs = JSON.parse(JSON.stringify(mockConnectionArgs));
6065
+ if (clonedArgs[0] && clonedArgs[0].config) {
6066
+ clonedArgs[0].config.host = "127.0.0.1";
6067
+ clonedArgs[0].config.port = 127;
6068
+ } else if (clonedArgs[0]) {
6069
+ clonedArgs[0].host = "127.0.0.1";
6070
+ clonedArgs[0].port = 127;
6071
+ }
6072
+ super(...clonedArgs);
6073
+ this._isConnectOrErrorEmitted = false;
6074
+ this._connectEventMock = new TdMysql2ConnectionEventMock(spanInfo);
5897
6075
  }
5898
- super(...clonedArgs);
5899
- this._isConnectOrErrorEmitted = false;
5900
- this._connectEventMock = new TdMysql2ConnectionEventMock(spanInfo);
5901
- }
5902
- on(event, listener) {
5903
- if (!this._connectEventMock) return super.on(event, listener);
5904
- if (event === "connect" && !this._isConnectOrErrorEmitted) {
5905
- this._connectEventMock.getReplayedConnectionEvent(inputValue).then(({ output }) => {
5906
- if (output !== void 0) process.nextTick(() => {
5907
- listener.call(this, output);
5908
- this._isConnectOrErrorEmitted = true;
6076
+ on(event, listener) {
6077
+ if (!this._connectEventMock) return super.on(event, listener);
6078
+ if (event === "connect" && !this._isConnectOrErrorEmitted) {
6079
+ this._connectEventMock.getReplayedConnectionEvent(inputValue).then(({ output }) => {
6080
+ if (output !== void 0) process.nextTick(() => {
6081
+ listener.call(this, output);
6082
+ this._isConnectOrErrorEmitted = true;
6083
+ });
6084
+ }).catch((err) => {
6085
+ logger.error(`[Mysql2Instrumentation] Error replaying connection event:`, err);
5909
6086
  });
5910
- }).catch((err) => {
5911
- logger.error(`[Mysql2Instrumentation] Error replaying connection event:`, err);
5912
- });
5913
- return this;
6087
+ return this;
6088
+ }
6089
+ if (event === "error" && !this._isConnectOrErrorEmitted) return this;
6090
+ return super.on(event, listener);
5914
6091
  }
5915
- if (event === "error" && !this._isConnectOrErrorEmitted) return this;
5916
- return super.on(event, listener);
5917
6092
  }
5918
- }
5919
- const mockConnection = new MockConnection(...args);
5920
- mockConnection.addListener("error", (_err) => {});
5921
- SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: {
5922
- connected: true,
5923
- mock: true
5924
- } });
5925
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.OK });
5926
- return mockConnection;
5927
- });
5928
- } });
6093
+ const mockConnection = new MockConnection(...args);
6094
+ mockConnection.addListener("error", (_err) => {});
6095
+ return mockConnection;
6096
+ });
6097
+ }
6098
+ });
5929
6099
  return new OriginalConnection(...args);
5930
6100
  }
5931
6101
  const staticProps = Object.getOwnPropertyNames(OriginalConnection).filter((key) => ![
@@ -6123,19 +6293,28 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
6123
6293
  }
6124
6294
  if (self.mode === TuskDriftMode.REPLAY) {
6125
6295
  const stackTrace = captureStackTrace(["JsonwebtokenInstrumentation"]);
6126
- return handleReplayMode({ replayModeHandler: () => {
6127
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalVerify.apply(this, args), {
6128
- name: "jsonwebtoken.verify",
6129
- kind: __opentelemetry_api.SpanKind.CLIENT,
6130
- submodule: "verify",
6131
- packageName: "jsonwebtoken",
6132
- instrumentationName: self.INSTRUMENTATION_NAME,
6133
- inputValue,
6134
- isPreAppStart: false
6135
- }, (spanInfo) => {
6136
- return self.handleReplayVerify(verifyConfig, inputValue, spanInfo, stackTrace);
6137
- });
6138
- } });
6296
+ return handleReplayMode({
6297
+ noOpRequestHandler: () => {
6298
+ if (!!verifyConfig.callback) {
6299
+ process.nextTick(() => verifyConfig.callback(null, void 0));
6300
+ return;
6301
+ } else return;
6302
+ },
6303
+ isServerRequest: false,
6304
+ replayModeHandler: () => {
6305
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalVerify.apply(this, args), {
6306
+ name: "jsonwebtoken.verify",
6307
+ kind: __opentelemetry_api.SpanKind.CLIENT,
6308
+ submodule: "verify",
6309
+ packageName: "jsonwebtoken",
6310
+ instrumentationName: self.INSTRUMENTATION_NAME,
6311
+ inputValue,
6312
+ isPreAppStart: false
6313
+ }, (spanInfo) => {
6314
+ return self.handleReplayVerify(verifyConfig, inputValue, spanInfo, stackTrace);
6315
+ });
6316
+ }
6317
+ });
6139
6318
  } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
6140
6319
  originalFunctionCall: () => originalVerify.apply(this, args),
6141
6320
  recordModeHandler: ({ isPreAppStart }) => {
@@ -6178,19 +6357,28 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
6178
6357
  };
6179
6358
  if (self.mode === TuskDriftMode.REPLAY) {
6180
6359
  const stackTrace = captureStackTrace(["JsonwebtokenInstrumentation"]);
6181
- return handleReplayMode({ replayModeHandler: () => {
6182
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalSign.apply(this, args), {
6183
- name: "jsonwebtoken.sign",
6184
- kind: __opentelemetry_api.SpanKind.CLIENT,
6185
- submodule: "sign",
6186
- packageName: "jsonwebtoken",
6187
- instrumentationName: self.INSTRUMENTATION_NAME,
6188
- inputValue,
6189
- isPreAppStart: false
6190
- }, (spanInfo) => {
6191
- return self.handleReplaySign(signConfig, inputValue, spanInfo, stackTrace);
6192
- });
6193
- } });
6360
+ return handleReplayMode({
6361
+ noOpRequestHandler: () => {
6362
+ if (!!signConfig.callback) {
6363
+ process.nextTick(() => signConfig.callback(null, void 0));
6364
+ return;
6365
+ } else return;
6366
+ },
6367
+ isServerRequest: false,
6368
+ replayModeHandler: () => {
6369
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalSign.apply(this, args), {
6370
+ name: "jsonwebtoken.sign",
6371
+ kind: __opentelemetry_api.SpanKind.CLIENT,
6372
+ submodule: "sign",
6373
+ packageName: "jsonwebtoken",
6374
+ instrumentationName: self.INSTRUMENTATION_NAME,
6375
+ inputValue,
6376
+ isPreAppStart: false
6377
+ }, (spanInfo) => {
6378
+ return self.handleReplaySign(signConfig, inputValue, spanInfo, stackTrace);
6379
+ });
6380
+ }
6381
+ });
6194
6382
  } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
6195
6383
  originalFunctionCall: () => originalSign.apply(this, args),
6196
6384
  recordModeHandler: ({ isPreAppStart }) => {
@@ -6378,11 +6566,7 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
6378
6566
  const hasCallback = !!verifyConfig.callback;
6379
6567
  if (!mockData) {
6380
6568
  logger.warn(`[JsonwebtokenInstrumentation] No mock data found for JWT verify: ${verifyConfig.token}`);
6381
- const error = /* @__PURE__ */ new Error("No mock data found");
6382
- if (hasCallback) {
6383
- process.nextTick(() => verifyConfig.callback(error));
6384
- return;
6385
- } else throw error;
6569
+ throw new Error(`[JsonwebtokenInstrumentation] No matching mock found for JWT verify: ${verifyConfig.token}`);
6386
6570
  }
6387
6571
  if (mockData.result && mockData.result.error) {
6388
6572
  let error = mockData.result.error;
@@ -6425,11 +6609,7 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
6425
6609
  const hasCallback = !!signConfig.callback;
6426
6610
  if (!mockData) {
6427
6611
  logger.warn(`[JsonwebtokenInstrumentation] No mock data found for JWT sign`);
6428
- const error = /* @__PURE__ */ new Error("No mock data found");
6429
- if (hasCallback) {
6430
- process.nextTick(() => signConfig.callback(error));
6431
- return;
6432
- } else throw error;
6612
+ throw new Error(`[JsonwebtokenInstrumentation] No matching mock found for JWT sign`);
6433
6613
  }
6434
6614
  if (mockData.result && mockData.result.error) {
6435
6615
  let error = mockData.result.error;
@@ -6846,20 +7026,30 @@ var FetchInstrumentation = class extends TdInstrumentationBase {
6846
7026
  headers: normalizedHeaders,
6847
7027
  body: encodedBody
6848
7028
  };
6849
- if (this.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
6850
- return SpanUtils.createAndExecuteSpan(this.mode, () => this.originalFetch(input, init), {
6851
- name: url,
6852
- kind: __opentelemetry_api.SpanKind.CLIENT,
6853
- packageName: "fetch",
6854
- packageType: __use_tusk_drift_schemas_core_span.PackageType.HTTP,
6855
- instrumentationName: this.INSTRUMENTATION_NAME,
6856
- submodule: inputValue.method,
6857
- inputValue,
6858
- isPreAppStart: false
6859
- }, (spanInfo) => {
6860
- return this._handleReplayFetch(inputValue, spanInfo, stackTrace);
6861
- });
6862
- } });
7029
+ if (this.mode === TuskDriftMode.REPLAY) return handleReplayMode({
7030
+ noOpRequestHandler: () => {
7031
+ const mockResponse = new Response(null, {
7032
+ status: 200,
7033
+ statusText: "OK"
7034
+ });
7035
+ return Promise.resolve(mockResponse);
7036
+ },
7037
+ isServerRequest: false,
7038
+ replayModeHandler: () => {
7039
+ return SpanUtils.createAndExecuteSpan(this.mode, () => this.originalFetch(input, init), {
7040
+ name: url,
7041
+ kind: __opentelemetry_api.SpanKind.CLIENT,
7042
+ packageName: "fetch",
7043
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.HTTP,
7044
+ instrumentationName: this.INSTRUMENTATION_NAME,
7045
+ submodule: inputValue.method,
7046
+ inputValue,
7047
+ isPreAppStart: false
7048
+ }, (spanInfo) => {
7049
+ return this._handleReplayFetch(inputValue, spanInfo, stackTrace);
7050
+ });
7051
+ }
7052
+ });
6863
7053
  else if (this.mode === TuskDriftMode.RECORD) return handleRecordMode({
6864
7054
  originalFunctionCall: () => this.originalFetch(input, init),
6865
7055
  recordModeHandler: ({ isPreAppStart }) => this._handleRecordFetch(input, inputValue, isPreAppStart, init),
@@ -6961,7 +7151,10 @@ var FetchInstrumentation = class extends TdInstrumentationBase {
6961
7151
  ...inputValue.headers && { headers: { matchImportance: 0 } }
6962
7152
  }
6963
7153
  });
6964
- if (!mockData) throw new Error(`No matching mock found for fetch request with input value: ${JSON.stringify(inputValue)}`);
7154
+ if (!mockData) {
7155
+ logger.warn(`[FetchInstrumentation] No mock data found for fetch request with input value: ${JSON.stringify(inputValue)}`);
7156
+ throw new Error(`[FetchInstrumentation] No matching mock found for fetch request`);
7157
+ }
6965
7158
  const { result } = mockData;
6966
7159
  const responseBody = this._constructFetchResponseBody(result);
6967
7160
  const mockResponse = new Response(responseBody, {
@@ -7227,20 +7420,24 @@ var IORedisInstrumentation = class extends TdInstrumentationBase {
7227
7420
  };
7228
7421
  if (self.mode === TuskDriftMode.REPLAY) {
7229
7422
  const stackTrace = captureStackTrace(["IORedisInstrumentation"]);
7230
- return handleReplayMode({ replayModeHandler: () => {
7231
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalSendCommand.apply(this, arguments), {
7232
- name: `ioredis.${commandName}`,
7233
- kind: __opentelemetry_api.SpanKind.CLIENT,
7234
- submodule: commandName,
7235
- packageType: __use_tusk_drift_schemas_core_span.PackageType.REDIS,
7236
- packageName: "ioredis",
7237
- instrumentationName: self.INSTRUMENTATION_NAME,
7238
- inputValue,
7239
- isPreAppStart: false
7240
- }, (spanInfo) => {
7241
- return self._handleReplaySendCommand(spanInfo, cmd, inputValue, commandName, stackTrace);
7242
- });
7243
- } });
7423
+ return handleReplayMode({
7424
+ noOpRequestHandler: () => {},
7425
+ isServerRequest: false,
7426
+ replayModeHandler: () => {
7427
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalSendCommand.apply(this, arguments), {
7428
+ name: `ioredis.${commandName}`,
7429
+ kind: __opentelemetry_api.SpanKind.CLIENT,
7430
+ submodule: commandName,
7431
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.REDIS,
7432
+ packageName: "ioredis",
7433
+ instrumentationName: self.INSTRUMENTATION_NAME,
7434
+ inputValue,
7435
+ isPreAppStart: false
7436
+ }, (spanInfo) => {
7437
+ return self._handleReplaySendCommand(spanInfo, cmd, inputValue, stackTrace);
7438
+ });
7439
+ }
7440
+ });
7244
7441
  } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
7245
7442
  originalFunctionCall: () => originalSendCommand.apply(this, arguments),
7246
7443
  recordModeHandler: ({ isPreAppStart }) => {
@@ -7271,20 +7468,29 @@ var IORedisInstrumentation = class extends TdInstrumentationBase {
7271
7468
  host: this.options?.host,
7272
7469
  port: this.options?.port
7273
7470
  };
7274
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
7275
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, arguments), {
7276
- name: "ioredis.connect",
7277
- kind: __opentelemetry_api.SpanKind.CLIENT,
7278
- submodule: "connect",
7279
- packageType: __use_tusk_drift_schemas_core_span.PackageType.REDIS,
7280
- packageName: "ioredis",
7281
- instrumentationName: self.INSTRUMENTATION_NAME,
7282
- inputValue,
7283
- isPreAppStart: false
7284
- }, (spanInfo) => {
7285
- return self._handleReplayConnect(spanInfo, this);
7286
- });
7287
- } });
7471
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
7472
+ noOpRequestHandler: () => {
7473
+ process.nextTick(() => {
7474
+ this.emit("ready");
7475
+ });
7476
+ return Promise.resolve();
7477
+ },
7478
+ isServerRequest: false,
7479
+ replayModeHandler: () => {
7480
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, arguments), {
7481
+ name: "ioredis.connect",
7482
+ kind: __opentelemetry_api.SpanKind.CLIENT,
7483
+ submodule: "connect",
7484
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.REDIS,
7485
+ packageName: "ioredis",
7486
+ instrumentationName: self.INSTRUMENTATION_NAME,
7487
+ inputValue,
7488
+ isPreAppStart: false
7489
+ }, (spanInfo) => {
7490
+ return self._handleReplayConnect(this);
7491
+ });
7492
+ }
7493
+ });
7288
7494
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
7289
7495
  originalFunctionCall: () => originalConnect.apply(this, arguments),
7290
7496
  recordModeHandler: ({ isPreAppStart }) => {
@@ -7341,20 +7547,26 @@ var IORedisInstrumentation = class extends TdInstrumentationBase {
7341
7547
  command: q.name,
7342
7548
  args: q.args || []
7343
7549
  })) };
7344
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
7345
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalExec.apply(this, args), {
7346
- name: "ioredis.pipeline.exec",
7347
- kind: __opentelemetry_api.SpanKind.CLIENT,
7348
- submodule: "pipeline-exec",
7349
- packageType: __use_tusk_drift_schemas_core_span.PackageType.REDIS,
7350
- packageName: "ioredis",
7351
- instrumentationName: self.INSTRUMENTATION_NAME,
7352
- inputValue,
7353
- isPreAppStart: false
7354
- }, (spanInfo) => {
7355
- return self._handleReplayPipelineExec(spanInfo, inputValue, args);
7356
- });
7357
- } });
7550
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
7551
+ noOpRequestHandler: () => {
7552
+ return [];
7553
+ },
7554
+ isServerRequest: false,
7555
+ replayModeHandler: () => {
7556
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalExec.apply(this, args), {
7557
+ name: "ioredis.pipeline.exec",
7558
+ kind: __opentelemetry_api.SpanKind.CLIENT,
7559
+ submodule: "pipeline-exec",
7560
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.REDIS,
7561
+ packageName: "ioredis",
7562
+ instrumentationName: self.INSTRUMENTATION_NAME,
7563
+ inputValue,
7564
+ isPreAppStart: false
7565
+ }, (spanInfo) => {
7566
+ return self._handleReplayPipelineExec(spanInfo, inputValue, args);
7567
+ });
7568
+ }
7569
+ });
7358
7570
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
7359
7571
  originalFunctionCall: () => originalExec.apply(this, args),
7360
7572
  recordModeHandler: ({ isPreAppStart }) => {
@@ -7403,7 +7615,7 @@ var IORedisInstrumentation = class extends TdInstrumentationBase {
7403
7615
  });
7404
7616
  return promise;
7405
7617
  }
7406
- async _handleReplaySendCommand(spanInfo, cmd, inputValue, commandName, stackTrace) {
7618
+ async _handleReplaySendCommand(spanInfo, cmd, inputValue, stackTrace) {
7407
7619
  logger.debug(`[IORedisInstrumentation] Replaying IORedis command ${cmd.name}`);
7408
7620
  const mockData = await findMockResponseAsync({
7409
7621
  mockRequestData: {
@@ -7421,13 +7633,10 @@ var IORedisInstrumentation = class extends TdInstrumentationBase {
7421
7633
  });
7422
7634
  if (!mockData) {
7423
7635
  logger.warn(`[IORedisInstrumentation] No mock data found for command: ${cmd.name}`);
7424
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.OK });
7425
- return;
7636
+ throw new Error(`[IORedisInstrumentation] No matching mock found for command: ${cmd.name}`);
7426
7637
  }
7427
7638
  logger.debug(`[IORedisInstrumentation] Found mock data for command ${cmd.name}: ${JSON.stringify(mockData)}`);
7428
7639
  const result = this._deserializeOutput(mockData.result);
7429
- SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: mockData.result });
7430
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.OK });
7431
7640
  if (cmd.callback && typeof cmd.callback === "function") process.nextTick(() => {
7432
7641
  cmd.callback(null, result);
7433
7642
  });
@@ -7465,10 +7674,8 @@ var IORedisInstrumentation = class extends TdInstrumentationBase {
7465
7674
  }
7466
7675
  return promise;
7467
7676
  }
7468
- async _handleReplayConnect(spanInfo, thisContext) {
7677
+ async _handleReplayConnect(thisContext) {
7469
7678
  logger.debug(`[IORedisInstrumentation] Replaying IORedis connect`);
7470
- SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: { connected: true } });
7471
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.OK });
7472
7679
  process.nextTick(() => {
7473
7680
  thisContext.emit("ready");
7474
7681
  });
@@ -7517,8 +7724,7 @@ var IORedisInstrumentation = class extends TdInstrumentationBase {
7517
7724
  });
7518
7725
  if (!mockData) {
7519
7726
  logger.warn(`[IORedisInstrumentation] No mock data found for pipeline exec`);
7520
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.OK });
7521
- return [];
7727
+ throw new Error(`[IORedisInstrumentation] No matching mock found for pipeline exec`);
7522
7728
  }
7523
7729
  logger.debug(`[IORedisInstrumentation] Found mock data for pipeline exec: ${JSON.stringify(mockData)}`);
7524
7730
  const result = this._deserializePipelineOutput(mockData.result);
@@ -7526,8 +7732,6 @@ var IORedisInstrumentation = class extends TdInstrumentationBase {
7526
7732
  if (typeof callback === "function") process.nextTick(() => {
7527
7733
  callback(null, result);
7528
7734
  });
7529
- SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: mockData.result });
7530
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.OK });
7531
7735
  return Promise.resolve(result);
7532
7736
  }
7533
7737
  _sanitizeArgs(args) {
@@ -7868,20 +8072,26 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
7868
8072
  };
7869
8073
  if (self.mode === TuskDriftMode.REPLAY) {
7870
8074
  const stackTrace = captureStackTrace(["GrpcInstrumentation"]);
7871
- return handleReplayMode({ replayModeHandler: () => {
7872
- return SpanUtils.createAndExecuteSpan(self.mode, () => original.apply(this, args), {
7873
- name: "grpc.client.unary",
7874
- kind: __opentelemetry_api.SpanKind.CLIENT,
7875
- submodule: "client",
7876
- packageType: __use_tusk_drift_schemas_core_span.PackageType.GRPC,
7877
- packageName: GRPC_MODULE_NAME,
7878
- instrumentationName: self.INSTRUMENTATION_NAME,
7879
- inputValue,
7880
- isPreAppStart: false
7881
- }, (spanInfo) => {
7882
- return self._handleReplayUnaryRequest(spanInfo, inputValue, callback, MetadataConstructor, stackTrace);
7883
- });
7884
- } });
8075
+ return handleReplayMode({
8076
+ noOpRequestHandler: () => {
8077
+ callback(null, void 0);
8078
+ },
8079
+ isServerRequest: false,
8080
+ replayModeHandler: () => {
8081
+ return SpanUtils.createAndExecuteSpan(self.mode, () => original.apply(this, args), {
8082
+ name: "grpc.client.unary",
8083
+ kind: __opentelemetry_api.SpanKind.CLIENT,
8084
+ submodule: "client",
8085
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.GRPC,
8086
+ packageName: GRPC_MODULE_NAME,
8087
+ instrumentationName: self.INSTRUMENTATION_NAME,
8088
+ inputValue,
8089
+ isPreAppStart: false
8090
+ }, (spanInfo) => {
8091
+ return self._handleReplayUnaryRequest(spanInfo, inputValue, callback, MetadataConstructor, stackTrace);
8092
+ });
8093
+ }
8094
+ });
7885
8095
  } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
7886
8096
  originalFunctionCall: () => original.apply(this, args),
7887
8097
  recordModeHandler: ({ isPreAppStart }) => {
@@ -7947,20 +8157,35 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
7947
8157
  jsonableStringMap
7948
8158
  }
7949
8159
  };
7950
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
7951
- return SpanUtils.createAndExecuteSpan(self.mode, () => original.apply(this, args), {
7952
- name: "grpc.client.server_stream",
7953
- kind: __opentelemetry_api.SpanKind.CLIENT,
7954
- submodule: "client",
7955
- packageType: __use_tusk_drift_schemas_core_span.PackageType.GRPC,
7956
- packageName: GRPC_MODULE_NAME,
7957
- instrumentationName: self.INSTRUMENTATION_NAME,
7958
- inputValue,
7959
- isPreAppStart: false
7960
- }, (spanInfo) => {
7961
- return self._handleReplayServerStreamRequest(spanInfo, inputValue, MetadataConstructor);
7962
- });
7963
- } });
8160
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
8161
+ noOpRequestHandler: () => {
8162
+ const stream$1 = new stream.Readable({
8163
+ objectMode: true,
8164
+ read() {}
8165
+ });
8166
+ Object.assign(stream$1, {
8167
+ cancel() {},
8168
+ getPeer: () => "0.0.0.0:0000",
8169
+ call: void 0
8170
+ });
8171
+ return stream$1;
8172
+ },
8173
+ isServerRequest: false,
8174
+ replayModeHandler: () => {
8175
+ return SpanUtils.createAndExecuteSpan(self.mode, () => original.apply(this, args), {
8176
+ name: "grpc.client.server_stream",
8177
+ kind: __opentelemetry_api.SpanKind.CLIENT,
8178
+ submodule: "client",
8179
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.GRPC,
8180
+ packageName: GRPC_MODULE_NAME,
8181
+ instrumentationName: self.INSTRUMENTATION_NAME,
8182
+ inputValue,
8183
+ isPreAppStart: false
8184
+ }, (spanInfo) => {
8185
+ return self._handleReplayServerStreamRequest(spanInfo, inputValue, MetadataConstructor);
8186
+ });
8187
+ }
8188
+ });
7964
8189
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
7965
8190
  originalFunctionCall: () => original.apply(this, args),
7966
8191
  recordModeHandler: ({ isPreAppStart }) => {
@@ -8147,9 +8372,7 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
8147
8372
  }).then((mockData) => {
8148
8373
  if (!mockData) {
8149
8374
  logger.warn(`[GrpcInstrumentation] No mock data found for gRPC request: ${inputValue.service}/${inputValue.method}`, inputValue);
8150
- callback(/* @__PURE__ */ new Error("No mock data found"));
8151
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.ERROR });
8152
- return;
8375
+ throw new Error(`[GrpcInstrumentation] No matching mock found for gRPC unary request`);
8153
8376
  }
8154
8377
  const mockResult = mockData.result;
8155
8378
  let status;
@@ -8182,12 +8405,9 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
8182
8405
  if (mockResult.metadata) emitter.emit("metadata", deserializeGrpcMetadata(MetadataConstructor, mockResult.metadata));
8183
8406
  emitter.emit("status", status);
8184
8407
  });
8185
- SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: mockResult });
8186
- SpanUtils.endSpan(spanInfo.span, { code: mockResult.error ? __opentelemetry_api.SpanStatusCode.ERROR : __opentelemetry_api.SpanStatusCode.OK });
8187
8408
  }).catch((error) => {
8188
8409
  logger.error(`[GrpcInstrumentation] Error fetching mock data:`, error);
8189
8410
  callback(error);
8190
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.ERROR });
8191
8411
  });
8192
8412
  return emitter;
8193
8413
  }
@@ -8301,21 +8521,7 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
8301
8521
  }).then((mockData) => {
8302
8522
  if (!mockData) {
8303
8523
  logger.warn(`[GrpcInstrumentation] No mock data found for gRPC server stream request: ${inputValue.service}/${inputValue.method}`, inputValue);
8304
- const error = /* @__PURE__ */ new Error("No mock data found");
8305
- process.nextTick(() => {
8306
- stream$1.emit("error", error);
8307
- stream$1.emit("status", {
8308
- code: 2,
8309
- details: "No mock data found",
8310
- metadata: new MetadataConstructor()
8311
- });
8312
- stream$1.push(null);
8313
- });
8314
- SpanUtils.endSpan(spanInfo.span, {
8315
- code: __opentelemetry_api.SpanStatusCode.ERROR,
8316
- message: "No mock data found"
8317
- });
8318
- return;
8524
+ throw new Error(`[GrpcInstrumentation] No matching mock found for gRPC server stream request`);
8319
8525
  }
8320
8526
  const mockResult = mockData.result;
8321
8527
  process.nextTick(() => {
@@ -8335,11 +8541,6 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
8335
8541
  stream$1.emit("error", errorObj);
8336
8542
  stream$1.emit("status", status);
8337
8543
  stream$1.push(null);
8338
- SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: mockResult });
8339
- SpanUtils.endSpan(spanInfo.span, {
8340
- code: __opentelemetry_api.SpanStatusCode.ERROR,
8341
- message: error.message
8342
- });
8343
8544
  } else {
8344
8545
  const { body, status: successStatus } = mockResult;
8345
8546
  const status = {
@@ -8356,8 +8557,6 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
8356
8557
  });
8357
8558
  stream$1.push(null);
8358
8559
  stream$1.emit("status", status);
8359
- SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: mockResult });
8360
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.OK });
8361
8560
  }
8362
8561
  });
8363
8562
  }).catch((error) => {
@@ -8371,7 +8570,6 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
8371
8570
  });
8372
8571
  stream$1.push(null);
8373
8572
  });
8374
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.ERROR });
8375
8573
  });
8376
8574
  return stream$1;
8377
8575
  }
@@ -8684,21 +8882,31 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
8684
8882
  operation: "document.get",
8685
8883
  path: this.path
8686
8884
  };
8687
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
8688
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalGet.call(this), {
8689
- name: "firestore.document.get",
8690
- kind: __opentelemetry_api.SpanKind.CLIENT,
8691
- submodule: "document",
8692
- packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
8693
- packageName: PACKAGE_NAME,
8694
- instrumentationName: self.INSTRUMENTATION_NAME,
8695
- inputValue,
8696
- isPreAppStart: false,
8697
- stopRecordingChildSpans: true
8698
- }, (spanInfo) => {
8699
- return self._handleReplayDocumentGet(spanInfo, inputValue);
8700
- });
8701
- } });
8885
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
8886
+ noOpRequestHandler: () => {
8887
+ return new TdFirestoreDocumentMock({
8888
+ exists: false,
8889
+ id: "",
8890
+ path: ""
8891
+ });
8892
+ },
8893
+ isServerRequest: false,
8894
+ replayModeHandler: () => {
8895
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalGet.call(this), {
8896
+ name: "firestore.document.get",
8897
+ kind: __opentelemetry_api.SpanKind.CLIENT,
8898
+ submodule: "document",
8899
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
8900
+ packageName: PACKAGE_NAME,
8901
+ instrumentationName: self.INSTRUMENTATION_NAME,
8902
+ inputValue,
8903
+ isPreAppStart: false,
8904
+ stopRecordingChildSpans: true
8905
+ }, (spanInfo) => {
8906
+ return self._handleReplayDocumentGet(spanInfo, inputValue);
8907
+ });
8908
+ }
8909
+ });
8702
8910
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
8703
8911
  originalFunctionCall: () => originalGet.call(this),
8704
8912
  recordModeHandler: ({ isPreAppStart }) => {
@@ -8767,7 +8975,7 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
8767
8975
  });
8768
8976
  if (!mockData) {
8769
8977
  logger.warn(`[FirestoreInstrumentation] No mock data found for document.get: ${inputValue.path}`);
8770
- return Promise.reject(/* @__PURE__ */ new Error("No mock data found"));
8978
+ throw new Error(`[FirestoreInstrumentation] No matching mock found for document.get`);
8771
8979
  }
8772
8980
  const documentResult = mockData.result;
8773
8981
  return new TdFirestoreDocumentMock(documentResult);
@@ -8781,21 +8989,32 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
8781
8989
  path: this.path,
8782
8990
  data
8783
8991
  };
8784
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
8785
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalCreate.call(this, data), {
8786
- name: "firestore.document.create",
8787
- kind: __opentelemetry_api.SpanKind.CLIENT,
8788
- submodule: "document",
8789
- packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
8790
- packageName: PACKAGE_NAME,
8791
- instrumentationName: self.INSTRUMENTATION_NAME,
8792
- inputValue,
8793
- isPreAppStart: false,
8794
- stopRecordingChildSpans: true
8795
- }, (spanInfo) => {
8796
- return self._handleReplayDocumentWrite(spanInfo, inputValue);
8797
- });
8798
- } });
8992
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
8993
+ noOpRequestHandler: () => {
8994
+ const now = Date.now();
8995
+ const emptyWriteResult = { writeTime: {
8996
+ seconds: Math.floor(now / 1e3),
8997
+ nanoseconds: now % 1e3 * 1e6
8998
+ } };
8999
+ return new TdFirestoreWriteResultMock(emptyWriteResult);
9000
+ },
9001
+ isServerRequest: false,
9002
+ replayModeHandler: () => {
9003
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalCreate.call(this, data), {
9004
+ name: "firestore.document.create",
9005
+ kind: __opentelemetry_api.SpanKind.CLIENT,
9006
+ submodule: "document",
9007
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
9008
+ packageName: PACKAGE_NAME,
9009
+ instrumentationName: self.INSTRUMENTATION_NAME,
9010
+ inputValue,
9011
+ isPreAppStart: false,
9012
+ stopRecordingChildSpans: true
9013
+ }, (spanInfo) => {
9014
+ return self._handleReplayDocumentWrite(spanInfo, inputValue);
9015
+ });
9016
+ }
9017
+ });
8799
9018
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
8800
9019
  originalFunctionCall: () => originalCreate.call(this, data),
8801
9020
  recordModeHandler: ({ isPreAppStart }) => {
@@ -8829,21 +9048,32 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
8829
9048
  data,
8830
9049
  options
8831
9050
  };
8832
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
8833
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalSet.call(this, data, options), {
8834
- name: "firestore.document.set",
8835
- kind: __opentelemetry_api.SpanKind.CLIENT,
8836
- submodule: "document",
8837
- packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
8838
- packageName: PACKAGE_NAME,
8839
- instrumentationName: self.INSTRUMENTATION_NAME,
8840
- inputValue,
8841
- isPreAppStart: false,
8842
- stopRecordingChildSpans: true
8843
- }, (spanInfo) => {
8844
- return self._handleReplayDocumentWrite(spanInfo, inputValue);
8845
- });
8846
- } });
9051
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
9052
+ noOpRequestHandler: () => {
9053
+ const now = Date.now();
9054
+ const emptyWriteResult = { writeTime: {
9055
+ seconds: Math.floor(now / 1e3),
9056
+ nanoseconds: now % 1e3 * 1e6
9057
+ } };
9058
+ return new TdFirestoreWriteResultMock(emptyWriteResult);
9059
+ },
9060
+ isServerRequest: false,
9061
+ replayModeHandler: () => {
9062
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalSet.call(this, data, options), {
9063
+ name: "firestore.document.set",
9064
+ kind: __opentelemetry_api.SpanKind.CLIENT,
9065
+ submodule: "document",
9066
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
9067
+ packageName: PACKAGE_NAME,
9068
+ instrumentationName: self.INSTRUMENTATION_NAME,
9069
+ inputValue,
9070
+ isPreAppStart: false,
9071
+ stopRecordingChildSpans: true
9072
+ }, (spanInfo) => {
9073
+ return self._handleReplayDocumentWrite(spanInfo, inputValue);
9074
+ });
9075
+ }
9076
+ });
8847
9077
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
8848
9078
  originalFunctionCall: () => originalSet.call(this, data, options),
8849
9079
  recordModeHandler: ({ isPreAppStart }) => {
@@ -8876,21 +9106,32 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
8876
9106
  path: this.path,
8877
9107
  data: args.length === 1 ? args[0] : args
8878
9108
  };
8879
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
8880
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalUpdate.apply(this, args), {
8881
- name: "firestore.document.update",
8882
- kind: __opentelemetry_api.SpanKind.CLIENT,
8883
- submodule: "document",
8884
- packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
8885
- packageName: PACKAGE_NAME,
8886
- instrumentationName: self.INSTRUMENTATION_NAME,
8887
- inputValue,
8888
- isPreAppStart: false,
8889
- stopRecordingChildSpans: true
8890
- }, (spanInfo) => {
8891
- return self._handleReplayDocumentWrite(spanInfo, inputValue);
8892
- });
8893
- } });
9109
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
9110
+ noOpRequestHandler: () => {
9111
+ const now = Date.now();
9112
+ const emptyWriteResult = { writeTime: {
9113
+ seconds: Math.floor(now / 1e3),
9114
+ nanoseconds: now % 1e3 * 1e6
9115
+ } };
9116
+ return new TdFirestoreWriteResultMock(emptyWriteResult);
9117
+ },
9118
+ isServerRequest: false,
9119
+ replayModeHandler: () => {
9120
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalUpdate.apply(this, args), {
9121
+ name: "firestore.document.update",
9122
+ kind: __opentelemetry_api.SpanKind.CLIENT,
9123
+ submodule: "document",
9124
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
9125
+ packageName: PACKAGE_NAME,
9126
+ instrumentationName: self.INSTRUMENTATION_NAME,
9127
+ inputValue,
9128
+ isPreAppStart: false,
9129
+ stopRecordingChildSpans: true
9130
+ }, (spanInfo) => {
9131
+ return self._handleReplayDocumentWrite(spanInfo, inputValue);
9132
+ });
9133
+ }
9134
+ });
8894
9135
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
8895
9136
  originalFunctionCall: () => originalUpdate.apply(this, args),
8896
9137
  recordModeHandler: ({ isPreAppStart }) => {
@@ -8923,21 +9164,32 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
8923
9164
  path: this.path,
8924
9165
  options: precondition
8925
9166
  };
8926
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
8927
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalDelete.call(this, precondition), {
8928
- name: "firestore.document.delete",
8929
- kind: __opentelemetry_api.SpanKind.CLIENT,
8930
- submodule: "document",
8931
- packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
8932
- packageName: PACKAGE_NAME,
8933
- instrumentationName: self.INSTRUMENTATION_NAME,
8934
- inputValue,
8935
- isPreAppStart: false,
8936
- stopRecordingChildSpans: true
8937
- }, (spanInfo) => {
8938
- return self._handleReplayDocumentWrite(spanInfo, inputValue);
8939
- });
8940
- } });
9167
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
9168
+ noOpRequestHandler: () => {
9169
+ const now = Date.now();
9170
+ const emptyWriteResult = { writeTime: {
9171
+ seconds: Math.floor(now / 1e3),
9172
+ nanoseconds: now % 1e3 * 1e6
9173
+ } };
9174
+ return new TdFirestoreWriteResultMock(emptyWriteResult);
9175
+ },
9176
+ isServerRequest: false,
9177
+ replayModeHandler: () => {
9178
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalDelete.call(this, precondition), {
9179
+ name: "firestore.document.delete",
9180
+ kind: __opentelemetry_api.SpanKind.CLIENT,
9181
+ submodule: "document",
9182
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
9183
+ packageName: PACKAGE_NAME,
9184
+ instrumentationName: self.INSTRUMENTATION_NAME,
9185
+ inputValue,
9186
+ isPreAppStart: false,
9187
+ stopRecordingChildSpans: true
9188
+ }, (spanInfo) => {
9189
+ return self._handleReplayDocumentWrite(spanInfo, inputValue);
9190
+ });
9191
+ }
9192
+ });
8941
9193
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
8942
9194
  originalFunctionCall: () => originalDelete.call(this, precondition),
8943
9195
  recordModeHandler: ({ isPreAppStart }) => {
@@ -8992,7 +9244,7 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
8992
9244
  });
8993
9245
  if (!mockData) {
8994
9246
  logger.warn(`[FirestoreInstrumentation] No mock data found for ${inputValue.operation}: ${inputValue.path}`);
8995
- return Promise.reject(/* @__PURE__ */ new Error("No mock data found"));
9247
+ throw new Error(`[FirestoreInstrumentation] No matching mock found for ${inputValue.operation}`);
8996
9248
  }
8997
9249
  const writeResult = mockData.result;
8998
9250
  return new TdFirestoreWriteResultMock(writeResult);
@@ -9006,21 +9258,31 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
9006
9258
  path: this.path,
9007
9259
  data
9008
9260
  };
9009
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
9010
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalAdd.call(this, data), {
9011
- name: "firestore.collection.add",
9012
- kind: __opentelemetry_api.SpanKind.CLIENT,
9013
- submodule: "collection",
9014
- packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
9015
- packageName: PACKAGE_NAME,
9016
- instrumentationName: self.INSTRUMENTATION_NAME,
9017
- inputValue,
9018
- isPreAppStart: false,
9019
- stopRecordingChildSpans: true
9020
- }, (spanInfo) => {
9021
- return self._handleReplayCollectionAdd(spanInfo, inputValue, this);
9022
- });
9023
- } });
9261
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
9262
+ noOpRequestHandler: () => {
9263
+ if (!this.originalCollectionDocFn) {
9264
+ logger.error(`[FirestoreInstrumentation] Original doc function not available`);
9265
+ return Promise.reject(/* @__PURE__ */ new Error("Original doc function not available"));
9266
+ }
9267
+ return this.originalCollectionDocFn.call(this, "");
9268
+ },
9269
+ isServerRequest: false,
9270
+ replayModeHandler: () => {
9271
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalAdd.call(this, data), {
9272
+ name: "firestore.collection.add",
9273
+ kind: __opentelemetry_api.SpanKind.CLIENT,
9274
+ submodule: "collection",
9275
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
9276
+ packageName: PACKAGE_NAME,
9277
+ instrumentationName: self.INSTRUMENTATION_NAME,
9278
+ inputValue,
9279
+ isPreAppStart: false,
9280
+ stopRecordingChildSpans: true
9281
+ }, (spanInfo) => {
9282
+ return self._handleReplayCollectionAdd(spanInfo, inputValue, this);
9283
+ });
9284
+ }
9285
+ });
9024
9286
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
9025
9287
  originalFunctionCall: () => originalAdd.call(this, data),
9026
9288
  recordModeHandler: ({ isPreAppStart }) => {
@@ -9075,7 +9337,7 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
9075
9337
  });
9076
9338
  if (!mockData) {
9077
9339
  logger.warn(`[FirestoreInstrumentation] No mock data found for collection.add: ${inputValue.path}`);
9078
- return Promise.reject(/* @__PURE__ */ new Error("No mock data found"));
9340
+ throw new Error(`[FirestoreInstrumentation] No matching mock found for collection.add`);
9079
9341
  }
9080
9342
  const recordedId = mockData.result.id;
9081
9343
  if (!this.originalCollectionDocFn) {
@@ -9094,42 +9356,48 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
9094
9356
  path: collectionPath,
9095
9357
  documentId: documentPath
9096
9358
  };
9097
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
9098
- return SpanUtils.createAndExecuteSpan(self.mode, () => documentPath ? originalDoc.call(this, documentPath) : originalDoc.call(this), {
9099
- name: "firestore.collection.doc",
9100
- kind: __opentelemetry_api.SpanKind.CLIENT,
9101
- submodule: "collection",
9102
- packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
9103
- packageName: PACKAGE_NAME,
9104
- instrumentationName: self.INSTRUMENTATION_NAME,
9105
- inputValue,
9106
- isPreAppStart: false,
9107
- stopRecordingChildSpans: true
9108
- }, (spanInfo) => {
9109
- const mockData = findMockResponseSync({
9110
- mockRequestData: {
9111
- traceId: spanInfo.traceId,
9112
- spanId: spanInfo.spanId,
9113
- name: "firestore.collection.doc",
9114
- inputValue: createMockInputValue(inputValue),
9115
- packageName: PACKAGE_NAME,
9116
- instrumentationName: self.INSTRUMENTATION_NAME,
9117
- submoduleName: "collection",
9118
- kind: __opentelemetry_api.SpanKind.CLIENT
9119
- },
9120
- tuskDrift: self.tuskDrift
9359
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
9360
+ noOpRequestHandler: () => {
9361
+ return originalDoc.call(this, "");
9362
+ },
9363
+ isServerRequest: false,
9364
+ replayModeHandler: () => {
9365
+ return SpanUtils.createAndExecuteSpan(self.mode, () => documentPath ? originalDoc.call(this, documentPath) : originalDoc.call(this), {
9366
+ name: "firestore.collection.doc",
9367
+ kind: __opentelemetry_api.SpanKind.CLIENT,
9368
+ submodule: "collection",
9369
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
9370
+ packageName: PACKAGE_NAME,
9371
+ instrumentationName: self.INSTRUMENTATION_NAME,
9372
+ inputValue,
9373
+ isPreAppStart: false,
9374
+ stopRecordingChildSpans: true
9375
+ }, (spanInfo) => {
9376
+ const mockData = findMockResponseSync({
9377
+ mockRequestData: {
9378
+ traceId: spanInfo.traceId,
9379
+ spanId: spanInfo.spanId,
9380
+ name: "firestore.collection.doc",
9381
+ inputValue: createMockInputValue(inputValue),
9382
+ packageName: PACKAGE_NAME,
9383
+ instrumentationName: self.INSTRUMENTATION_NAME,
9384
+ submoduleName: "collection",
9385
+ kind: __opentelemetry_api.SpanKind.CLIENT
9386
+ },
9387
+ tuskDrift: self.tuskDrift
9388
+ });
9389
+ if (!mockData) {
9390
+ logger.warn(`[FirestoreInstrumentation] No mock data found for collection.doc: ${collectionPath}`);
9391
+ throw new Error(`[FirestoreInstrumentation] No matching mock found for collection.doc`);
9392
+ }
9393
+ const recordedId = mockData.result.id;
9394
+ logger.debug(`[FirestoreInstrumentation] replaying doc call with recorded id: ${recordedId}`);
9395
+ const docRef = originalDoc.call(this, recordedId);
9396
+ logger.debug(`[FirestoreInstrumentation] doc ref, id`, docRef, recordedId);
9397
+ return docRef;
9121
9398
  });
9122
- if (!mockData) {
9123
- logger.warn(`[FirestoreInstrumentation] No mock data found for collection.doc: ${collectionPath}`);
9124
- throw new Error("No mock data found for collection.doc");
9125
- }
9126
- const recordedId = mockData.result.id;
9127
- logger.debug(`[FirestoreInstrumentation] replaying doc call with recorded id: ${recordedId}`);
9128
- const docRef = originalDoc.call(this, recordedId);
9129
- logger.debug(`[FirestoreInstrumentation] doc ref, id`, docRef, recordedId);
9130
- return docRef;
9131
- });
9132
- } });
9399
+ }
9400
+ });
9133
9401
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
9134
9402
  originalFunctionCall: () => documentPath ? originalDoc.call(this, documentPath) : originalDoc.call(this),
9135
9403
  recordModeHandler: ({ isPreAppStart }) => {
@@ -9172,21 +9440,31 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
9172
9440
  operation: "query.get",
9173
9441
  path: this._queryOptions?.parentPath?.formattedName || "unknown"
9174
9442
  };
9175
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
9176
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalGet.call(this), {
9177
- name: "firestore.query.get",
9178
- kind: __opentelemetry_api.SpanKind.CLIENT,
9179
- submodule: "query",
9180
- packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
9181
- packageName: PACKAGE_NAME,
9182
- instrumentationName: self.INSTRUMENTATION_NAME,
9183
- inputValue,
9184
- isPreAppStart: false,
9185
- stopRecordingChildSpans: true
9186
- }, (spanInfo) => {
9187
- return self._handleReplayQueryGet(spanInfo, inputValue);
9188
- });
9189
- } });
9443
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
9444
+ noOpRequestHandler: () => {
9445
+ return new TdFirestoreQueryMock({
9446
+ size: 0,
9447
+ empty: true,
9448
+ docs: []
9449
+ });
9450
+ },
9451
+ isServerRequest: false,
9452
+ replayModeHandler: () => {
9453
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalGet.call(this), {
9454
+ name: "firestore.query.get",
9455
+ kind: __opentelemetry_api.SpanKind.CLIENT,
9456
+ submodule: "query",
9457
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
9458
+ packageName: PACKAGE_NAME,
9459
+ instrumentationName: self.INSTRUMENTATION_NAME,
9460
+ inputValue,
9461
+ isPreAppStart: false,
9462
+ stopRecordingChildSpans: true
9463
+ }, (spanInfo) => {
9464
+ return self._handleReplayQueryGet(spanInfo, inputValue);
9465
+ });
9466
+ }
9467
+ });
9190
9468
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
9191
9469
  originalFunctionCall: () => originalGet.call(this),
9192
9470
  recordModeHandler: ({ isPreAppStart }) => {
@@ -9263,7 +9541,7 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
9263
9541
  });
9264
9542
  if (!mockData) {
9265
9543
  logger.warn(`[FirestoreInstrumentation] No mock data found for query.get: ${inputValue.path}`);
9266
- return Promise.reject(/* @__PURE__ */ new Error("No mock data found"));
9544
+ throw new Error(`[FirestoreInstrumentation] No matching mock found for query.get`);
9267
9545
  }
9268
9546
  const queryResult = mockData.result;
9269
9547
  return new TdFirestoreQueryMock(queryResult);
@@ -9345,47 +9623,53 @@ var NextjsInstrumentation = class extends TdInstrumentationBase {
9345
9623
  const method = req.method || "GET";
9346
9624
  const url = req.url || "/";
9347
9625
  logger.debug(`[NextjsInstrumentation] Intercepted Next.js request: ${method} ${url}`);
9348
- if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({ replayModeHandler: () => {
9349
- const inputValue = {
9350
- method,
9351
- url,
9352
- target: url,
9353
- headers: self._normalizeHeaders(req.headers || {})
9354
- };
9355
- const replayTraceId = self.replayHooks.extractTraceIdFromHeaders(req);
9356
- if (!replayTraceId) {
9357
- logger.debug(`[NextjsInstrumentation] No trace ID found, calling original handler`);
9358
- return originalHandleRequest.call(this, req, res, parsedUrl);
9359
- }
9360
- logger.debug(`[NextjsInstrumentation] Setting replay trace id`, replayTraceId);
9361
- const envVars = self.replayHooks.extractEnvVarsFromHeaders(req);
9362
- if (envVars) EnvVarTracker.setEnvVars(replayTraceId, envVars);
9363
- const ctxWithReplayTraceId = SpanUtils.setCurrentReplayTraceId(replayTraceId);
9364
- if (!ctxWithReplayTraceId) throw new Error("Error setting current replay trace id");
9365
- return __opentelemetry_api.context.with(ctxWithReplayTraceId, () => {
9366
- return SpanUtils.createAndExecuteSpan(self.mode, () => originalHandleRequest.call(this, req, res, parsedUrl), {
9367
- name: url,
9368
- kind: __opentelemetry_api.SpanKind.SERVER,
9369
- packageName: "nextjs",
9370
- submodule: method,
9371
- packageType: __use_tusk_drift_schemas_core_span.PackageType.HTTP,
9372
- instrumentationName: self.INSTRUMENTATION_NAME,
9373
- inputValue,
9374
- inputSchemaMerges: { headers: { matchImportance: 0 } },
9375
- isPreAppStart: false
9376
- }, (spanInfo) => {
9377
- return self._handleNextjsRequestInSpan({
9378
- req,
9379
- res,
9380
- parsedUrl,
9381
- originalHandleRequest,
9382
- spanInfo,
9626
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
9627
+ noOpRequestHandler: () => {
9628
+ throw new Error(`[NextjsInstrumentation] Should never call noOpRequestHandler for server requests ${method} ${url}`);
9629
+ },
9630
+ isServerRequest: true,
9631
+ replayModeHandler: () => {
9632
+ const inputValue = {
9633
+ method,
9634
+ url,
9635
+ target: url,
9636
+ headers: self._normalizeHeaders(req.headers || {})
9637
+ };
9638
+ const replayTraceId = self.replayHooks.extractTraceIdFromHeaders(req);
9639
+ if (!replayTraceId) {
9640
+ logger.debug(`[NextjsInstrumentation] No trace ID found, calling original handler`);
9641
+ return originalHandleRequest.call(this, req, res, parsedUrl);
9642
+ }
9643
+ logger.debug(`[NextjsInstrumentation] Setting replay trace id`, replayTraceId);
9644
+ const envVars = self.replayHooks.extractEnvVarsFromHeaders(req);
9645
+ if (envVars) EnvVarTracker.setEnvVars(replayTraceId, envVars);
9646
+ const ctxWithReplayTraceId = SpanUtils.setCurrentReplayTraceId(replayTraceId);
9647
+ if (!ctxWithReplayTraceId) throw new Error("Error setting current replay trace id");
9648
+ return __opentelemetry_api.context.with(ctxWithReplayTraceId, () => {
9649
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalHandleRequest.call(this, req, res, parsedUrl), {
9650
+ name: url,
9651
+ kind: __opentelemetry_api.SpanKind.SERVER,
9652
+ packageName: "nextjs",
9653
+ submodule: method,
9654
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.HTTP,
9655
+ instrumentationName: self.INSTRUMENTATION_NAME,
9383
9656
  inputValue,
9384
- thisContext: this
9657
+ inputSchemaMerges: { headers: { matchImportance: 0 } },
9658
+ isPreAppStart: false
9659
+ }, (spanInfo) => {
9660
+ return self._handleNextjsRequestInSpan({
9661
+ req,
9662
+ res,
9663
+ parsedUrl,
9664
+ originalHandleRequest,
9665
+ spanInfo,
9666
+ inputValue,
9667
+ thisContext: this
9668
+ });
9385
9669
  });
9386
9670
  });
9387
- });
9388
- } });
9671
+ }
9672
+ });
9389
9673
  else if (self.mode === TuskDriftMode.RECORD) {
9390
9674
  if (method.toUpperCase() === "OPTIONS" || !!req.headers["access-control-request-method"]) return originalHandleRequest.call(this, req, res, parsedUrl);
9391
9675
  logger.debug(`[NextjsInstrumentation] Creating server span for ${method} ${url}`);
@@ -9523,9 +9807,9 @@ var NextjsInstrumentation = class extends TdInstrumentationBase {
9523
9807
  } : { code: __opentelemetry_api.SpanStatusCode.OK };
9524
9808
  SpanUtils.setStatus(spanInfo.span, status);
9525
9809
  const decodedType = getDecodedType(outputValue.headers?.["content-type"] || "");
9526
- if (decodedType && STATIC_ASSET_TYPES.has(decodedType)) {
9810
+ if (decodedType && !ACCEPTABLE_CONTENT_TYPES.has(decodedType)) {
9527
9811
  TraceBlockingManager.getInstance().blockTrace(spanInfo.traceId);
9528
- logger.debug(`[NextjsInstrumentation] Blocking trace ${spanInfo.traceId} because it is an static asset response. Decoded type: ${decodedType}`);
9812
+ logger.debug(`[NextjsInstrumentation] Blocking trace ${spanInfo.traceId} because it is not an acceptable decoded type: ${decodedType}`, { acceptableContentTypes: Array.from(ACCEPTABLE_CONTENT_TYPES) });
9529
9813
  }
9530
9814
  SpanUtils.endSpan(spanInfo.span);
9531
9815
  if (self.mode === TuskDriftMode.REPLAY) try {
@@ -12109,7 +12393,7 @@ var TdSpanExporter = class {
12109
12393
  logger.debug(`After filtering based on library name: ${filteredSpansBasedOnLibraryName.length} span(s) remaining`);
12110
12394
  const MAX_SPAN_SIZE_MB = 1;
12111
12395
  const MAX_SPAN_SIZE_BYTES = MAX_SPAN_SIZE_MB * 1024 * 1024;
12112
- const filteredSpansBasedOnSize = filteredSpansBasedOnLibraryName.filter((span) => {
12396
+ const filteredBlockedSpans = filteredSpansBasedOnLibraryName.filter((span) => {
12113
12397
  const traceId = span.spanContext().traceId;
12114
12398
  if (traceBlockingManager.isTraceBlocked(traceId)) {
12115
12399
  logger.debug(`Skipping span '${span.name}' (${span.spanContext().spanId}) - trace ${traceId} is blocked`);
@@ -12128,8 +12412,8 @@ var TdSpanExporter = class {
12128
12412
  }
12129
12413
  return true;
12130
12414
  });
12131
- logger.debug(`Filtered ${filteredSpansBasedOnLibraryName.length - filteredSpansBasedOnSize.length} oversized span(s), ${filteredSpansBasedOnSize.length} remaining`);
12132
- const cleanSpans = filteredSpansBasedOnSize.map((span) => SpanTransformer.transformSpanToCleanJSON(span));
12415
+ logger.debug(`Filtered ${filteredSpansBasedOnLibraryName.length - filteredBlockedSpans.length} blocked/oversized span(s), ${filteredBlockedSpans.length} remaining`);
12416
+ const cleanSpans = filteredBlockedSpans.map((span) => SpanTransformer.transformSpanToCleanJSON(span));
12133
12417
  if (this.adapters.length === 0) {
12134
12418
  logger.debug("No adapters configured");
12135
12419
  resultCallback({ code: import_src.ExportResultCode.SUCCESS });
@@ -12773,14 +13057,15 @@ var TuskDriftCore = class TuskDriftCore {
12773
13057
  sdkVersion: SDK_VERSION,
12774
13058
  sdkInstanceId: this.generateSdkInstanceId()
12775
13059
  });
12776
- const tracerProvider = new __opentelemetry_sdk_trace_node.NodeTracerProvider({ resource: new __opentelemetry_resources.Resource({ [__opentelemetry_semantic_conventions.ATTR_SERVICE_NAME]: serviceName }) });
12777
- tracerProvider.addSpanProcessor(new __opentelemetry_sdk_trace_node.BatchSpanProcessor(this.spanExporter, {
12778
- maxQueueSize: 2048,
12779
- maxExportBatchSize: 512,
12780
- scheduledDelayMillis: 2e3,
12781
- exportTimeoutMillis: 3e4
12782
- }));
12783
- tracerProvider.register();
13060
+ new __opentelemetry_sdk_trace_node.NodeTracerProvider({
13061
+ resource: new __opentelemetry_resources.Resource({ [__opentelemetry_semantic_conventions.ATTR_SERVICE_NAME]: serviceName }),
13062
+ spanProcessors: [new __opentelemetry_sdk_trace_node.BatchSpanProcessor(this.spanExporter, {
13063
+ maxQueueSize: 2048,
13064
+ maxExportBatchSize: 512,
13065
+ scheduledDelayMillis: 2e3,
13066
+ exportTimeoutMillis: 3e4
13067
+ })]
13068
+ }).register();
12784
13069
  logger.debug(`OpenTelemetry tracing initialized`);
12785
13070
  }
12786
13071
  generateSdkInstanceId() {