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

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.9";
279
290
 
280
291
  //#endregion
281
292
  //#region src/version.ts
@@ -1867,6 +1878,24 @@ var TdMockClientRequest = class TdMockClientRequest extends events.EventEmitter
1867
1878
  async startPlayback() {
1868
1879
  this.playbackStarted = true;
1869
1880
  try {
1881
+ if (!this.spanInfo) {
1882
+ logger.debug(`[TdMockClientRequest] Background request detected (no spanInfo), returning 200 OK without mock lookup`);
1883
+ const emptyResponse = {
1884
+ statusCode: 200,
1885
+ statusMessage: "OK",
1886
+ headers: {},
1887
+ httpVersion: "1.1",
1888
+ httpVersionMajor: 1,
1889
+ httpVersionMinor: 1,
1890
+ complete: true,
1891
+ readable: false
1892
+ };
1893
+ this.emit("finish");
1894
+ process.nextTick(() => {
1895
+ this.playResponse(emptyResponse);
1896
+ });
1897
+ return;
1898
+ }
1870
1899
  const rawInputValue = {
1871
1900
  method: this.method || "GET",
1872
1901
  path: this.path,
@@ -1904,7 +1933,10 @@ var TdMockClientRequest = class TdMockClientRequest extends events.EventEmitter
1904
1933
  headers: { matchImportance: 0 }
1905
1934
  }
1906
1935
  });
1907
- if (!mockData) throw new Error(`No matching mock found for ${this.method} ${this.path}`);
1936
+ if (!mockData) {
1937
+ logger.warn(`[TdMockClientRequest] No mock data found for ${this.method} ${this.path}`);
1938
+ throw new Error(`[TdMockClientRequest] No matching mock found for ${this.method} ${this.path}`);
1939
+ }
1908
1940
  this.emit("finish");
1909
1941
  process.nextTick(() => {
1910
1942
  this.playResponse(mockData.result);
@@ -2090,11 +2122,19 @@ function handleRecordMode({ originalFunctionCall, recordModeHandler, spanKind })
2090
2122
  /**
2091
2123
  * Utility function that abstracts the common replay mode pattern of checking if the app is ready
2092
2124
  *
2093
- * Currently just calls the replayModeHandler, but we might add some logic here in the future.
2125
+ * If this is a background request (app is ready and no parent span), calls the backgroundRequestHandler.
2126
+ * Otherwise, calls the replayModeHandler.
2094
2127
  * @param replayModeHandler - Function that handles the replay mode logic when app is ready
2095
- * @returns The result from either originalFunctionCall or replayModeHandler
2128
+ * @param noOpRequestHandler - Function to handle no-op requests, called for background requests
2129
+ * @returns The result from either noOpRequestHandler or replayModeHandler
2096
2130
  */
2097
- function handleReplayMode({ replayModeHandler }) {
2131
+ function handleReplayMode({ replayModeHandler, noOpRequestHandler, isServerRequest }) {
2132
+ const isAppReady = TuskDriftCore.getInstance().isAppReady();
2133
+ const currentSpanInfo = SpanUtils.getCurrentSpanInfo();
2134
+ if (isAppReady && !currentSpanInfo && !isServerRequest) {
2135
+ logger.debug(`[ModeUtils] Handling no-op request`);
2136
+ return noOpRequestHandler();
2137
+ }
2098
2138
  return replayModeHandler();
2099
2139
  }
2100
2140
 
@@ -2613,52 +2653,58 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
2613
2653
  logger.debug(`[HttpInstrumentation] Dropping inbound request due to transforms: ${method} ${url}`);
2614
2654
  return originalHandler.call(this);
2615
2655
  }
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,
2656
+ if (this.mode === TuskDriftMode.REPLAY) return handleReplayMode({
2657
+ noOpRequestHandler: () => {
2658
+ throw new Error(`[HttpInstrumentation] Should never call noOpRequestHandler for server requests`);
2659
+ },
2660
+ isServerRequest: true,
2661
+ replayModeHandler: () => {
2662
+ if (req.headers["accept-encoding"]) delete req.headers["accept-encoding"];
2663
+ const fullUrl = `${spanProtocol}://${req.headers.host || "localhost"}${url}`;
2664
+ const inputValue = {
2665
+ method,
2666
+ url: fullUrl,
2667
+ target,
2668
+ headers: req.headers,
2669
+ httpVersion: req.httpVersion,
2670
+ remoteAddress: req.socket?.remoteAddress,
2671
+ remotePort: req.socket?.remotePort
2672
+ };
2673
+ const replayTraceId = this.replayHooks.extractTraceIdFromHeaders(req);
2674
+ if (!replayTraceId) {
2675
+ logger.debug(`[HttpInstrumentation] No trace id found in headers`, req.headers);
2676
+ return originalHandler.call(this);
2677
+ }
2678
+ logger.debug(`[HttpInstrumentation] Setting replay trace id`, replayTraceId);
2679
+ const envVars = this.replayHooks.extractEnvVarsFromHeaders(req);
2680
+ if (envVars) EnvVarTracker.setEnvVars(replayTraceId, envVars);
2681
+ const ctxWithReplayTraceId = SpanUtils.setCurrentReplayTraceId(replayTraceId);
2682
+ if (!ctxWithReplayTraceId) throw new Error("Error setting current replay trace id");
2683
+ return __opentelemetry_api.context.with(ctxWithReplayTraceId, () => {
2684
+ return SpanUtils.createAndExecuteSpan(this.mode, () => originalHandler.call(this), {
2685
+ name: `${target}`,
2686
+ kind: __opentelemetry_api.SpanKind.SERVER,
2687
+ packageName: spanProtocol,
2688
+ submodule: method,
2689
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.HTTP,
2690
+ instrumentationName: this.INSTRUMENTATION_NAME,
2655
2691
  inputValue,
2656
- schemaMerges: { headers: { matchImportance: 0 } },
2657
- protocol: spanProtocol
2692
+ inputSchemaMerges: { headers: { matchImportance: 0 } },
2693
+ isPreAppStart: false
2694
+ }, (spanInfo) => {
2695
+ return this._handleInboundRequestInSpan({
2696
+ req,
2697
+ res,
2698
+ originalHandler,
2699
+ spanInfo,
2700
+ inputValue,
2701
+ schemaMerges: { headers: { matchImportance: 0 } },
2702
+ protocol: spanProtocol
2703
+ });
2658
2704
  });
2659
2705
  });
2660
- });
2661
- } });
2706
+ }
2707
+ });
2662
2708
  else if (this.mode === TuskDriftMode.RECORD) {
2663
2709
  if (method.toUpperCase() === "OPTIONS" || !!req.headers["access-control-request-method"]) return originalHandler.call(this);
2664
2710
  logger.debug(`[HttpInstrumentation] Creating server span for ${method} ${url}`);
@@ -3139,37 +3185,48 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
3139
3185
  const requestProtocol = self._normalizeProtocol(requestOptions.protocol || void 0, protocol);
3140
3186
  if (self.mode === TuskDriftMode.REPLAY) {
3141
3187
  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) => {
3188
+ return handleReplayMode({
3189
+ noOpRequestHandler: () => {
3163
3190
  return self.replayHooks.handleOutboundReplayRequest({
3164
3191
  method,
3165
3192
  requestOptions,
3166
3193
  protocol: requestProtocol,
3167
- args,
3168
- spanInfo,
3169
- stackTrace
3194
+ args
3170
3195
  });
3171
- });
3172
- } });
3196
+ },
3197
+ isServerRequest: false,
3198
+ replayModeHandler: () => {
3199
+ const headers = normalizeHeaders(requestOptions.headers || {});
3200
+ const inputValue = {
3201
+ method,
3202
+ path: requestOptions.path || void 0,
3203
+ headers,
3204
+ protocol: requestProtocol,
3205
+ hostname: requestOptions.hostname || requestOptions.host || void 0,
3206
+ port: requestOptions.port ? Number(requestOptions.port) : void 0,
3207
+ timeout: requestOptions.timeout || void 0
3208
+ };
3209
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalRequest.apply(this, args), {
3210
+ name: requestOptions.path || `${requestProtocol.toUpperCase()} ${method}`,
3211
+ kind: __opentelemetry_api.SpanKind.CLIENT,
3212
+ packageName: requestProtocol,
3213
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.HTTP,
3214
+ instrumentationName: self.INSTRUMENTATION_NAME,
3215
+ submodule: method,
3216
+ inputValue,
3217
+ isPreAppStart: false
3218
+ }, (spanInfo) => {
3219
+ return self.replayHooks.handleOutboundReplayRequest({
3220
+ method,
3221
+ requestOptions,
3222
+ protocol: requestProtocol,
3223
+ args,
3224
+ spanInfo,
3225
+ stackTrace
3226
+ });
3227
+ });
3228
+ }
3229
+ });
3173
3230
  } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
3174
3231
  originalFunctionCall: () => originalRequest.apply(this, args),
3175
3232
  recordModeHandler: ({ isPreAppStart }) => {
@@ -3221,36 +3278,47 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
3221
3278
  } else requestOptions = args[0] || {};
3222
3279
  const method = "GET";
3223
3280
  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) => {
3281
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
3282
+ noOpRequestHandler: () => {
3245
3283
  return self.replayHooks.handleOutboundReplayRequest({
3246
3284
  method,
3247
3285
  requestOptions,
3248
3286
  protocol: requestProtocol,
3249
- args,
3250
- spanInfo
3287
+ args
3251
3288
  });
3252
- });
3253
- } });
3289
+ },
3290
+ isServerRequest: false,
3291
+ replayModeHandler: () => {
3292
+ const headers = normalizeHeaders(requestOptions.headers || {});
3293
+ const inputValue = {
3294
+ method,
3295
+ path: requestOptions.path || void 0,
3296
+ headers,
3297
+ protocol: requestProtocol,
3298
+ hostname: requestOptions.hostname || requestOptions.host || void 0,
3299
+ port: requestOptions.port ? Number(requestOptions.port) : void 0,
3300
+ timeout: requestOptions.timeout || void 0
3301
+ };
3302
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalGet.apply(this, args), {
3303
+ name: requestOptions.path || `${requestProtocol.toUpperCase()} ${method}`,
3304
+ kind: __opentelemetry_api.SpanKind.CLIENT,
3305
+ packageName: requestProtocol,
3306
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.HTTP,
3307
+ instrumentationName: self.INSTRUMENTATION_NAME,
3308
+ submodule: method,
3309
+ inputValue,
3310
+ isPreAppStart: false
3311
+ }, (spanInfo) => {
3312
+ return self.replayHooks.handleOutboundReplayRequest({
3313
+ method,
3314
+ requestOptions,
3315
+ protocol: requestProtocol,
3316
+ args,
3317
+ spanInfo
3318
+ });
3319
+ });
3320
+ }
3321
+ });
3254
3322
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
3255
3323
  originalFunctionCall: () => originalGet.apply(this, args),
3256
3324
  recordModeHandler: ({ isPreAppStart }) => {
@@ -3646,7 +3714,8 @@ var TdPgClientMock = class extends events.EventEmitter {
3646
3714
  clientType: "client"
3647
3715
  };
3648
3716
  const inputValue = createMockInputValue(rawInputValue);
3649
- return this.pgInstrumentation.handleReplayQuery(queryConfig, inputValue, this.spanInfo, stackTrace);
3717
+ if (this.spanInfo) return this.pgInstrumentation.handleReplayQuery(queryConfig, inputValue, this.spanInfo, stackTrace);
3718
+ else return this.pgInstrumentation.handleNoOpReplayQuery(queryConfig);
3650
3719
  }
3651
3720
  release() {
3652
3721
  this.emit("end");
@@ -3751,22 +3820,28 @@ var PgInstrumentation = class extends TdInstrumentationBase {
3751
3820
  };
3752
3821
  if (self.mode === TuskDriftMode.REPLAY) {
3753
3822
  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
- } });
3823
+ return handleReplayMode({
3824
+ noOpRequestHandler: () => {
3825
+ return self.handleNoOpReplayQuery(queryConfig);
3826
+ },
3827
+ isServerRequest: false,
3828
+ replayModeHandler: () => {
3829
+ const packageName = inputValue.clientType === "pool" ? "pg-pool" : "pg";
3830
+ const spanName = inputValue.clientType === "pool" ? "pg-pool.query" : "pg.query";
3831
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(this, args), {
3832
+ name: spanName,
3833
+ kind: __opentelemetry_api.SpanKind.CLIENT,
3834
+ submodule: "query",
3835
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
3836
+ packageName,
3837
+ instrumentationName: self.INSTRUMENTATION_NAME,
3838
+ inputValue,
3839
+ isPreAppStart: false
3840
+ }, (spanInfo) => {
3841
+ return self.handleReplayQuery(queryConfig, inputValue, spanInfo, stackTrace);
3842
+ });
3843
+ }
3844
+ });
3770
3845
  } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
3771
3846
  originalFunctionCall: () => originalQuery.apply(this, args),
3772
3847
  recordModeHandler: ({ isPreAppStart }) => {
@@ -3796,20 +3871,29 @@ var PgInstrumentation = class extends TdInstrumentationBase {
3796
3871
  return (originalConnect) => {
3797
3872
  return function connect(callback) {
3798
3873
  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
- } });
3874
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
3875
+ noOpRequestHandler: () => {
3876
+ if (callback) {
3877
+ process.nextTick(() => callback(null));
3878
+ return;
3879
+ } else return Promise.resolve();
3880
+ },
3881
+ isServerRequest: false,
3882
+ replayModeHandler: () => {
3883
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
3884
+ name: `pg.connect`,
3885
+ kind: __opentelemetry_api.SpanKind.CLIENT,
3886
+ submodule: "connect",
3887
+ packageName: "pg",
3888
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
3889
+ instrumentationName: self.INSTRUMENTATION_NAME,
3890
+ inputValue,
3891
+ isPreAppStart: false
3892
+ }, (spanInfo) => {
3893
+ return self._handleReplayConnect(callback);
3894
+ });
3895
+ }
3896
+ });
3813
3897
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
3814
3898
  originalFunctionCall: () => originalConnect.apply(this, [callback]),
3815
3899
  recordModeHandler: ({ isPreAppStart }) => {
@@ -3913,6 +3997,16 @@ var PgInstrumentation = class extends TdInstrumentationBase {
3913
3997
  throw error;
3914
3998
  });
3915
3999
  }
4000
+ async handleNoOpReplayQuery(queryConfig) {
4001
+ const emptyResult = {
4002
+ rows: [],
4003
+ rowCount: 0
4004
+ };
4005
+ if (queryConfig.callback) {
4006
+ process.nextTick(() => queryConfig.callback(null, emptyResult));
4007
+ return;
4008
+ } else return Promise.resolve(emptyResult);
4009
+ }
3916
4010
  async handleReplayQuery(queryConfig, inputValue, spanInfo, stackTrace) {
3917
4011
  logger.debug(`[PgInstrumentation] Replaying PG query`);
3918
4012
  const packageName = inputValue.clientType === "pool" ? "pg-pool" : "pg";
@@ -3934,10 +4028,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
3934
4028
  if (!mockData) {
3935
4029
  const queryText = queryConfig.text || inputValue.text || "UNKNOWN_QUERY";
3936
4030
  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"));
4031
+ throw new Error(`[PgInstrumentation] No mock data found for PG query: ${queryText}`);
3941
4032
  }
3942
4033
  const processedResult = this.convertPostgresTypes(mockData.result);
3943
4034
  if (queryConfig.callback) {
@@ -4072,20 +4163,30 @@ var PgInstrumentation = class extends TdInstrumentationBase {
4072
4163
  return (originalConnect) => {
4073
4164
  return function connect(callback) {
4074
4165
  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
- } });
4166
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
4167
+ noOpRequestHandler: () => {
4168
+ const mockClient = new TdPgClientMock(self);
4169
+ if (callback) {
4170
+ process.nextTick(() => callback(null, mockClient, () => {}));
4171
+ return;
4172
+ } else return Promise.resolve(mockClient);
4173
+ },
4174
+ isServerRequest: false,
4175
+ replayModeHandler: () => {
4176
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
4177
+ name: `pg-pool.connect`,
4178
+ kind: __opentelemetry_api.SpanKind.CLIENT,
4179
+ submodule: "connect",
4180
+ packageName: "pg-pool",
4181
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
4182
+ instrumentationName: self.INSTRUMENTATION_NAME,
4183
+ inputValue,
4184
+ isPreAppStart: false
4185
+ }, (spanInfo) => {
4186
+ return self._handleReplayPoolConnect(spanInfo, callback);
4187
+ });
4188
+ }
4189
+ });
4089
4190
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
4090
4191
  originalFunctionCall: () => originalConnect.apply(this, [callback]),
4091
4192
  recordModeHandler: ({ isPreAppStart }) => {
@@ -4248,23 +4349,35 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
4248
4349
  connectionString: connectionString ? this._sanitizeConnectionString(connectionString) : void 0,
4249
4350
  options: options ? this._sanitizeConnectionOptions(options) : void 0
4250
4351
  };
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
- } });
4352
+ if (this.mode === TuskDriftMode.REPLAY) return handleReplayMode({
4353
+ noOpRequestHandler: () => {
4354
+ try {
4355
+ const sqlInstance = originalFunction(...args);
4356
+ return this._wrapSqlInstance(sqlInstance);
4357
+ } catch (error) {
4358
+ logger.debug(`[PostgresInstrumentation] Postgres connection error in replay: ${error.message}`);
4359
+ throw error;
4360
+ }
4361
+ },
4362
+ isServerRequest: false,
4363
+ replayModeHandler: () => {
4364
+ return SpanUtils.createAndExecuteSpan(this.mode, () => {
4365
+ const sqlInstance = originalFunction(...args);
4366
+ return this._wrapSqlInstance(sqlInstance);
4367
+ }, {
4368
+ name: "postgres.connect",
4369
+ kind: __opentelemetry_api.SpanKind.CLIENT,
4370
+ submodule: "connect",
4371
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
4372
+ packageName: "postgres",
4373
+ instrumentationName: this.INSTRUMENTATION_NAME,
4374
+ inputValue,
4375
+ isPreAppStart: false
4376
+ }, (spanInfo) => {
4377
+ return this._handleReplayConnect(originalFunction, args);
4378
+ });
4379
+ }
4380
+ });
4268
4381
  else if (this.mode === TuskDriftMode.RECORD) return handleRecordMode({
4269
4382
  originalFunctionCall: () => {
4270
4383
  const sqlInstance = originalFunction(...args);
@@ -4324,20 +4437,13 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
4324
4437
  }
4325
4438
  return wrappedInstance;
4326
4439
  }
4327
- _handleReplayConnect(spanInfo, originalFunction, args) {
4440
+ _handleReplayConnect(originalFunction, args) {
4328
4441
  logger.debug(`[PostgresInstrumentation] Replaying Postgres connection`);
4329
4442
  try {
4330
4443
  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;
4444
+ return this._wrapSqlInstance(sqlInstance);
4335
4445
  } catch (error) {
4336
4446
  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
4447
  throw error;
4342
4448
  }
4343
4449
  }
@@ -4397,26 +4503,30 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
4397
4503
  };
4398
4504
  if (this.mode === TuskDriftMode.REPLAY) {
4399
4505
  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",
4506
+ return handleReplayMode({
4507
+ noOpRequestHandler: () => {},
4508
+ isServerRequest: false,
4509
+ replayModeHandler: () => {
4510
+ return SpanUtils.createAndExecuteSpan(this.mode, () => originalSql.call(this, strings, ...values), {
4415
4511
  name: "postgres.query",
4416
- stackTrace
4512
+ kind: __opentelemetry_api.SpanKind.CLIENT,
4513
+ submodule: "query",
4514
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
4515
+ packageName: "postgres",
4516
+ instrumentationName: this.INSTRUMENTATION_NAME,
4517
+ inputValue,
4518
+ isPreAppStart: false
4519
+ }, (spanInfo) => {
4520
+ return this.handleReplaySqlQuery({
4521
+ inputValue,
4522
+ spanInfo,
4523
+ submodule: "query",
4524
+ name: "postgres.query",
4525
+ stackTrace
4526
+ });
4417
4527
  });
4418
- });
4419
- } });
4528
+ }
4529
+ });
4420
4530
  } else if (this.mode === TuskDriftMode.RECORD) return handleRecordMode({
4421
4531
  originalFunctionCall: () => originalSql.call(this, strings, ...values),
4422
4532
  recordModeHandler: ({ isPreAppStart }) => {
@@ -4450,28 +4560,34 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
4450
4560
  };
4451
4561
  if (this.mode === TuskDriftMode.REPLAY) {
4452
4562
  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",
4563
+ return handleReplayMode({
4564
+ noOpRequestHandler: () => {
4565
+ return Promise.resolve(void 0);
4566
+ },
4567
+ isServerRequest: false,
4568
+ replayModeHandler: () => {
4569
+ return this._createPendingQueryWrapper(() => {
4570
+ return SpanUtils.createAndExecuteSpan(this.mode, () => executeUnsafe(), {
4469
4571
  name: "postgres.unsafe",
4470
- stackTrace
4572
+ kind: __opentelemetry_api.SpanKind.CLIENT,
4573
+ submodule: "unsafe",
4574
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
4575
+ packageName: "postgres",
4576
+ instrumentationName: this.INSTRUMENTATION_NAME,
4577
+ inputValue,
4578
+ isPreAppStart: false
4579
+ }, (spanInfo) => {
4580
+ return this.handleReplayUnsafeQuery({
4581
+ inputValue,
4582
+ spanInfo,
4583
+ submodule: "unsafe",
4584
+ name: "postgres.unsafe",
4585
+ stackTrace
4586
+ });
4471
4587
  });
4472
4588
  });
4473
- });
4474
- } });
4589
+ }
4590
+ });
4475
4591
  } else if (this.mode === TuskDriftMode.RECORD) return handleRecordMode({
4476
4592
  originalFunctionCall: executeUnsafe,
4477
4593
  recordModeHandler: ({ isPreAppStart }) => {
@@ -4504,20 +4620,24 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
4504
4620
  };
4505
4621
  if (this.mode === TuskDriftMode.REPLAY) {
4506
4622
  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
- } });
4623
+ return handleReplayMode({
4624
+ noOpRequestHandler: () => {},
4625
+ isServerRequest: false,
4626
+ replayModeHandler: () => {
4627
+ return SpanUtils.createAndExecuteSpan(this.mode, () => executeBegin(), {
4628
+ name: "postgres.begin",
4629
+ kind: __opentelemetry_api.SpanKind.CLIENT,
4630
+ submodule: "transaction",
4631
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.PG,
4632
+ packageName: "postgres",
4633
+ instrumentationName: this.INSTRUMENTATION_NAME,
4634
+ inputValue,
4635
+ isPreAppStart: false
4636
+ }, (spanInfo) => {
4637
+ return this._handleReplayBeginTransaction(spanInfo, options, stackTrace);
4638
+ });
4639
+ }
4640
+ });
4521
4641
  } else if (this.mode === TuskDriftMode.RECORD) return handleRecordMode({
4522
4642
  originalFunctionCall: executeBegin,
4523
4643
  recordModeHandler: ({ isPreAppStart }) => {
@@ -4633,28 +4753,13 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
4633
4753
  });
4634
4754
  if (!mockData) {
4635
4755
  logger.warn(`[PostgresInstrumentation] No mock data found for transaction BEGIN`);
4636
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.OK });
4637
- return;
4756
+ throw new Error(`[PostgresInstrumentation] No matching mock found for transaction BEGIN`);
4638
4757
  }
4639
4758
  logger.debug(`[PostgresInstrumentation] Found mock data for transaction: ${JSON.stringify(mockData)}`);
4640
4759
  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 {
4760
+ if (transactionResult && typeof transactionResult === "object" && "status" in transactionResult && transactionResult.status === "committed") return transactionResult.result;
4761
+ else {
4649
4762
  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
4763
  throw new Error(errorMessage);
4659
4764
  }
4660
4765
  }
@@ -4701,7 +4806,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
4701
4806
  if (!mockData) {
4702
4807
  const queryText = inputValue.query || "UNKNOWN_QUERY";
4703
4808
  logger.warn(`[PostgresInstrumentation] No mock data found for Postgres sql query: ${queryText}`);
4704
- return;
4809
+ throw new Error(`[PostgresInstrumentation] No matching mock found for Postgres sql query: ${queryText}`);
4705
4810
  }
4706
4811
  logger.debug(`[PostgresInstrumentation] Found mock data for Postgres sql query: ${JSON.stringify(mockData)}`);
4707
4812
  const processedResult = this.convertPostgresTypes(mockData.result);
@@ -4732,7 +4837,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
4732
4837
  if (!mockData) {
4733
4838
  const queryText = inputValue.query || "UNKNOWN_QUERY";
4734
4839
  logger.warn(`[PostgresInstrumentation] No mock data found for Postgres unsafe query: ${queryText}`);
4735
- return;
4840
+ throw new Error(`[PostgresInstrumentation] No matching mock found for Postgres unsafe query: ${queryText}`);
4736
4841
  }
4737
4842
  logger.debug(`[PostgresInstrumentation] Found mock data for Postgres unsafe query: ${JSON.stringify(mockData)}`);
4738
4843
  const processedResult = this.convertPostgresTypes(mockData.result);
@@ -4821,7 +4926,7 @@ var PostgresInstrumentation = class extends TdInstrumentationBase {
4821
4926
  * Extends EventEmitter to properly handle all connection methods and events
4822
4927
  */
4823
4928
  var TdMysql2ConnectionMock = class extends events.EventEmitter {
4824
- constructor(mysql2Instrumentation, spanInfo, clientType = "poolConnection") {
4929
+ constructor(mysql2Instrumentation, clientType = "poolConnection", spanInfo) {
4825
4930
  super();
4826
4931
  this.threadId = null;
4827
4932
  this.config = {
@@ -4857,7 +4962,8 @@ var TdMysql2ConnectionMock = class extends events.EventEmitter {
4857
4962
  clientType: this.clientType
4858
4963
  };
4859
4964
  const inputValue = createMockInputValue(rawInputValue);
4860
- return this.mysql2Instrumentation.handleReplayQuery(queryConfig, inputValue, this.spanInfo, stackTrace);
4965
+ if (this.spanInfo) return this.mysql2Instrumentation.handleReplayQuery(queryConfig, inputValue, this.spanInfo, stackTrace);
4966
+ else return this.mysql2Instrumentation.handleNoOpReplayQuery(queryConfig);
4861
4967
  }
4862
4968
  execute(...args) {
4863
4969
  logger.debug(`[TdMysql2ConnectionMock] Mock connection execute intercepted in REPLAY mode`);
@@ -4881,7 +4987,8 @@ var TdMysql2ConnectionMock = class extends events.EventEmitter {
4881
4987
  clientType: this.clientType
4882
4988
  };
4883
4989
  const inputValue = createMockInputValue(rawInputValue);
4884
- return this.mysql2Instrumentation.handleReplayQuery(queryConfig, inputValue, this.spanInfo, stackTrace);
4990
+ if (this.spanInfo) return this.mysql2Instrumentation.handleReplayQuery(queryConfig, inputValue, this.spanInfo, stackTrace);
4991
+ else return this.mysql2Instrumentation.handleNoOpReplayQuery(queryConfig);
4885
4992
  }
4886
4993
  release() {
4887
4994
  this.emit("end");
@@ -4981,6 +5088,27 @@ var TdMysql2QueryMock = class {
4981
5088
  return this._handleQuery(queryConfig, inputValue, spanInfo, spanName, submoduleName, stackTrace);
4982
5089
  }
4983
5090
  /**
5091
+ * Handle background query requests (outside of trace context)
5092
+ * Returns an EventEmitter that immediately completes with empty results
5093
+ */
5094
+ handleNoOpReplayQuery(queryConfig) {
5095
+ logger.debug(`[Mysql2Instrumentation] Background query detected, returning empty result`);
5096
+ const emitter = new events.EventEmitter();
5097
+ emitter.then = function(onResolve, onReject) {
5098
+ return new Promise((resolve) => {
5099
+ emitter.once("end", () => {
5100
+ resolve([[], []]);
5101
+ });
5102
+ }).then(onResolve, onReject);
5103
+ };
5104
+ process.nextTick(() => {
5105
+ const callback = queryConfig.callback;
5106
+ if (callback) callback(null, [], []);
5107
+ emitter.emit("end");
5108
+ });
5109
+ return emitter;
5110
+ }
5111
+ /**
4984
5112
  * Handle query - always returns an EventEmitter (like mysql2 does)
4985
5113
  * This handles both callback and streaming modes
4986
5114
  * The EventEmitter is also thenable (has a .then() method) to support await/Promise usage
@@ -5005,12 +5133,7 @@ var TdMysql2QueryMock = class {
5005
5133
  if (!mockData) {
5006
5134
  const sql = queryConfig.sql || inputValue.sql || "UNKNOWN_QUERY";
5007
5135
  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;
5136
+ throw new Error(`[Mysql2Instrumentation] No matching mock found for query: ${sql}`);
5014
5137
  }
5015
5138
  const processedResult = this._convertMysql2Types(mockData.result);
5016
5139
  storedRows = processedResult.rows;
@@ -5335,21 +5458,27 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
5335
5458
  };
5336
5459
  if (self.mode === TuskDriftMode.REPLAY) {
5337
5460
  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
- } });
5461
+ return handleReplayMode({
5462
+ noOpRequestHandler: () => {
5463
+ return self.queryMock.handleNoOpReplayQuery(queryConfig);
5464
+ },
5465
+ isServerRequest: false,
5466
+ replayModeHandler: () => {
5467
+ const spanName = `mysql2.${clientType}.query`;
5468
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalQuery.apply(this, args), {
5469
+ name: spanName,
5470
+ kind: __opentelemetry_api.SpanKind.CLIENT,
5471
+ submodule: "query",
5472
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5473
+ packageName: "mysql2",
5474
+ instrumentationName: self.INSTRUMENTATION_NAME,
5475
+ inputValue,
5476
+ isPreAppStart: false
5477
+ }, (spanInfo) => {
5478
+ return self.handleReplayQuery(queryConfig, inputValue, spanInfo, "query", stackTrace);
5479
+ });
5480
+ }
5481
+ });
5353
5482
  } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
5354
5483
  originalFunctionCall: () => originalQuery.apply(this, args),
5355
5484
  recordModeHandler: ({ isPreAppStart }) => {
@@ -5394,21 +5523,27 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
5394
5523
  };
5395
5524
  if (self.mode === TuskDriftMode.REPLAY) {
5396
5525
  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
- } });
5526
+ return handleReplayMode({
5527
+ noOpRequestHandler: () => {
5528
+ return self.queryMock.handleNoOpReplayQuery(queryConfig);
5529
+ },
5530
+ isServerRequest: false,
5531
+ replayModeHandler: () => {
5532
+ const spanName = `mysql2.${clientType}.execute`;
5533
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalExecute.apply(this, args), {
5534
+ name: spanName,
5535
+ kind: __opentelemetry_api.SpanKind.CLIENT,
5536
+ submodule: "execute",
5537
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5538
+ packageName: "mysql2",
5539
+ instrumentationName: self.INSTRUMENTATION_NAME,
5540
+ inputValue,
5541
+ isPreAppStart: false
5542
+ }, (spanInfo) => {
5543
+ return self.handleReplayQuery(queryConfig, inputValue, spanInfo, "execute", stackTrace);
5544
+ });
5545
+ }
5546
+ });
5412
5547
  } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
5413
5548
  originalFunctionCall: () => originalExecute.apply(this, args),
5414
5549
  recordModeHandler: ({ isPreAppStart }) => {
@@ -5437,20 +5572,26 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
5437
5572
  return (originalGetConnection) => {
5438
5573
  return function getConnection(callback) {
5439
5574
  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
- } });
5575
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
5576
+ noOpRequestHandler: () => {
5577
+ return self.handleNoOpReplayGetConnection(callback);
5578
+ },
5579
+ isServerRequest: false,
5580
+ replayModeHandler: () => {
5581
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalGetConnection.apply(this, [callback]), {
5582
+ name: `mysql2.pool.getConnection`,
5583
+ kind: __opentelemetry_api.SpanKind.CLIENT,
5584
+ submodule: "getConnection",
5585
+ packageName: "mysql2",
5586
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5587
+ instrumentationName: self.INSTRUMENTATION_NAME,
5588
+ inputValue,
5589
+ isPreAppStart: false
5590
+ }, (spanInfo) => {
5591
+ return self._handleReplayPoolGetConnection(spanInfo, callback);
5592
+ });
5593
+ }
5594
+ });
5454
5595
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
5455
5596
  originalFunctionCall: () => originalGetConnection.apply(this, [callback]),
5456
5597
  recordModeHandler: ({ isPreAppStart }) => {
@@ -5478,24 +5619,34 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
5478
5619
  return (originalConnect) => {
5479
5620
  return function connect(callback) {
5480
5621
  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) => {
5622
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
5623
+ noOpRequestHandler: () => {
5492
5624
  if (callback) {
5493
5625
  process.nextTick(() => callback(null));
5494
5626
  return;
5495
5627
  }
5496
5628
  return Promise.resolve();
5497
- });
5498
- } });
5629
+ },
5630
+ isServerRequest: false,
5631
+ replayModeHandler: () => {
5632
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, [callback]), {
5633
+ name: `mysql2.${clientType}.connect`,
5634
+ kind: __opentelemetry_api.SpanKind.CLIENT,
5635
+ submodule: "connect",
5636
+ packageName: "mysql2",
5637
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5638
+ instrumentationName: self.INSTRUMENTATION_NAME,
5639
+ inputValue,
5640
+ isPreAppStart: false
5641
+ }, (spanInfo) => {
5642
+ if (callback) {
5643
+ process.nextTick(() => callback(null));
5644
+ return;
5645
+ }
5646
+ return Promise.resolve();
5647
+ });
5648
+ }
5649
+ });
5499
5650
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
5500
5651
  originalFunctionCall: () => originalConnect.apply(this, [callback]),
5501
5652
  recordModeHandler: ({ isPreAppStart }) => {
@@ -5523,24 +5674,34 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
5523
5674
  return (originalPing) => {
5524
5675
  return function ping(callback) {
5525
5676
  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) => {
5677
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
5678
+ noOpRequestHandler: () => {
5537
5679
  if (callback) {
5538
5680
  process.nextTick(() => callback(null));
5539
5681
  return;
5540
5682
  }
5541
5683
  return Promise.resolve();
5542
- });
5543
- } });
5684
+ },
5685
+ isServerRequest: false,
5686
+ replayModeHandler: () => {
5687
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalPing.apply(this, [callback]), {
5688
+ name: `mysql2.${clientType}.ping`,
5689
+ kind: __opentelemetry_api.SpanKind.CLIENT,
5690
+ submodule: "ping",
5691
+ packageName: "mysql2",
5692
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5693
+ instrumentationName: self.INSTRUMENTATION_NAME,
5694
+ inputValue,
5695
+ isPreAppStart: false
5696
+ }, (spanInfo) => {
5697
+ if (callback) {
5698
+ process.nextTick(() => callback(null));
5699
+ return;
5700
+ }
5701
+ return Promise.resolve();
5702
+ });
5703
+ }
5704
+ });
5544
5705
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
5545
5706
  originalFunctionCall: () => originalPing.apply(this, [callback]),
5546
5707
  recordModeHandler: ({ isPreAppStart }) => {
@@ -5568,24 +5729,34 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
5568
5729
  return (originalEnd) => {
5569
5730
  return function end(callback) {
5570
5731
  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) => {
5732
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
5733
+ noOpRequestHandler: () => {
5582
5734
  if (callback) {
5583
5735
  process.nextTick(() => callback(null));
5584
5736
  return;
5585
5737
  }
5586
5738
  return Promise.resolve();
5587
- });
5588
- } });
5739
+ },
5740
+ isServerRequest: false,
5741
+ replayModeHandler: () => {
5742
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalEnd.apply(this, [callback]), {
5743
+ name: `mysql2.${clientType}.end`,
5744
+ kind: __opentelemetry_api.SpanKind.CLIENT,
5745
+ submodule: "end",
5746
+ packageName: "mysql2",
5747
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
5748
+ instrumentationName: self.INSTRUMENTATION_NAME,
5749
+ inputValue,
5750
+ isPreAppStart: false
5751
+ }, (spanInfo) => {
5752
+ if (callback) {
5753
+ process.nextTick(() => callback(null));
5754
+ return;
5755
+ }
5756
+ return Promise.resolve();
5757
+ });
5758
+ }
5759
+ });
5589
5760
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
5590
5761
  originalFunctionCall: () => originalEnd.apply(this, [callback]),
5591
5762
  recordModeHandler: ({ isPreAppStart }) => {
@@ -5760,6 +5931,9 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
5760
5931
  handleReplayQuery(queryConfig, inputValue, spanInfo, submoduleName = "query", stackTrace) {
5761
5932
  return this.queryMock.handleReplayQuery(queryConfig, inputValue, spanInfo, submoduleName, stackTrace);
5762
5933
  }
5934
+ handleNoOpReplayQuery(queryConfig) {
5935
+ return this.queryMock.handleNoOpReplayQuery(queryConfig);
5936
+ }
5763
5937
  _handleRecordPoolGetConnectionInSpan(spanInfo, originalGetConnection, callback, context$4) {
5764
5938
  if (callback) {
5765
5939
  const wrappedCallback = (error, connection) => {
@@ -5813,9 +5987,18 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
5813
5987
  throw error;
5814
5988
  });
5815
5989
  }
5990
+ handleNoOpReplayGetConnection(callback) {
5991
+ logger.debug(`[Mysql2Instrumentation] Background getConnection detected, returning mock connection`);
5992
+ const mockConnection = new TdMysql2ConnectionMock(this, "pool");
5993
+ if (callback) {
5994
+ process.nextTick(() => callback(null, mockConnection));
5995
+ return;
5996
+ }
5997
+ return Promise.resolve(mockConnection);
5998
+ }
5816
5999
  _handleReplayPoolGetConnection(spanInfo, callback) {
5817
6000
  logger.debug(`[Mysql2Instrumentation] Replaying MySQL2 Pool getConnection`);
5818
- const mockConnection = new TdMysql2ConnectionMock(this, spanInfo, "pool");
6001
+ const mockConnection = new TdMysql2ConnectionMock(this, "pool", spanInfo);
5819
6002
  if (callback) {
5820
6003
  process.nextTick(() => callback(null, mockConnection));
5821
6004
  return;
@@ -5874,58 +6057,59 @@ var Mysql2Instrumentation = class extends TdInstrumentationBase {
5874
6057
  },
5875
6058
  spanKind: __opentelemetry_api.SpanKind.CLIENT
5876
6059
  });
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;
6060
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
6061
+ noOpRequestHandler: () => {
6062
+ return new TdMysql2ConnectionMock(self, "connection");
6063
+ },
6064
+ isServerRequest: false,
6065
+ replayModeHandler: () => {
6066
+ return SpanUtils.createAndExecuteSpan(self.mode, () => new OriginalConnection(...args), {
6067
+ name: `mysql2.connection.create`,
6068
+ kind: __opentelemetry_api.SpanKind.CLIENT,
6069
+ submodule: "connectEvent",
6070
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.MYSQL,
6071
+ packageName: "mysql2",
6072
+ instrumentationName: self.INSTRUMENTATION_NAME,
6073
+ inputValue,
6074
+ isPreAppStart: false
6075
+ }, (spanInfo) => {
6076
+ class MockConnection extends OriginalConnection {
6077
+ constructor(...mockConnectionArgs) {
6078
+ const clonedArgs = JSON.parse(JSON.stringify(mockConnectionArgs));
6079
+ if (clonedArgs[0] && clonedArgs[0].config) {
6080
+ clonedArgs[0].config.host = "127.0.0.1";
6081
+ clonedArgs[0].config.port = 127;
6082
+ } else if (clonedArgs[0]) {
6083
+ clonedArgs[0].host = "127.0.0.1";
6084
+ clonedArgs[0].port = 127;
6085
+ }
6086
+ super(...clonedArgs);
6087
+ this._isConnectOrErrorEmitted = false;
6088
+ this._connectEventMock = new TdMysql2ConnectionEventMock(spanInfo);
5897
6089
  }
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;
6090
+ on(event, listener) {
6091
+ if (!this._connectEventMock) return super.on(event, listener);
6092
+ if (event === "connect" && !this._isConnectOrErrorEmitted) {
6093
+ this._connectEventMock.getReplayedConnectionEvent(inputValue).then(({ output }) => {
6094
+ if (output !== void 0) process.nextTick(() => {
6095
+ listener.call(this, output);
6096
+ this._isConnectOrErrorEmitted = true;
6097
+ });
6098
+ }).catch((err) => {
6099
+ logger.error(`[Mysql2Instrumentation] Error replaying connection event:`, err);
5909
6100
  });
5910
- }).catch((err) => {
5911
- logger.error(`[Mysql2Instrumentation] Error replaying connection event:`, err);
5912
- });
5913
- return this;
6101
+ return this;
6102
+ }
6103
+ if (event === "error" && !this._isConnectOrErrorEmitted) return this;
6104
+ return super.on(event, listener);
5914
6105
  }
5915
- if (event === "error" && !this._isConnectOrErrorEmitted) return this;
5916
- return super.on(event, listener);
5917
6106
  }
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
- } });
6107
+ const mockConnection = new MockConnection(...args);
6108
+ mockConnection.addListener("error", (_err) => {});
6109
+ return mockConnection;
6110
+ });
6111
+ }
6112
+ });
5929
6113
  return new OriginalConnection(...args);
5930
6114
  }
5931
6115
  const staticProps = Object.getOwnPropertyNames(OriginalConnection).filter((key) => ![
@@ -6123,19 +6307,28 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
6123
6307
  }
6124
6308
  if (self.mode === TuskDriftMode.REPLAY) {
6125
6309
  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
- } });
6310
+ return handleReplayMode({
6311
+ noOpRequestHandler: () => {
6312
+ if (!!verifyConfig.callback) {
6313
+ process.nextTick(() => verifyConfig.callback(null, void 0));
6314
+ return;
6315
+ } else return;
6316
+ },
6317
+ isServerRequest: false,
6318
+ replayModeHandler: () => {
6319
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalVerify.apply(this, args), {
6320
+ name: "jsonwebtoken.verify",
6321
+ kind: __opentelemetry_api.SpanKind.CLIENT,
6322
+ submodule: "verify",
6323
+ packageName: "jsonwebtoken",
6324
+ instrumentationName: self.INSTRUMENTATION_NAME,
6325
+ inputValue,
6326
+ isPreAppStart: false
6327
+ }, (spanInfo) => {
6328
+ return self.handleReplayVerify(verifyConfig, inputValue, spanInfo, stackTrace);
6329
+ });
6330
+ }
6331
+ });
6139
6332
  } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
6140
6333
  originalFunctionCall: () => originalVerify.apply(this, args),
6141
6334
  recordModeHandler: ({ isPreAppStart }) => {
@@ -6178,19 +6371,28 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
6178
6371
  };
6179
6372
  if (self.mode === TuskDriftMode.REPLAY) {
6180
6373
  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
- } });
6374
+ return handleReplayMode({
6375
+ noOpRequestHandler: () => {
6376
+ if (!!signConfig.callback) {
6377
+ process.nextTick(() => signConfig.callback(null, void 0));
6378
+ return;
6379
+ } else return;
6380
+ },
6381
+ isServerRequest: false,
6382
+ replayModeHandler: () => {
6383
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalSign.apply(this, args), {
6384
+ name: "jsonwebtoken.sign",
6385
+ kind: __opentelemetry_api.SpanKind.CLIENT,
6386
+ submodule: "sign",
6387
+ packageName: "jsonwebtoken",
6388
+ instrumentationName: self.INSTRUMENTATION_NAME,
6389
+ inputValue,
6390
+ isPreAppStart: false
6391
+ }, (spanInfo) => {
6392
+ return self.handleReplaySign(signConfig, inputValue, spanInfo, stackTrace);
6393
+ });
6394
+ }
6395
+ });
6194
6396
  } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
6195
6397
  originalFunctionCall: () => originalSign.apply(this, args),
6196
6398
  recordModeHandler: ({ isPreAppStart }) => {
@@ -6378,11 +6580,7 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
6378
6580
  const hasCallback = !!verifyConfig.callback;
6379
6581
  if (!mockData) {
6380
6582
  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;
6583
+ throw new Error(`[JsonwebtokenInstrumentation] No matching mock found for JWT verify: ${verifyConfig.token}`);
6386
6584
  }
6387
6585
  if (mockData.result && mockData.result.error) {
6388
6586
  let error = mockData.result.error;
@@ -6425,11 +6623,7 @@ var JsonwebtokenInstrumentation = class extends TdInstrumentationBase {
6425
6623
  const hasCallback = !!signConfig.callback;
6426
6624
  if (!mockData) {
6427
6625
  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;
6626
+ throw new Error(`[JsonwebtokenInstrumentation] No matching mock found for JWT sign`);
6433
6627
  }
6434
6628
  if (mockData.result && mockData.result.error) {
6435
6629
  let error = mockData.result.error;
@@ -6846,20 +7040,30 @@ var FetchInstrumentation = class extends TdInstrumentationBase {
6846
7040
  headers: normalizedHeaders,
6847
7041
  body: encodedBody
6848
7042
  };
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
- } });
7043
+ if (this.mode === TuskDriftMode.REPLAY) return handleReplayMode({
7044
+ noOpRequestHandler: () => {
7045
+ const mockResponse = new Response(null, {
7046
+ status: 200,
7047
+ statusText: "OK"
7048
+ });
7049
+ return Promise.resolve(mockResponse);
7050
+ },
7051
+ isServerRequest: false,
7052
+ replayModeHandler: () => {
7053
+ return SpanUtils.createAndExecuteSpan(this.mode, () => this.originalFetch(input, init), {
7054
+ name: url,
7055
+ kind: __opentelemetry_api.SpanKind.CLIENT,
7056
+ packageName: "fetch",
7057
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.HTTP,
7058
+ instrumentationName: this.INSTRUMENTATION_NAME,
7059
+ submodule: inputValue.method,
7060
+ inputValue,
7061
+ isPreAppStart: false
7062
+ }, (spanInfo) => {
7063
+ return this._handleReplayFetch(inputValue, spanInfo, stackTrace);
7064
+ });
7065
+ }
7066
+ });
6863
7067
  else if (this.mode === TuskDriftMode.RECORD) return handleRecordMode({
6864
7068
  originalFunctionCall: () => this.originalFetch(input, init),
6865
7069
  recordModeHandler: ({ isPreAppStart }) => this._handleRecordFetch(input, inputValue, isPreAppStart, init),
@@ -6961,7 +7165,10 @@ var FetchInstrumentation = class extends TdInstrumentationBase {
6961
7165
  ...inputValue.headers && { headers: { matchImportance: 0 } }
6962
7166
  }
6963
7167
  });
6964
- if (!mockData) throw new Error(`No matching mock found for fetch request with input value: ${JSON.stringify(inputValue)}`);
7168
+ if (!mockData) {
7169
+ logger.warn(`[FetchInstrumentation] No mock data found for fetch request with input value: ${JSON.stringify(inputValue)}`);
7170
+ throw new Error(`[FetchInstrumentation] No matching mock found for fetch request`);
7171
+ }
6965
7172
  const { result } = mockData;
6966
7173
  const responseBody = this._constructFetchResponseBody(result);
6967
7174
  const mockResponse = new Response(responseBody, {
@@ -7227,20 +7434,24 @@ var IORedisInstrumentation = class extends TdInstrumentationBase {
7227
7434
  };
7228
7435
  if (self.mode === TuskDriftMode.REPLAY) {
7229
7436
  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
- } });
7437
+ return handleReplayMode({
7438
+ noOpRequestHandler: () => {},
7439
+ isServerRequest: false,
7440
+ replayModeHandler: () => {
7441
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalSendCommand.apply(this, arguments), {
7442
+ name: `ioredis.${commandName}`,
7443
+ kind: __opentelemetry_api.SpanKind.CLIENT,
7444
+ submodule: commandName,
7445
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.REDIS,
7446
+ packageName: "ioredis",
7447
+ instrumentationName: self.INSTRUMENTATION_NAME,
7448
+ inputValue,
7449
+ isPreAppStart: false
7450
+ }, (spanInfo) => {
7451
+ return self._handleReplaySendCommand(spanInfo, cmd, inputValue, stackTrace);
7452
+ });
7453
+ }
7454
+ });
7244
7455
  } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
7245
7456
  originalFunctionCall: () => originalSendCommand.apply(this, arguments),
7246
7457
  recordModeHandler: ({ isPreAppStart }) => {
@@ -7271,20 +7482,29 @@ var IORedisInstrumentation = class extends TdInstrumentationBase {
7271
7482
  host: this.options?.host,
7272
7483
  port: this.options?.port
7273
7484
  };
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
- } });
7485
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
7486
+ noOpRequestHandler: () => {
7487
+ process.nextTick(() => {
7488
+ this.emit("ready");
7489
+ });
7490
+ return Promise.resolve();
7491
+ },
7492
+ isServerRequest: false,
7493
+ replayModeHandler: () => {
7494
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalConnect.apply(this, arguments), {
7495
+ name: "ioredis.connect",
7496
+ kind: __opentelemetry_api.SpanKind.CLIENT,
7497
+ submodule: "connect",
7498
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.REDIS,
7499
+ packageName: "ioredis",
7500
+ instrumentationName: self.INSTRUMENTATION_NAME,
7501
+ inputValue,
7502
+ isPreAppStart: false
7503
+ }, (spanInfo) => {
7504
+ return self._handleReplayConnect(this);
7505
+ });
7506
+ }
7507
+ });
7288
7508
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
7289
7509
  originalFunctionCall: () => originalConnect.apply(this, arguments),
7290
7510
  recordModeHandler: ({ isPreAppStart }) => {
@@ -7341,20 +7561,26 @@ var IORedisInstrumentation = class extends TdInstrumentationBase {
7341
7561
  command: q.name,
7342
7562
  args: q.args || []
7343
7563
  })) };
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
- } });
7564
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
7565
+ noOpRequestHandler: () => {
7566
+ return [];
7567
+ },
7568
+ isServerRequest: false,
7569
+ replayModeHandler: () => {
7570
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalExec.apply(this, args), {
7571
+ name: "ioredis.pipeline.exec",
7572
+ kind: __opentelemetry_api.SpanKind.CLIENT,
7573
+ submodule: "pipeline-exec",
7574
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.REDIS,
7575
+ packageName: "ioredis",
7576
+ instrumentationName: self.INSTRUMENTATION_NAME,
7577
+ inputValue,
7578
+ isPreAppStart: false
7579
+ }, (spanInfo) => {
7580
+ return self._handleReplayPipelineExec(spanInfo, inputValue, args);
7581
+ });
7582
+ }
7583
+ });
7358
7584
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
7359
7585
  originalFunctionCall: () => originalExec.apply(this, args),
7360
7586
  recordModeHandler: ({ isPreAppStart }) => {
@@ -7403,7 +7629,7 @@ var IORedisInstrumentation = class extends TdInstrumentationBase {
7403
7629
  });
7404
7630
  return promise;
7405
7631
  }
7406
- async _handleReplaySendCommand(spanInfo, cmd, inputValue, commandName, stackTrace) {
7632
+ async _handleReplaySendCommand(spanInfo, cmd, inputValue, stackTrace) {
7407
7633
  logger.debug(`[IORedisInstrumentation] Replaying IORedis command ${cmd.name}`);
7408
7634
  const mockData = await findMockResponseAsync({
7409
7635
  mockRequestData: {
@@ -7421,13 +7647,10 @@ var IORedisInstrumentation = class extends TdInstrumentationBase {
7421
7647
  });
7422
7648
  if (!mockData) {
7423
7649
  logger.warn(`[IORedisInstrumentation] No mock data found for command: ${cmd.name}`);
7424
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.OK });
7425
- return;
7650
+ throw new Error(`[IORedisInstrumentation] No matching mock found for command: ${cmd.name}`);
7426
7651
  }
7427
7652
  logger.debug(`[IORedisInstrumentation] Found mock data for command ${cmd.name}: ${JSON.stringify(mockData)}`);
7428
7653
  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
7654
  if (cmd.callback && typeof cmd.callback === "function") process.nextTick(() => {
7432
7655
  cmd.callback(null, result);
7433
7656
  });
@@ -7465,10 +7688,8 @@ var IORedisInstrumentation = class extends TdInstrumentationBase {
7465
7688
  }
7466
7689
  return promise;
7467
7690
  }
7468
- async _handleReplayConnect(spanInfo, thisContext) {
7691
+ async _handleReplayConnect(thisContext) {
7469
7692
  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
7693
  process.nextTick(() => {
7473
7694
  thisContext.emit("ready");
7474
7695
  });
@@ -7517,8 +7738,7 @@ var IORedisInstrumentation = class extends TdInstrumentationBase {
7517
7738
  });
7518
7739
  if (!mockData) {
7519
7740
  logger.warn(`[IORedisInstrumentation] No mock data found for pipeline exec`);
7520
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.OK });
7521
- return [];
7741
+ throw new Error(`[IORedisInstrumentation] No matching mock found for pipeline exec`);
7522
7742
  }
7523
7743
  logger.debug(`[IORedisInstrumentation] Found mock data for pipeline exec: ${JSON.stringify(mockData)}`);
7524
7744
  const result = this._deserializePipelineOutput(mockData.result);
@@ -7526,8 +7746,6 @@ var IORedisInstrumentation = class extends TdInstrumentationBase {
7526
7746
  if (typeof callback === "function") process.nextTick(() => {
7527
7747
  callback(null, result);
7528
7748
  });
7529
- SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: mockData.result });
7530
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.OK });
7531
7749
  return Promise.resolve(result);
7532
7750
  }
7533
7751
  _sanitizeArgs(args) {
@@ -7868,20 +8086,26 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
7868
8086
  };
7869
8087
  if (self.mode === TuskDriftMode.REPLAY) {
7870
8088
  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
- } });
8089
+ return handleReplayMode({
8090
+ noOpRequestHandler: () => {
8091
+ callback(null, void 0);
8092
+ },
8093
+ isServerRequest: false,
8094
+ replayModeHandler: () => {
8095
+ return SpanUtils.createAndExecuteSpan(self.mode, () => original.apply(this, args), {
8096
+ name: "grpc.client.unary",
8097
+ kind: __opentelemetry_api.SpanKind.CLIENT,
8098
+ submodule: "client",
8099
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.GRPC,
8100
+ packageName: GRPC_MODULE_NAME,
8101
+ instrumentationName: self.INSTRUMENTATION_NAME,
8102
+ inputValue,
8103
+ isPreAppStart: false
8104
+ }, (spanInfo) => {
8105
+ return self._handleReplayUnaryRequest(spanInfo, inputValue, callback, MetadataConstructor, stackTrace);
8106
+ });
8107
+ }
8108
+ });
7885
8109
  } else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
7886
8110
  originalFunctionCall: () => original.apply(this, args),
7887
8111
  recordModeHandler: ({ isPreAppStart }) => {
@@ -7947,20 +8171,35 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
7947
8171
  jsonableStringMap
7948
8172
  }
7949
8173
  };
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
- } });
8174
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
8175
+ noOpRequestHandler: () => {
8176
+ const stream$1 = new stream.Readable({
8177
+ objectMode: true,
8178
+ read() {}
8179
+ });
8180
+ Object.assign(stream$1, {
8181
+ cancel() {},
8182
+ getPeer: () => "0.0.0.0:0000",
8183
+ call: void 0
8184
+ });
8185
+ return stream$1;
8186
+ },
8187
+ isServerRequest: false,
8188
+ replayModeHandler: () => {
8189
+ return SpanUtils.createAndExecuteSpan(self.mode, () => original.apply(this, args), {
8190
+ name: "grpc.client.server_stream",
8191
+ kind: __opentelemetry_api.SpanKind.CLIENT,
8192
+ submodule: "client",
8193
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.GRPC,
8194
+ packageName: GRPC_MODULE_NAME,
8195
+ instrumentationName: self.INSTRUMENTATION_NAME,
8196
+ inputValue,
8197
+ isPreAppStart: false
8198
+ }, (spanInfo) => {
8199
+ return self._handleReplayServerStreamRequest(spanInfo, inputValue, MetadataConstructor);
8200
+ });
8201
+ }
8202
+ });
7964
8203
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
7965
8204
  originalFunctionCall: () => original.apply(this, args),
7966
8205
  recordModeHandler: ({ isPreAppStart }) => {
@@ -8147,9 +8386,7 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
8147
8386
  }).then((mockData) => {
8148
8387
  if (!mockData) {
8149
8388
  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;
8389
+ throw new Error(`[GrpcInstrumentation] No matching mock found for gRPC unary request`);
8153
8390
  }
8154
8391
  const mockResult = mockData.result;
8155
8392
  let status;
@@ -8182,12 +8419,9 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
8182
8419
  if (mockResult.metadata) emitter.emit("metadata", deserializeGrpcMetadata(MetadataConstructor, mockResult.metadata));
8183
8420
  emitter.emit("status", status);
8184
8421
  });
8185
- SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: mockResult });
8186
- SpanUtils.endSpan(spanInfo.span, { code: mockResult.error ? __opentelemetry_api.SpanStatusCode.ERROR : __opentelemetry_api.SpanStatusCode.OK });
8187
8422
  }).catch((error) => {
8188
8423
  logger.error(`[GrpcInstrumentation] Error fetching mock data:`, error);
8189
8424
  callback(error);
8190
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.ERROR });
8191
8425
  });
8192
8426
  return emitter;
8193
8427
  }
@@ -8301,21 +8535,7 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
8301
8535
  }).then((mockData) => {
8302
8536
  if (!mockData) {
8303
8537
  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;
8538
+ throw new Error(`[GrpcInstrumentation] No matching mock found for gRPC server stream request`);
8319
8539
  }
8320
8540
  const mockResult = mockData.result;
8321
8541
  process.nextTick(() => {
@@ -8335,11 +8555,6 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
8335
8555
  stream$1.emit("error", errorObj);
8336
8556
  stream$1.emit("status", status);
8337
8557
  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
8558
  } else {
8344
8559
  const { body, status: successStatus } = mockResult;
8345
8560
  const status = {
@@ -8356,8 +8571,6 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
8356
8571
  });
8357
8572
  stream$1.push(null);
8358
8573
  stream$1.emit("status", status);
8359
- SpanUtils.addSpanAttributes(spanInfo.span, { outputValue: mockResult });
8360
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.OK });
8361
8574
  }
8362
8575
  });
8363
8576
  }).catch((error) => {
@@ -8371,7 +8584,6 @@ var GrpcInstrumentation = class GrpcInstrumentation extends TdInstrumentationBas
8371
8584
  });
8372
8585
  stream$1.push(null);
8373
8586
  });
8374
- SpanUtils.endSpan(spanInfo.span, { code: __opentelemetry_api.SpanStatusCode.ERROR });
8375
8587
  });
8376
8588
  return stream$1;
8377
8589
  }
@@ -8684,21 +8896,31 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
8684
8896
  operation: "document.get",
8685
8897
  path: this.path
8686
8898
  };
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
- } });
8899
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
8900
+ noOpRequestHandler: () => {
8901
+ return new TdFirestoreDocumentMock({
8902
+ exists: false,
8903
+ id: "",
8904
+ path: ""
8905
+ });
8906
+ },
8907
+ isServerRequest: false,
8908
+ replayModeHandler: () => {
8909
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalGet.call(this), {
8910
+ name: "firestore.document.get",
8911
+ kind: __opentelemetry_api.SpanKind.CLIENT,
8912
+ submodule: "document",
8913
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
8914
+ packageName: PACKAGE_NAME,
8915
+ instrumentationName: self.INSTRUMENTATION_NAME,
8916
+ inputValue,
8917
+ isPreAppStart: false,
8918
+ stopRecordingChildSpans: true
8919
+ }, (spanInfo) => {
8920
+ return self._handleReplayDocumentGet(spanInfo, inputValue);
8921
+ });
8922
+ }
8923
+ });
8702
8924
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
8703
8925
  originalFunctionCall: () => originalGet.call(this),
8704
8926
  recordModeHandler: ({ isPreAppStart }) => {
@@ -8767,7 +8989,7 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
8767
8989
  });
8768
8990
  if (!mockData) {
8769
8991
  logger.warn(`[FirestoreInstrumentation] No mock data found for document.get: ${inputValue.path}`);
8770
- return Promise.reject(/* @__PURE__ */ new Error("No mock data found"));
8992
+ throw new Error(`[FirestoreInstrumentation] No matching mock found for document.get`);
8771
8993
  }
8772
8994
  const documentResult = mockData.result;
8773
8995
  return new TdFirestoreDocumentMock(documentResult);
@@ -8781,21 +9003,32 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
8781
9003
  path: this.path,
8782
9004
  data
8783
9005
  };
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
- } });
9006
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
9007
+ noOpRequestHandler: () => {
9008
+ const now = Date.now();
9009
+ const emptyWriteResult = { writeTime: {
9010
+ seconds: Math.floor(now / 1e3),
9011
+ nanoseconds: now % 1e3 * 1e6
9012
+ } };
9013
+ return new TdFirestoreWriteResultMock(emptyWriteResult);
9014
+ },
9015
+ isServerRequest: false,
9016
+ replayModeHandler: () => {
9017
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalCreate.call(this, data), {
9018
+ name: "firestore.document.create",
9019
+ kind: __opentelemetry_api.SpanKind.CLIENT,
9020
+ submodule: "document",
9021
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
9022
+ packageName: PACKAGE_NAME,
9023
+ instrumentationName: self.INSTRUMENTATION_NAME,
9024
+ inputValue,
9025
+ isPreAppStart: false,
9026
+ stopRecordingChildSpans: true
9027
+ }, (spanInfo) => {
9028
+ return self._handleReplayDocumentWrite(spanInfo, inputValue);
9029
+ });
9030
+ }
9031
+ });
8799
9032
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
8800
9033
  originalFunctionCall: () => originalCreate.call(this, data),
8801
9034
  recordModeHandler: ({ isPreAppStart }) => {
@@ -8829,21 +9062,32 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
8829
9062
  data,
8830
9063
  options
8831
9064
  };
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
- } });
9065
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
9066
+ noOpRequestHandler: () => {
9067
+ const now = Date.now();
9068
+ const emptyWriteResult = { writeTime: {
9069
+ seconds: Math.floor(now / 1e3),
9070
+ nanoseconds: now % 1e3 * 1e6
9071
+ } };
9072
+ return new TdFirestoreWriteResultMock(emptyWriteResult);
9073
+ },
9074
+ isServerRequest: false,
9075
+ replayModeHandler: () => {
9076
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalSet.call(this, data, options), {
9077
+ name: "firestore.document.set",
9078
+ kind: __opentelemetry_api.SpanKind.CLIENT,
9079
+ submodule: "document",
9080
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
9081
+ packageName: PACKAGE_NAME,
9082
+ instrumentationName: self.INSTRUMENTATION_NAME,
9083
+ inputValue,
9084
+ isPreAppStart: false,
9085
+ stopRecordingChildSpans: true
9086
+ }, (spanInfo) => {
9087
+ return self._handleReplayDocumentWrite(spanInfo, inputValue);
9088
+ });
9089
+ }
9090
+ });
8847
9091
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
8848
9092
  originalFunctionCall: () => originalSet.call(this, data, options),
8849
9093
  recordModeHandler: ({ isPreAppStart }) => {
@@ -8876,21 +9120,32 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
8876
9120
  path: this.path,
8877
9121
  data: args.length === 1 ? args[0] : args
8878
9122
  };
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
- } });
9123
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
9124
+ noOpRequestHandler: () => {
9125
+ const now = Date.now();
9126
+ const emptyWriteResult = { writeTime: {
9127
+ seconds: Math.floor(now / 1e3),
9128
+ nanoseconds: now % 1e3 * 1e6
9129
+ } };
9130
+ return new TdFirestoreWriteResultMock(emptyWriteResult);
9131
+ },
9132
+ isServerRequest: false,
9133
+ replayModeHandler: () => {
9134
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalUpdate.apply(this, args), {
9135
+ name: "firestore.document.update",
9136
+ kind: __opentelemetry_api.SpanKind.CLIENT,
9137
+ submodule: "document",
9138
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
9139
+ packageName: PACKAGE_NAME,
9140
+ instrumentationName: self.INSTRUMENTATION_NAME,
9141
+ inputValue,
9142
+ isPreAppStart: false,
9143
+ stopRecordingChildSpans: true
9144
+ }, (spanInfo) => {
9145
+ return self._handleReplayDocumentWrite(spanInfo, inputValue);
9146
+ });
9147
+ }
9148
+ });
8894
9149
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
8895
9150
  originalFunctionCall: () => originalUpdate.apply(this, args),
8896
9151
  recordModeHandler: ({ isPreAppStart }) => {
@@ -8923,21 +9178,32 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
8923
9178
  path: this.path,
8924
9179
  options: precondition
8925
9180
  };
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
- } });
9181
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
9182
+ noOpRequestHandler: () => {
9183
+ const now = Date.now();
9184
+ const emptyWriteResult = { writeTime: {
9185
+ seconds: Math.floor(now / 1e3),
9186
+ nanoseconds: now % 1e3 * 1e6
9187
+ } };
9188
+ return new TdFirestoreWriteResultMock(emptyWriteResult);
9189
+ },
9190
+ isServerRequest: false,
9191
+ replayModeHandler: () => {
9192
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalDelete.call(this, precondition), {
9193
+ name: "firestore.document.delete",
9194
+ kind: __opentelemetry_api.SpanKind.CLIENT,
9195
+ submodule: "document",
9196
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
9197
+ packageName: PACKAGE_NAME,
9198
+ instrumentationName: self.INSTRUMENTATION_NAME,
9199
+ inputValue,
9200
+ isPreAppStart: false,
9201
+ stopRecordingChildSpans: true
9202
+ }, (spanInfo) => {
9203
+ return self._handleReplayDocumentWrite(spanInfo, inputValue);
9204
+ });
9205
+ }
9206
+ });
8941
9207
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
8942
9208
  originalFunctionCall: () => originalDelete.call(this, precondition),
8943
9209
  recordModeHandler: ({ isPreAppStart }) => {
@@ -8992,7 +9258,7 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
8992
9258
  });
8993
9259
  if (!mockData) {
8994
9260
  logger.warn(`[FirestoreInstrumentation] No mock data found for ${inputValue.operation}: ${inputValue.path}`);
8995
- return Promise.reject(/* @__PURE__ */ new Error("No mock data found"));
9261
+ throw new Error(`[FirestoreInstrumentation] No matching mock found for ${inputValue.operation}`);
8996
9262
  }
8997
9263
  const writeResult = mockData.result;
8998
9264
  return new TdFirestoreWriteResultMock(writeResult);
@@ -9006,21 +9272,31 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
9006
9272
  path: this.path,
9007
9273
  data
9008
9274
  };
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
- } });
9275
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
9276
+ noOpRequestHandler: () => {
9277
+ if (!this.originalCollectionDocFn) {
9278
+ logger.error(`[FirestoreInstrumentation] Original doc function not available`);
9279
+ return Promise.reject(/* @__PURE__ */ new Error("Original doc function not available"));
9280
+ }
9281
+ return this.originalCollectionDocFn.call(this, "");
9282
+ },
9283
+ isServerRequest: false,
9284
+ replayModeHandler: () => {
9285
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalAdd.call(this, data), {
9286
+ name: "firestore.collection.add",
9287
+ kind: __opentelemetry_api.SpanKind.CLIENT,
9288
+ submodule: "collection",
9289
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
9290
+ packageName: PACKAGE_NAME,
9291
+ instrumentationName: self.INSTRUMENTATION_NAME,
9292
+ inputValue,
9293
+ isPreAppStart: false,
9294
+ stopRecordingChildSpans: true
9295
+ }, (spanInfo) => {
9296
+ return self._handleReplayCollectionAdd(spanInfo, inputValue, this);
9297
+ });
9298
+ }
9299
+ });
9024
9300
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
9025
9301
  originalFunctionCall: () => originalAdd.call(this, data),
9026
9302
  recordModeHandler: ({ isPreAppStart }) => {
@@ -9075,7 +9351,7 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
9075
9351
  });
9076
9352
  if (!mockData) {
9077
9353
  logger.warn(`[FirestoreInstrumentation] No mock data found for collection.add: ${inputValue.path}`);
9078
- return Promise.reject(/* @__PURE__ */ new Error("No mock data found"));
9354
+ throw new Error(`[FirestoreInstrumentation] No matching mock found for collection.add`);
9079
9355
  }
9080
9356
  const recordedId = mockData.result.id;
9081
9357
  if (!this.originalCollectionDocFn) {
@@ -9094,42 +9370,48 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
9094
9370
  path: collectionPath,
9095
9371
  documentId: documentPath
9096
9372
  };
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
9373
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
9374
+ noOpRequestHandler: () => {
9375
+ return originalDoc.call(this, "");
9376
+ },
9377
+ isServerRequest: false,
9378
+ replayModeHandler: () => {
9379
+ return SpanUtils.createAndExecuteSpan(self.mode, () => documentPath ? originalDoc.call(this, documentPath) : originalDoc.call(this), {
9380
+ name: "firestore.collection.doc",
9381
+ kind: __opentelemetry_api.SpanKind.CLIENT,
9382
+ submodule: "collection",
9383
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
9384
+ packageName: PACKAGE_NAME,
9385
+ instrumentationName: self.INSTRUMENTATION_NAME,
9386
+ inputValue,
9387
+ isPreAppStart: false,
9388
+ stopRecordingChildSpans: true
9389
+ }, (spanInfo) => {
9390
+ const mockData = findMockResponseSync({
9391
+ mockRequestData: {
9392
+ traceId: spanInfo.traceId,
9393
+ spanId: spanInfo.spanId,
9394
+ name: "firestore.collection.doc",
9395
+ inputValue: createMockInputValue(inputValue),
9396
+ packageName: PACKAGE_NAME,
9397
+ instrumentationName: self.INSTRUMENTATION_NAME,
9398
+ submoduleName: "collection",
9399
+ kind: __opentelemetry_api.SpanKind.CLIENT
9400
+ },
9401
+ tuskDrift: self.tuskDrift
9402
+ });
9403
+ if (!mockData) {
9404
+ logger.warn(`[FirestoreInstrumentation] No mock data found for collection.doc: ${collectionPath}`);
9405
+ throw new Error(`[FirestoreInstrumentation] No matching mock found for collection.doc`);
9406
+ }
9407
+ const recordedId = mockData.result.id;
9408
+ logger.debug(`[FirestoreInstrumentation] replaying doc call with recorded id: ${recordedId}`);
9409
+ const docRef = originalDoc.call(this, recordedId);
9410
+ logger.debug(`[FirestoreInstrumentation] doc ref, id`, docRef, recordedId);
9411
+ return docRef;
9121
9412
  });
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
- } });
9413
+ }
9414
+ });
9133
9415
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
9134
9416
  originalFunctionCall: () => documentPath ? originalDoc.call(this, documentPath) : originalDoc.call(this),
9135
9417
  recordModeHandler: ({ isPreAppStart }) => {
@@ -9172,21 +9454,31 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
9172
9454
  operation: "query.get",
9173
9455
  path: this._queryOptions?.parentPath?.formattedName || "unknown"
9174
9456
  };
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
- } });
9457
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
9458
+ noOpRequestHandler: () => {
9459
+ return new TdFirestoreQueryMock({
9460
+ size: 0,
9461
+ empty: true,
9462
+ docs: []
9463
+ });
9464
+ },
9465
+ isServerRequest: false,
9466
+ replayModeHandler: () => {
9467
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalGet.call(this), {
9468
+ name: "firestore.query.get",
9469
+ kind: __opentelemetry_api.SpanKind.CLIENT,
9470
+ submodule: "query",
9471
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.FIRESTORE,
9472
+ packageName: PACKAGE_NAME,
9473
+ instrumentationName: self.INSTRUMENTATION_NAME,
9474
+ inputValue,
9475
+ isPreAppStart: false,
9476
+ stopRecordingChildSpans: true
9477
+ }, (spanInfo) => {
9478
+ return self._handleReplayQueryGet(spanInfo, inputValue);
9479
+ });
9480
+ }
9481
+ });
9190
9482
  else if (self.mode === TuskDriftMode.RECORD) return handleRecordMode({
9191
9483
  originalFunctionCall: () => originalGet.call(this),
9192
9484
  recordModeHandler: ({ isPreAppStart }) => {
@@ -9263,7 +9555,7 @@ var FirestoreInstrumentation = class extends TdInstrumentationBase {
9263
9555
  });
9264
9556
  if (!mockData) {
9265
9557
  logger.warn(`[FirestoreInstrumentation] No mock data found for query.get: ${inputValue.path}`);
9266
- return Promise.reject(/* @__PURE__ */ new Error("No mock data found"));
9558
+ throw new Error(`[FirestoreInstrumentation] No matching mock found for query.get`);
9267
9559
  }
9268
9560
  const queryResult = mockData.result;
9269
9561
  return new TdFirestoreQueryMock(queryResult);
@@ -9345,47 +9637,53 @@ var NextjsInstrumentation = class extends TdInstrumentationBase {
9345
9637
  const method = req.method || "GET";
9346
9638
  const url = req.url || "/";
9347
9639
  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,
9640
+ if (self.mode === TuskDriftMode.REPLAY) return handleReplayMode({
9641
+ noOpRequestHandler: () => {
9642
+ throw new Error(`[NextjsInstrumentation] Should never call noOpRequestHandler for server requests ${method} ${url}`);
9643
+ },
9644
+ isServerRequest: true,
9645
+ replayModeHandler: () => {
9646
+ const inputValue = {
9647
+ method,
9648
+ url,
9649
+ target: url,
9650
+ headers: self._normalizeHeaders(req.headers || {})
9651
+ };
9652
+ const replayTraceId = self.replayHooks.extractTraceIdFromHeaders(req);
9653
+ if (!replayTraceId) {
9654
+ logger.debug(`[NextjsInstrumentation] No trace ID found, calling original handler`);
9655
+ return originalHandleRequest.call(this, req, res, parsedUrl);
9656
+ }
9657
+ logger.debug(`[NextjsInstrumentation] Setting replay trace id`, replayTraceId);
9658
+ const envVars = self.replayHooks.extractEnvVarsFromHeaders(req);
9659
+ if (envVars) EnvVarTracker.setEnvVars(replayTraceId, envVars);
9660
+ const ctxWithReplayTraceId = SpanUtils.setCurrentReplayTraceId(replayTraceId);
9661
+ if (!ctxWithReplayTraceId) throw new Error("Error setting current replay trace id");
9662
+ return __opentelemetry_api.context.with(ctxWithReplayTraceId, () => {
9663
+ return SpanUtils.createAndExecuteSpan(self.mode, () => originalHandleRequest.call(this, req, res, parsedUrl), {
9664
+ name: url,
9665
+ kind: __opentelemetry_api.SpanKind.SERVER,
9666
+ packageName: "nextjs",
9667
+ submodule: method,
9668
+ packageType: __use_tusk_drift_schemas_core_span.PackageType.HTTP,
9669
+ instrumentationName: self.INSTRUMENTATION_NAME,
9383
9670
  inputValue,
9384
- thisContext: this
9671
+ inputSchemaMerges: { headers: { matchImportance: 0 } },
9672
+ isPreAppStart: false
9673
+ }, (spanInfo) => {
9674
+ return self._handleNextjsRequestInSpan({
9675
+ req,
9676
+ res,
9677
+ parsedUrl,
9678
+ originalHandleRequest,
9679
+ spanInfo,
9680
+ inputValue,
9681
+ thisContext: this
9682
+ });
9385
9683
  });
9386
9684
  });
9387
- });
9388
- } });
9685
+ }
9686
+ });
9389
9687
  else if (self.mode === TuskDriftMode.RECORD) {
9390
9688
  if (method.toUpperCase() === "OPTIONS" || !!req.headers["access-control-request-method"]) return originalHandleRequest.call(this, req, res, parsedUrl);
9391
9689
  logger.debug(`[NextjsInstrumentation] Creating server span for ${method} ${url}`);
@@ -12109,7 +12407,7 @@ var TdSpanExporter = class {
12109
12407
  logger.debug(`After filtering based on library name: ${filteredSpansBasedOnLibraryName.length} span(s) remaining`);
12110
12408
  const MAX_SPAN_SIZE_MB = 1;
12111
12409
  const MAX_SPAN_SIZE_BYTES = MAX_SPAN_SIZE_MB * 1024 * 1024;
12112
- const filteredSpansBasedOnSize = filteredSpansBasedOnLibraryName.filter((span) => {
12410
+ const filteredBlockedSpans = filteredSpansBasedOnLibraryName.filter((span) => {
12113
12411
  const traceId = span.spanContext().traceId;
12114
12412
  if (traceBlockingManager.isTraceBlocked(traceId)) {
12115
12413
  logger.debug(`Skipping span '${span.name}' (${span.spanContext().spanId}) - trace ${traceId} is blocked`);
@@ -12128,8 +12426,8 @@ var TdSpanExporter = class {
12128
12426
  }
12129
12427
  return true;
12130
12428
  });
12131
- logger.debug(`Filtered ${filteredSpansBasedOnLibraryName.length - filteredSpansBasedOnSize.length} oversized span(s), ${filteredSpansBasedOnSize.length} remaining`);
12132
- const cleanSpans = filteredSpansBasedOnSize.map((span) => SpanTransformer.transformSpanToCleanJSON(span));
12429
+ logger.debug(`Filtered ${filteredSpansBasedOnLibraryName.length - filteredBlockedSpans.length} blocked/oversized span(s), ${filteredBlockedSpans.length} remaining`);
12430
+ const cleanSpans = filteredBlockedSpans.map((span) => SpanTransformer.transformSpanToCleanJSON(span));
12133
12431
  if (this.adapters.length === 0) {
12134
12432
  logger.debug("No adapters configured");
12135
12433
  resultCallback({ code: import_src.ExportResultCode.SUCCESS });
@@ -12773,14 +13071,15 @@ var TuskDriftCore = class TuskDriftCore {
12773
13071
  sdkVersion: SDK_VERSION,
12774
13072
  sdkInstanceId: this.generateSdkInstanceId()
12775
13073
  });
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();
13074
+ new __opentelemetry_sdk_trace_node.NodeTracerProvider({
13075
+ resource: new __opentelemetry_resources.Resource({ [__opentelemetry_semantic_conventions.ATTR_SERVICE_NAME]: serviceName }),
13076
+ spanProcessors: [new __opentelemetry_sdk_trace_node.BatchSpanProcessor(this.spanExporter, {
13077
+ maxQueueSize: 2048,
13078
+ maxExportBatchSize: 512,
13079
+ scheduledDelayMillis: 2e3,
13080
+ exportTimeoutMillis: 3e4
13081
+ })]
13082
+ }).register();
12784
13083
  logger.debug(`OpenTelemetry tracing initialized`);
12785
13084
  }
12786
13085
  generateSdkInstanceId() {