MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / slowResponseTracker

Function slowResponseTracker

server/src/middleware/slow-response.ts:78–106  ·  view source on GitHub ↗
(req: Request, res: Response, next: NextFunction)

Source from the content-addressed store, hash-verified

76 * Only tracks /api/* paths to avoid noise from static assets.
77 */
78export function slowResponseTracker(req: Request, res: Response, next: NextFunction): void {
79 if (!req.path.startsWith("/api/")) {
80 return next();
81 }
82
83 const start = process.hrtime.bigint();
84
85 res.on("finish", () => {
86 const durationMs = Number(process.hrtime.bigint() - start) / 1e6;
87
88 if (durationMs > WARN_THRESHOLD_MS) {
89 logger.warn(
90 {
91 method: req.method,
92 path: req.path.slice(0, 200),
93 status: res.statusCode,
94 duration_ms: Math.round(durationMs),
95 },
96 "Slow API response"
97 );
98
99 if (durationMs > ALERT_THRESHOLD_MS && shouldAlert(normalizeAlertKey(req.method, req.path))) {
100 notifySlack(req.method, req.path, durationMs, res.statusCode);
101 }
102 }
103 });
104
105 next();
106}

Callers

nothing calls this directly

Calls 4

shouldAlertFunction · 0.85
normalizeAlertKeyFunction · 0.85
warnMethod · 0.80
notifySlackFunction · 0.70

Tested by

no test coverage detected