ai-perf-sdk 1.0.5 → 1.0.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-perf-sdk",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Plug-and-play custom performance monitoring SDK",
5
5
  "license": "MIT",
6
6
  "author": "Akash",
package/src/batcher.js CHANGED
@@ -43,7 +43,7 @@ async function flush() {
43
43
  }
44
44
 
45
45
  const payload = queue.splice(0, queue.length);
46
- console.log(`[AI-PERF-SDK] Flushing ${payload.length} items...`);
46
+ console.log(`[AI-PERF-SDK] 🚀 Flushing ${payload.length} items to ${config.endpoint}...`);
47
47
 
48
48
  try {
49
49
  await sendBatch({
@@ -51,8 +51,9 @@ async function flush() {
51
51
  headers: config.headers,
52
52
  payload: payload
53
53
  });
54
+ console.log(`[AI-PERF-SDK] ✅ Batch delivered successfully.`);
54
55
  } catch (err) {
55
- console.error("[AI-PERF-SDK] Flush failed. Returning items to queue.");
56
+ console.error("[AI-PERF-SDK] Flush failed. Returning items to queue.");
56
57
  queue.unshift(...payload);
57
58
  }
58
59
  }
package/src/instrument.js CHANGED
@@ -99,7 +99,36 @@ function instrumentHttp() {
99
99
  req.end();
100
100
  return req;
101
101
  };
102
+
103
+ // --- Inbound Request (Server) Patching (PROTOTYPE METHOD) ---
104
+ const originalEmit = module.Server.prototype.emit;
105
+ module.Server.prototype.emit = function (event, req, res) {
106
+ if (event === 'request' && req && res) {
107
+ console.log(`[AI-PERF-SDK] Inbound Intercepted: ${req.method} ${req.url}`);
108
+ const start = performance.now();
109
+ const url = req.url;
110
+ const method = req.method;
111
+
112
+ // Ignore telemetry calls
113
+ if (url && !url.includes('/api/telemetry')) {
114
+ res.on('finish', () => {
115
+ const duration = performance.now() - start;
116
+ enqueue({
117
+ type: "http-inbound",
118
+ url: url,
119
+ method: method,
120
+ duration: Math.round(duration),
121
+ status: res.statusCode,
122
+ timestamp: new Date().toISOString()
123
+ });
124
+ });
125
+ }
126
+ }
127
+ return originalEmit.apply(this, arguments);
128
+ };
102
129
  });
103
130
  }
104
131
 
132
+
105
133
  module.exports = { instrumentHttp };
134
+