ai-perf-sdk 1.0.5 → 1.0.6

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/instrument.js +30 -0
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.6",
4
4
  "description": "Plug-and-play custom performance monitoring SDK",
5
5
  "license": "MIT",
6
6
  "author": "Akash",
package/src/instrument.js CHANGED
@@ -99,7 +99,37 @@ function instrumentHttp() {
99
99
  req.end();
100
100
  return req;
101
101
  };
102
+
103
+ // --- Inbound Request (Server) Patching ---
104
+ const originalCreateServer = module.createServer;
105
+ module.createServer = function () {
106
+ const server = originalCreateServer.apply(this, arguments);
107
+
108
+ server.on('request', (req, res) => {
109
+ const start = performance.now();
110
+ const url = req.url;
111
+ const method = req.method;
112
+
113
+ // Ignore telemetry calls
114
+ if (url.includes('/api/telemetry')) return;
115
+
116
+ res.on('finish', () => {
117
+ const duration = performance.now() - start;
118
+ enqueue({
119
+ type: "http-inbound",
120
+ url: url,
121
+ method: method,
122
+ duration: Math.round(duration),
123
+ status: res.statusCode,
124
+ timestamp: new Date().toISOString()
125
+ });
126
+ });
127
+ });
128
+
129
+ return server;
130
+ };
102
131
  });
103
132
  }
104
133
 
105
134
  module.exports = { instrumentHttp };
135
+