flow-debugger 1.0.0
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/PORTFOLIO_README_SECTION.md +177 -0
- package/README.md +251 -0
- package/dashboard/app.js +339 -0
- package/dashboard/index.html +168 -0
- package/dashboard/style.css +846 -0
- package/dist/cjs/core/Analytics.js +174 -0
- package/dist/cjs/core/Analytics.js.map +1 -0
- package/dist/cjs/core/Classifier.js +66 -0
- package/dist/cjs/core/Classifier.js.map +1 -0
- package/dist/cjs/core/HealthMonitor.js +79 -0
- package/dist/cjs/core/HealthMonitor.js.map +1 -0
- package/dist/cjs/core/RootCause.js +89 -0
- package/dist/cjs/core/RootCause.js.map +1 -0
- package/dist/cjs/core/Sampler.js +34 -0
- package/dist/cjs/core/Sampler.js.map +1 -0
- package/dist/cjs/core/Timeline.js +90 -0
- package/dist/cjs/core/Timeline.js.map +1 -0
- package/dist/cjs/core/TraceEngine.js +222 -0
- package/dist/cjs/core/TraceEngine.js.map +1 -0
- package/dist/cjs/core/types.js +21 -0
- package/dist/cjs/core/types.js.map +1 -0
- package/dist/cjs/index.js +46 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/integrations/axios.js +136 -0
- package/dist/cjs/integrations/axios.js.map +1 -0
- package/dist/cjs/integrations/fetch.js +153 -0
- package/dist/cjs/integrations/fetch.js.map +1 -0
- package/dist/cjs/integrations/mongo.js +111 -0
- package/dist/cjs/integrations/mongo.js.map +1 -0
- package/dist/cjs/integrations/mysql.js +212 -0
- package/dist/cjs/integrations/mysql.js.map +1 -0
- package/dist/cjs/integrations/postgres.js +182 -0
- package/dist/cjs/integrations/postgres.js.map +1 -0
- package/dist/cjs/integrations/redis.js +105 -0
- package/dist/cjs/integrations/redis.js.map +1 -0
- package/dist/cjs/middleware/express.js +255 -0
- package/dist/cjs/middleware/express.js.map +1 -0
- package/dist/esm/core/Analytics.js +170 -0
- package/dist/esm/core/Analytics.js.map +1 -0
- package/dist/esm/core/Classifier.js +61 -0
- package/dist/esm/core/Classifier.js.map +1 -0
- package/dist/esm/core/HealthMonitor.js +75 -0
- package/dist/esm/core/HealthMonitor.js.map +1 -0
- package/dist/esm/core/RootCause.js +86 -0
- package/dist/esm/core/RootCause.js.map +1 -0
- package/dist/esm/core/Sampler.js +30 -0
- package/dist/esm/core/Sampler.js.map +1 -0
- package/dist/esm/core/Timeline.js +86 -0
- package/dist/esm/core/Timeline.js.map +1 -0
- package/dist/esm/core/TraceEngine.js +217 -0
- package/dist/esm/core/TraceEngine.js.map +1 -0
- package/dist/esm/core/types.js +18 -0
- package/dist/esm/core/types.js.map +1 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/integrations/axios.js +133 -0
- package/dist/esm/integrations/axios.js.map +1 -0
- package/dist/esm/integrations/fetch.js +149 -0
- package/dist/esm/integrations/fetch.js.map +1 -0
- package/dist/esm/integrations/mongo.js +107 -0
- package/dist/esm/integrations/mongo.js.map +1 -0
- package/dist/esm/integrations/mysql.js +209 -0
- package/dist/esm/integrations/mysql.js.map +1 -0
- package/dist/esm/integrations/postgres.js +179 -0
- package/dist/esm/integrations/postgres.js.map +1 -0
- package/dist/esm/integrations/redis.js +102 -0
- package/dist/esm/integrations/redis.js.map +1 -0
- package/dist/esm/middleware/express.js +219 -0
- package/dist/esm/middleware/express.js.map +1 -0
- package/dist/types/core/Analytics.d.ts +35 -0
- package/dist/types/core/Analytics.d.ts.map +1 -0
- package/dist/types/core/Classifier.d.ts +21 -0
- package/dist/types/core/Classifier.d.ts.map +1 -0
- package/dist/types/core/HealthMonitor.d.ts +14 -0
- package/dist/types/core/HealthMonitor.d.ts.map +1 -0
- package/dist/types/core/RootCause.d.ts +12 -0
- package/dist/types/core/RootCause.d.ts.map +1 -0
- package/dist/types/core/Sampler.d.ts +13 -0
- package/dist/types/core/Sampler.d.ts.map +1 -0
- package/dist/types/core/Timeline.d.ts +22 -0
- package/dist/types/core/Timeline.d.ts.map +1 -0
- package/dist/types/core/TraceEngine.d.ts +47 -0
- package/dist/types/core/TraceEngine.d.ts.map +1 -0
- package/dist/types/core/types.d.ts +118 -0
- package/dist/types/core/types.d.ts.map +1 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/integrations/axios.d.ts +22 -0
- package/dist/types/integrations/axios.d.ts.map +1 -0
- package/dist/types/integrations/fetch.d.ts +25 -0
- package/dist/types/integrations/fetch.d.ts.map +1 -0
- package/dist/types/integrations/mongo.d.ts +26 -0
- package/dist/types/integrations/mongo.d.ts.map +1 -0
- package/dist/types/integrations/mysql.d.ts +20 -0
- package/dist/types/integrations/mysql.d.ts.map +1 -0
- package/dist/types/integrations/postgres.d.ts +20 -0
- package/dist/types/integrations/postgres.d.ts.map +1 -0
- package/dist/types/integrations/redis.d.ts +20 -0
- package/dist/types/integrations/redis.d.ts.map +1 -0
- package/dist/types/middleware/express.d.ts +39 -0
- package/dist/types/middleware/express.d.ts.map +1 -0
- package/example/server.ts +234 -0
- package/jest.config.js +8 -0
- package/package.json +110 -0
- package/portfolio-repo/APIRESPONSE DASH.png +0 -0
- package/portfolio-repo/PAYLOAD.png +0 -0
- package/portfolio-repo/README.md +182 -0
- package/src/core/Analytics.ts +209 -0
- package/src/core/Classifier.ts +82 -0
- package/src/core/HealthMonitor.ts +92 -0
- package/src/core/RootCause.ts +105 -0
- package/src/core/Sampler.ts +35 -0
- package/src/core/Timeline.ts +108 -0
- package/src/core/TraceEngine.ts +266 -0
- package/src/core/types.ts +170 -0
- package/src/index.ts +42 -0
- package/src/integrations/axios.ts +164 -0
- package/src/integrations/fetch.ts +172 -0
- package/src/integrations/mongo.ts +130 -0
- package/src/integrations/mysql.ts +239 -0
- package/src/integrations/postgres.ts +217 -0
- package/src/integrations/redis.ts +122 -0
- package/src/middleware/express.ts +264 -0
- package/tests/Analytics.test.ts +136 -0
- package/tests/Classifier.test.ts +57 -0
- package/tests/RootCause.test.ts +69 -0
- package/tests/TraceEngine.test.ts +110 -0
- package/tsconfig.cjs.json +9 -0
- package/tsconfig.esm.json +9 -0
- package/tsconfig.json +31 -0
- package/tsconfig.types.json +8 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Flow Debugger - Portfolio README Section
|
|
2
|
+
|
|
3
|
+
Copy this section and add it to your portfolio README at:
|
|
4
|
+
https://github.com/sannuk79/PROJECTS-AND-NPM-PACKAGES-
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
### 🔍 3. Flow Debugger
|
|
9
|
+
**Production-safe request tracing with root cause detection and live analytics dashboard.**
|
|
10
|
+
|
|
11
|
+
[](https://www.npmjs.com/package/flow-debugger)
|
|
12
|
+
[](https://github.com/sannuk79/debugerpackages)
|
|
13
|
+
[](https://www.npmjs.com/package/flow-debugger)
|
|
14
|
+
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
### 🔄 Architecture Overview
|
|
18
|
+
```mermaid
|
|
19
|
+
graph LR
|
|
20
|
+
A[Request] --> B[Generate TraceID]
|
|
21
|
+
B --> C[Step-by-Step Tracking]
|
|
22
|
+
C --> D[Auto-Classify: INFO/WARN/ERROR/CRITICAL]
|
|
23
|
+
D --> E[Root Cause Detection]
|
|
24
|
+
E --> F[Analytics Dashboard]
|
|
25
|
+
F --> G[Search & Filter]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### ✨ Key Features
|
|
29
|
+
|
|
30
|
+
**Auto-Instrumentation (Zero Code Changes):**
|
|
31
|
+
- ✅ MongoDB, MySQL, PostgreSQL, Redis
|
|
32
|
+
- ✅ Fetch API, Axios
|
|
33
|
+
- ✅ Express middleware
|
|
34
|
+
|
|
35
|
+
**External API Tracing:**
|
|
36
|
+
- 🔵 Stripe API auto-tagged
|
|
37
|
+
- 🟢 Razorpay API auto-tagged
|
|
38
|
+
- 🟡 SendGrid API auto-tagged
|
|
39
|
+
- 🟣 Twilio API auto-tagged
|
|
40
|
+
|
|
41
|
+
**Advanced Debugging:**
|
|
42
|
+
- 🎯 **Root Cause Detection**: Timeout → Failure → Slow bottleneck algorithm
|
|
43
|
+
- 📄 **Error Stack Preview**: Shows `errorFile:line` in dashboard (e.g., `auth.service.ts:42`)
|
|
44
|
+
- 📦 **Payload Size Detection**: Warns on large payloads (>1MB) slowing requests
|
|
45
|
+
- 🌍 **Environment Tagging**: Filter traces by dev/staging/production
|
|
46
|
+
- 🔍 **Trace Search**: Search by traceId, endpoint, error message
|
|
47
|
+
- 📊 **Live Dashboard**: Real-time analytics at `/__debugger/dashboard`
|
|
48
|
+
|
|
49
|
+
**Production-Safe:**
|
|
50
|
+
- ⚡ Never blocks requests
|
|
51
|
+
- 🛡️ All code wrapped in try/catch
|
|
52
|
+
- 🚀 <1ms overhead per request
|
|
53
|
+
|
|
54
|
+
### 📈 Performance Metrics
|
|
55
|
+
|
|
56
|
+
**Load Testing Results:**
|
|
57
|
+
```
|
|
58
|
+
✅ 56,000 requests in 10 seconds
|
|
59
|
+
✅ 100 concurrent connections
|
|
60
|
+
✅ 5,600 req/sec throughput
|
|
61
|
+
✅ <1ms average overhead
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Test Coverage:**
|
|
65
|
+
```
|
|
66
|
+
✅ 30/30 tests passing
|
|
67
|
+
✅ CJS, ESM, TypeScript builds
|
|
68
|
+
✅ Production-tested
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 🚀 Quick Start
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npm install flow-debugger
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
const express = require('express');
|
|
79
|
+
const { flowDebugger, fetchTracer, axiosTracer } = require('flow-debugger');
|
|
80
|
+
const axios = require('axios');
|
|
81
|
+
|
|
82
|
+
const app = express();
|
|
83
|
+
app.use(express.json());
|
|
84
|
+
|
|
85
|
+
// Initialize with environment
|
|
86
|
+
const debugger_ = flowDebugger({
|
|
87
|
+
environment: 'production',
|
|
88
|
+
slowThreshold: 300,
|
|
89
|
+
largePayloadThreshold: 1024 * 1024, // 1MB
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
app.use(debugger_.middleware);
|
|
93
|
+
|
|
94
|
+
// Auto-trace external APIs
|
|
95
|
+
fetchTracer({ getTracer: debugger_.getTracer });
|
|
96
|
+
axiosTracer(axios, { getTracer: debugger_.getTracer });
|
|
97
|
+
|
|
98
|
+
// Your routes...
|
|
99
|
+
app.get('/api/users', async (req, res) => {
|
|
100
|
+
// All database calls, API calls automatically traced
|
|
101
|
+
const users = await User.find();
|
|
102
|
+
res.json(users);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
app.listen(3000);
|
|
106
|
+
// Dashboard: http://localhost:3000/__debugger/dashboard
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 🎯 Real Production Use Cases
|
|
110
|
+
|
|
111
|
+
**1. Payment Gateway Failures**
|
|
112
|
+
```
|
|
113
|
+
🔍 Root Cause: Stripe API timed out after 2000ms
|
|
114
|
+
Service: stripe | Confidence: high
|
|
115
|
+
📄 payment.service.ts:89
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**2. Large Payload Slowdown**
|
|
119
|
+
```
|
|
120
|
+
POST /api/upload 📦 5.2MB WARN 1200ms
|
|
121
|
+
Root Cause: Large payload (5.2MB) slowed JSON parsing
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**3. Environment-Specific Bugs**
|
|
125
|
+
```
|
|
126
|
+
Search: "redis" | Environment: production
|
|
127
|
+
Found 12 results — all showing ECONNREFUSED in production only
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**4. Service Failure Breakdown**
|
|
131
|
+
```
|
|
132
|
+
Top Failures:
|
|
133
|
+
Stripe API 42%
|
|
134
|
+
Redis 33%
|
|
135
|
+
PostgreSQL 12%
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### 📊 Dashboard Features
|
|
139
|
+
|
|
140
|
+
- **Real-time Monitoring**: Live request traces with auto-refresh
|
|
141
|
+
- **Service Health**: Track MongoDB, MySQL, PostgreSQL, Redis, external APIs
|
|
142
|
+
- **Endpoint Analytics**: Avg/P95/Max latency, error rates, slow query detection
|
|
143
|
+
- **Search & Filter**: Find traces by ID, endpoint, error message, environment
|
|
144
|
+
- **Root Cause Detection**: Automatic identification of failure origins
|
|
145
|
+
- **Error Stack Preview**: Direct file:line references for debugging
|
|
146
|
+
|
|
147
|
+
### 🔗 Links
|
|
148
|
+
|
|
149
|
+
**[View on NPM](https://www.npmjs.com/package/flow-debugger)** | **[Source Code](https://github.com/sannuk79/debugerpackages)** | **[Documentation](https://github.com/sannuk79/debugerpackages#readme)**
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Combined Usage Example
|
|
154
|
+
|
|
155
|
+
Build a hardened, monitored, and debuggable API with all three packages:
|
|
156
|
+
|
|
157
|
+
```javascript
|
|
158
|
+
const { apiMonitor } = require('@sannuk792/api-response-monitor');
|
|
159
|
+
const { guard } = require('payload-guard-filter');
|
|
160
|
+
const { flowDebugger } = require('flow-debugger');
|
|
161
|
+
|
|
162
|
+
const debugger_ = flowDebugger({ environment: 'production' });
|
|
163
|
+
|
|
164
|
+
app.use(apiMonitor({ mode: 'minimal' })); // Global Monitoring
|
|
165
|
+
app.use(debugger_.middleware); // Request Tracing
|
|
166
|
+
|
|
167
|
+
app.post('/api/secure-data', (req, res) => {
|
|
168
|
+
const safeBody = userShape(req.body); // Precise Filtering
|
|
169
|
+
res.json(safeBody);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// Dashboards:
|
|
173
|
+
// - API Monitor: http://localhost:3000/__monitor
|
|
174
|
+
// - Flow Debugger: http://localhost:3000/__debugger/dashboard
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
package/README.md
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
# 🔍 flow-debugger
|
|
2
|
+
|
|
3
|
+
**Production-safe flow-level debugging SDK for Node.js, Web, and React Native.**
|
|
4
|
+
|
|
5
|
+
Traces requests step-by-step, measures timing, classifies errors, detects root causes, and provides endpoint analytics with a live dashboard.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## ✨ Features
|
|
10
|
+
|
|
11
|
+
- **Request Tracing** — Every request gets a unique `traceId` with step-by-step timing
|
|
12
|
+
- **Auto-Instrument** — MongoDB, MySQL, PostgreSQL, Redis — zero extra code needed
|
|
13
|
+
- **Root Cause Detection** — Automatically identifies why a request failed or was slow
|
|
14
|
+
- **Error Classification** — `INFO` / `WARN` / `ERROR` / `CRITICAL` auto-categorization
|
|
15
|
+
- **Timeout Detection** — Catches hanging queries/operations with configurable timeouts
|
|
16
|
+
- **Slow Query Detection** — Flags slow SQL/NoSQL queries with threshold alerts
|
|
17
|
+
- **Endpoint Analytics** — Per-route stats: requests, errors, slow, avg/p95/max latency
|
|
18
|
+
- **Service Health Monitor** — Real-time dependency health: `Redis: healthy`, `Mongo: degraded`
|
|
19
|
+
- **Live Dashboard** — Beautiful analytics UI at `/__debugger/dashboard`
|
|
20
|
+
- **Console Timeline** — Visual request timeline directly in your terminal
|
|
21
|
+
- **Production-Safe** — Never blocks requests, never crashes your app, all try/catch wrapped
|
|
22
|
+
- **Sampling** — Configurable sampling rate for high-traffic environments
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 📦 Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install flow-debugger
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 🚀 Quick Start (Express)
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import express from 'express';
|
|
38
|
+
import { flowDebugger, mongoTracer, mysqlTracer, pgTracer, redisTracer } from 'flow-debugger';
|
|
39
|
+
|
|
40
|
+
const app = express();
|
|
41
|
+
|
|
42
|
+
// 1. Initialize debugger
|
|
43
|
+
const debug = flowDebugger({
|
|
44
|
+
slowThreshold: 300, // ms — mark steps as slow
|
|
45
|
+
slowQueryThreshold: 300, // ms — flag slow DB queries
|
|
46
|
+
enableDashboard: true, // serve /__debugger/dashboard
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
app.use(debug.middleware);
|
|
50
|
+
|
|
51
|
+
// 2. Auto-instrument databases (optional — zero code tracing!)
|
|
52
|
+
mongoTracer(mongoose, { getTracer: debug.getTracer });
|
|
53
|
+
mysqlTracer(mysqlPool, { getTracer: debug.getTracer });
|
|
54
|
+
pgTracer(pgPool, { getTracer: debug.getTracer });
|
|
55
|
+
redisTracer(redisClient, { getTracer: debug.getTracer });
|
|
56
|
+
|
|
57
|
+
// 3. Use manual steps in your routes
|
|
58
|
+
app.post('/api/login', async (req, res) => {
|
|
59
|
+
const tracer = req.tracer;
|
|
60
|
+
|
|
61
|
+
const user = await tracer.step('DB find user', async () => {
|
|
62
|
+
return User.findOne({ email: req.body.email });
|
|
63
|
+
}, { service: 'mongo' });
|
|
64
|
+
|
|
65
|
+
await tracer.step('Redis cache session', async () => {
|
|
66
|
+
return redis.set(`session:${user.id}`, JSON.stringify(user));
|
|
67
|
+
}, { service: 'redis' });
|
|
68
|
+
|
|
69
|
+
const token = await tracer.step('JWT generate', async () => {
|
|
70
|
+
return jwt.sign({ id: user.id }, SECRET);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
res.json({ token, user });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
app.listen(3000);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Console Output:
|
|
80
|
+
```
|
|
81
|
+
┌─── flow-debugger ── req_m3k2_abc123_1 ── POST /api/login ───
|
|
82
|
+
│ [0ms] Request start
|
|
83
|
+
│ [2ms] DB find user ✔ (14ms) [mongo]
|
|
84
|
+
│ [16ms] Redis cache session ✔ (3ms) [redis]
|
|
85
|
+
│ [20ms] JWT generate ✔ (1ms)
|
|
86
|
+
│ [21ms] Response 200
|
|
87
|
+
│
|
|
88
|
+
│ Classification: INFO
|
|
89
|
+
│ Total: 21ms
|
|
90
|
+
└──────────────────────────────────────────────────────
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## 🧩 Auto-Instrument (Zero Code Tracing)
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { mongoTracer, mysqlTracer, pgTracer, redisTracer } from 'flow-debugger';
|
|
99
|
+
|
|
100
|
+
// Mongoose — patches Query.prototype.exec
|
|
101
|
+
mongoTracer(mongoose, { getTracer: debug.getTracer });
|
|
102
|
+
|
|
103
|
+
// mysql2 — patches pool.query() and pool.execute()
|
|
104
|
+
mysqlTracer(pool, { getTracer: debug.getTracer });
|
|
105
|
+
|
|
106
|
+
// pg — patches pool.query() and client.query()
|
|
107
|
+
pgTracer(pgPool, { getTracer: debug.getTracer });
|
|
108
|
+
|
|
109
|
+
// Redis — wraps get, set, del, hget, etc.
|
|
110
|
+
redisTracer(redisClient, { getTracer: debug.getTracer });
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Auto output (no extra code needed):**
|
|
114
|
+
```
|
|
115
|
+
MySQL SELECT users → 12ms ✔
|
|
116
|
+
Postgres SELECT orders → 18ms ✔
|
|
117
|
+
Redis SET session → 3ms ✔
|
|
118
|
+
Mongo users.findOne → 22ms ✔
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## ⏱ Timeout Detection
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
await tracer.step('DB query', async () => {
|
|
127
|
+
return db.query('SELECT * FROM orders');
|
|
128
|
+
}, { service: 'postgres', timeout: 2000 });
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
If the query takes >2s:
|
|
132
|
+
```
|
|
133
|
+
CRITICAL: DB query timed out after 2000ms
|
|
134
|
+
Root cause: DB timeout
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## 🏷 Dependency Tagging
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
await tracer.step('Cache lookup', fn, { service: 'redis' });
|
|
143
|
+
await tracer.step('User query', fn, { service: 'postgres' });
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Dashboard grouping:
|
|
147
|
+
```
|
|
148
|
+
Top failures:
|
|
149
|
+
Redis 42%
|
|
150
|
+
Postgres 33%
|
|
151
|
+
External 12%
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## 📊 Dashboard
|
|
157
|
+
|
|
158
|
+
Access the live analytics dashboard at:
|
|
159
|
+
```
|
|
160
|
+
http://localhost:3000/__debugger/dashboard
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### API Endpoints:
|
|
164
|
+
| Route | Description |
|
|
165
|
+
|---|---|
|
|
166
|
+
| `GET /__debugger` | Full analytics JSON |
|
|
167
|
+
| `GET /__debugger/dashboard` | Live HTML dashboard |
|
|
168
|
+
| `GET /__debugger/health` | Service health status |
|
|
169
|
+
| `GET /__debugger/endpoint?path=/api/login` | Per-endpoint stats |
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## ⚙️ Configuration
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
flowDebugger({
|
|
177
|
+
enabled: true, // Enable/disable debugger
|
|
178
|
+
slowThreshold: 300, // ms — slow step threshold
|
|
179
|
+
slowQueryThreshold: 300, // ms — slow query threshold
|
|
180
|
+
defaultTimeout: 30000, // ms — default step timeout
|
|
181
|
+
samplingRate: 1, // 0-1 (1 = 100%)
|
|
182
|
+
alwaysSampleErrors: true, // Always trace errors even if sampled out
|
|
183
|
+
maxTraces: 1000, // Max traces in memory
|
|
184
|
+
enableTimeline: true, // Console timeline output
|
|
185
|
+
enableDashboard: true, // Serve /__debugger routes
|
|
186
|
+
logger: console.log, // Custom logger function
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## 🔍 Root Cause Detection
|
|
193
|
+
|
|
194
|
+
The package automatically identifies the most likely cause of failures:
|
|
195
|
+
|
|
196
|
+
| Scenario | Root Cause |
|
|
197
|
+
|---|---|
|
|
198
|
+
| Response 500 + Redis failed | `Redis GET failed: connection refused` |
|
|
199
|
+
| DB query 900ms + total latency high | `Slow PostgreSQL query: SELECT orders (900ms)` |
|
|
200
|
+
| Step timeout after 2s | `Payment API timed out after 2000ms` |
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## 📡 Subpath Imports
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
// Only import what you need
|
|
208
|
+
import { flowDebugger } from 'flow-debugger/express';
|
|
209
|
+
import { mongoTracer } from 'flow-debugger/mongo';
|
|
210
|
+
import { mysqlTracer } from 'flow-debugger/mysql';
|
|
211
|
+
import { pgTracer } from 'flow-debugger/postgres';
|
|
212
|
+
import { redisTracer } from 'flow-debugger/redis';
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## 🏗 Architecture
|
|
218
|
+
|
|
219
|
+
```
|
|
220
|
+
core/
|
|
221
|
+
TraceEngine — request trace lifecycle
|
|
222
|
+
Classifier — INFO/WARN/ERROR/CRITICAL
|
|
223
|
+
RootCause — failure origin detection
|
|
224
|
+
Analytics — endpoint-level aggregation
|
|
225
|
+
HealthMonitor — dependency health tracking
|
|
226
|
+
Timeline — console renderer
|
|
227
|
+
|
|
228
|
+
integrations/
|
|
229
|
+
mongo — Mongoose auto-tracing
|
|
230
|
+
mysql — mysql2 auto-tracing
|
|
231
|
+
postgres — pg auto-tracing
|
|
232
|
+
redis — Redis auto-tracing
|
|
233
|
+
|
|
234
|
+
middleware/
|
|
235
|
+
express — Express middleware + dashboard
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## 🛡 Production Rules
|
|
241
|
+
|
|
242
|
+
1. **Debugger never blocks requests** — all logic is async & non-blocking
|
|
243
|
+
2. **Debugger never crashes your app** — every operation is try/catch wrapped
|
|
244
|
+
3. **Use sampling in high traffic** — set `samplingRate: 0.1` for 10% sampling
|
|
245
|
+
4. **Errors always get traced** — even when sampling drops a request
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## 📄 License
|
|
250
|
+
|
|
251
|
+
MIT
|