flow-debugger 1.9.3 → 1.9.5
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/EXAMPLES.md +38 -0
- package/README.md +391 -266
- package/bin/cli.js +1 -1
- package/dist/cjs/index.js +10 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/react_native.js +308 -0
- package/dist/cjs/react_native.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/react_native.js +298 -0
- package/dist/esm/react_native.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/react_native.d.ts +54 -0
- package/dist/types/react_native.d.ts.map +1 -0
- package/package.json +126 -121
- package/python-sdk/fastapi_middleware.py +217 -0
package/README.md
CHANGED
|
@@ -1,266 +1,391 @@
|
|
|
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
|
-

|
|
10
|
-
---
|
|
11
|
-

|
|
12
|
-
---
|
|
13
|
-
## 🚀 Easy 3-Line Setup (Beginner Friendly)
|
|
14
|
-
Beginners can get a professional dashboard and request tracing with just **3 lines of code**:
|
|
15
|
-
|
|
16
|
-
```typescript
|
|
17
|
-
const debug = flowDebugger({ enableDashboard: true }); // 1. Init
|
|
18
|
-
app.use(debug.middleware); // 2. Middleware
|
|
19
|
-
mongoTracer(mongoose, { getTracer: debug.getTracer }); // 3. Auto-Trace
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
## ✨ Features
|
|
25
|
-
|
|
26
|
-
- **Request Tracing** — Every request gets a unique `traceId` with step-by-step timing
|
|
27
|
-
- **Auto-Instrument** — MongoDB, MySQL, PostgreSQL, Redis — zero extra code needed
|
|
28
|
-
- **Root Cause Detection** — Automatically identifies why a request failed or was slow
|
|
29
|
-
- **Error Classification** — `INFO` / `WARN` / `ERROR` / `CRITICAL` auto-categorization
|
|
30
|
-
- **Timeout Detection** — Catches hanging queries/operations with configurable timeouts
|
|
31
|
-
- **Slow Query Detection** — Flags slow SQL/NoSQL queries with threshold alerts
|
|
32
|
-
- **Endpoint Analytics** — Per-route stats: requests, errors, slow, avg/p95/max latency
|
|
33
|
-
- **Service Health Monitor** — Real-time dependency health: `Redis: healthy`, `Mongo: degraded`
|
|
34
|
-
- **Live Dashboard** — Beautiful analytics UI at `/__debugger/dashboard`
|
|
35
|
-
- **Console Timeline** — Visual request timeline directly in your terminal
|
|
36
|
-
- **Production-Safe** — Never blocks requests, never crashes your app, all try/catch wrapped
|
|
37
|
-
- **Sampling** — Configurable sampling rate for high-traffic environments
|
|
38
|
-
|
|
39
|
-
---
|
|
40
|
-
|
|
41
|
-
## 📦 Installation
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
npm install flow-debugger
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
---
|
|
48
|
-
|
|
49
|
-
## 🚀 Quick Start (Express)
|
|
50
|
-
|
|
51
|
-
```typescript
|
|
52
|
-
import express from 'express';
|
|
53
|
-
import { flowDebugger, mongoTracer, mysqlTracer, pgTracer, redisTracer } from 'flow-debugger';
|
|
54
|
-
|
|
55
|
-
const app = express();
|
|
56
|
-
|
|
57
|
-
// 1. Initialize debugger
|
|
58
|
-
const debug = flowDebugger({
|
|
59
|
-
slowThreshold: 300, // ms — mark steps as slow
|
|
60
|
-
slowQueryThreshold: 300, // ms — flag slow DB queries
|
|
61
|
-
enableDashboard: true, // serve /__debugger/dashboard
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
app.use(debug.middleware);
|
|
65
|
-
|
|
66
|
-
// 2. Auto-instrument databases (optional — zero code tracing!)
|
|
67
|
-
mongoTracer(mongoose, { getTracer: debug.getTracer });
|
|
68
|
-
mysqlTracer(mysqlPool, { getTracer: debug.getTracer });
|
|
69
|
-
pgTracer(pgPool, { getTracer: debug.getTracer });
|
|
70
|
-
redisTracer(redisClient, { getTracer: debug.getTracer });
|
|
71
|
-
|
|
72
|
-
// 3. Use manual steps in your routes
|
|
73
|
-
app.post('/api/login', async (req, res) => {
|
|
74
|
-
const tracer = req.tracer;
|
|
75
|
-
|
|
76
|
-
const user = await tracer.step('DB find user', async () => {
|
|
77
|
-
return User.findOne({ email: req.body.email });
|
|
78
|
-
}, { service: 'mongo' });
|
|
79
|
-
|
|
80
|
-
await tracer.step('Redis cache session', async () => {
|
|
81
|
-
return redis.set(`session:${user.id}`, JSON.stringify(user));
|
|
82
|
-
}, { service: 'redis' });
|
|
83
|
-
|
|
84
|
-
const token = await tracer.step('JWT generate', async () => {
|
|
85
|
-
return jwt.sign({ id: user.id }, SECRET);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
res.json({ token, user });
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
app.listen(3000);
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### Console Output:
|
|
95
|
-
```
|
|
96
|
-
┌─── flow-debugger ── req_m3k2_abc123_1 ── POST /api/login ───
|
|
97
|
-
│ [0ms] Request start
|
|
98
|
-
│ [2ms] DB find user ✔ (14ms) [mongo]
|
|
99
|
-
│ [16ms] Redis cache session ✔ (3ms) [redis]
|
|
100
|
-
│ [20ms] JWT generate ✔ (1ms)
|
|
101
|
-
│ [21ms] Response 200
|
|
102
|
-
│
|
|
103
|
-
│ Classification: INFO
|
|
104
|
-
│ Total: 21ms
|
|
105
|
-
└──────────────────────────────────────────────────────
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
---
|
|
109
|
-
|
|
110
|
-
## 🧩 Auto-Instrument (Zero Code Tracing)
|
|
111
|
-
|
|
112
|
-
```typescript
|
|
113
|
-
import { mongoTracer, mysqlTracer, pgTracer, redisTracer } from 'flow-debugger';
|
|
114
|
-
|
|
115
|
-
// Mongoose — patches Query.prototype.exec
|
|
116
|
-
mongoTracer(mongoose, { getTracer: debug.getTracer });
|
|
117
|
-
|
|
118
|
-
// mysql2 — patches pool.query() and pool.execute()
|
|
119
|
-
mysqlTracer(pool, { getTracer: debug.getTracer });
|
|
120
|
-
|
|
121
|
-
// pg — patches pool.query() and client.query()
|
|
122
|
-
pgTracer(pgPool, { getTracer: debug.getTracer });
|
|
123
|
-
|
|
124
|
-
// Redis — wraps get, set, del, hget, etc.
|
|
125
|
-
redisTracer(redisClient, { getTracer: debug.getTracer });
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
**Auto output (no extra code needed):**
|
|
129
|
-
```
|
|
130
|
-
MySQL SELECT users → 12ms ✔
|
|
131
|
-
Postgres SELECT orders → 18ms ✔
|
|
132
|
-
Redis SET session → 3ms ✔
|
|
133
|
-
Mongo users.findOne → 22ms ✔
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
---
|
|
137
|
-
|
|
138
|
-
## ⏱ Timeout Detection
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
await tracer.step('DB query', async () => {
|
|
142
|
-
return db.query('SELECT * FROM orders');
|
|
143
|
-
}, { service: 'postgres', timeout: 2000 });
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
If the query takes >2s:
|
|
147
|
-
```
|
|
148
|
-
CRITICAL: DB query timed out after 2000ms
|
|
149
|
-
Root cause: DB timeout
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
---
|
|
153
|
-
|
|
154
|
-
## 🏷 Dependency Tagging
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
await tracer.step('Cache lookup', fn, { service: 'redis' });
|
|
158
|
-
await tracer.step('User query', fn, { service: 'postgres' });
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
Dashboard grouping:
|
|
162
|
-
```
|
|
163
|
-
Top failures:
|
|
164
|
-
Redis 42%
|
|
165
|
-
Postgres 33%
|
|
166
|
-
External 12%
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
---
|
|
170
|
-
|
|
171
|
-
## 📊 Dashboard
|
|
172
|
-
|
|
173
|
-
Access the live analytics dashboard at:
|
|
174
|
-
```
|
|
175
|
-
http://localhost:3000/__debugger/dashboard
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
### API Endpoints:
|
|
179
|
-
| Route | Description |
|
|
180
|
-
|---|---|
|
|
181
|
-
| `GET /__debugger` | Full analytics JSON |
|
|
182
|
-
| `GET /__debugger/dashboard` | Live HTML dashboard |
|
|
183
|
-
| `GET /__debugger/health` | Service health status |
|
|
184
|
-
| `GET /__debugger/endpoint?path=/api/login` | Per-endpoint stats |
|
|
185
|
-
|
|
186
|
-
---
|
|
187
|
-
|
|
188
|
-
## ⚙️ Configuration
|
|
189
|
-
|
|
190
|
-
```typescript
|
|
191
|
-
flowDebugger({
|
|
192
|
-
enabled: true, // Enable/disable debugger
|
|
193
|
-
slowThreshold: 300, // ms — slow step threshold
|
|
194
|
-
slowQueryThreshold: 300, // ms — slow query threshold
|
|
195
|
-
defaultTimeout: 30000, // ms — default step timeout
|
|
196
|
-
samplingRate: 1, // 0-1 (1 = 100%)
|
|
197
|
-
alwaysSampleErrors: true, // Always trace errors even if sampled out
|
|
198
|
-
maxTraces: 1000, // Max traces in memory
|
|
199
|
-
enableTimeline: true, // Console timeline output
|
|
200
|
-
enableDashboard: true, // Serve /__debugger routes
|
|
201
|
-
logger: console.log, // Custom logger function
|
|
202
|
-
});
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
---
|
|
206
|
-
|
|
207
|
-
## 🔍 Root Cause Detection
|
|
208
|
-
|
|
209
|
-
The package automatically identifies the most likely cause of failures:
|
|
210
|
-
|
|
211
|
-
| Scenario | Root Cause |
|
|
212
|
-
|---|---|
|
|
213
|
-
| Response 500 + Redis failed | `Redis GET failed: connection refused` |
|
|
214
|
-
| DB query 900ms + total latency high | `Slow PostgreSQL query: SELECT orders (900ms)` |
|
|
215
|
-
| Step timeout after 2s | `Payment API timed out after 2000ms` |
|
|
216
|
-
|
|
217
|
-
---
|
|
218
|
-
|
|
219
|
-
## 📡 Subpath Imports
|
|
220
|
-
|
|
221
|
-
```typescript
|
|
222
|
-
// Only import what you need
|
|
223
|
-
import { flowDebugger } from 'flow-debugger/express';
|
|
224
|
-
import { mongoTracer } from 'flow-debugger/mongo';
|
|
225
|
-
import { mysqlTracer } from 'flow-debugger/mysql';
|
|
226
|
-
import { pgTracer } from 'flow-debugger/postgres';
|
|
227
|
-
import { redisTracer } from 'flow-debugger/redis';
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
---
|
|
231
|
-
|
|
232
|
-
##
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
+

|
|
10
|
+
---
|
|
11
|
+

|
|
12
|
+
---
|
|
13
|
+
## 🚀 Easy 3-Line Setup (Beginner Friendly)
|
|
14
|
+
Beginners can get a professional dashboard and request tracing with just **3 lines of code**:
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
const debug = flowDebugger({ enableDashboard: true }); // 1. Init
|
|
18
|
+
app.use(debug.middleware); // 2. Middleware
|
|
19
|
+
mongoTracer(mongoose, { getTracer: debug.getTracer }); // 3. Auto-Trace
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## ✨ Features
|
|
25
|
+
|
|
26
|
+
- **Request Tracing** — Every request gets a unique `traceId` with step-by-step timing
|
|
27
|
+
- **Auto-Instrument** — MongoDB, MySQL, PostgreSQL, Redis — zero extra code needed
|
|
28
|
+
- **Root Cause Detection** — Automatically identifies why a request failed or was slow
|
|
29
|
+
- **Error Classification** — `INFO` / `WARN` / `ERROR` / `CRITICAL` auto-categorization
|
|
30
|
+
- **Timeout Detection** — Catches hanging queries/operations with configurable timeouts
|
|
31
|
+
- **Slow Query Detection** — Flags slow SQL/NoSQL queries with threshold alerts
|
|
32
|
+
- **Endpoint Analytics** — Per-route stats: requests, errors, slow, avg/p95/max latency
|
|
33
|
+
- **Service Health Monitor** — Real-time dependency health: `Redis: healthy`, `Mongo: degraded`
|
|
34
|
+
- **Live Dashboard** — Beautiful analytics UI at `/__debugger/dashboard`
|
|
35
|
+
- **Console Timeline** — Visual request timeline directly in your terminal
|
|
36
|
+
- **Production-Safe** — Never blocks requests, never crashes your app, all try/catch wrapped
|
|
37
|
+
- **Sampling** — Configurable sampling rate for high-traffic environments
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 📦 Installation
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm install flow-debugger
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 🚀 Quick Start (Express)
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import express from 'express';
|
|
53
|
+
import { flowDebugger, mongoTracer, mysqlTracer, pgTracer, redisTracer } from 'flow-debugger';
|
|
54
|
+
|
|
55
|
+
const app = express();
|
|
56
|
+
|
|
57
|
+
// 1. Initialize debugger
|
|
58
|
+
const debug = flowDebugger({
|
|
59
|
+
slowThreshold: 300, // ms — mark steps as slow
|
|
60
|
+
slowQueryThreshold: 300, // ms — flag slow DB queries
|
|
61
|
+
enableDashboard: true, // serve /__debugger/dashboard
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
app.use(debug.middleware);
|
|
65
|
+
|
|
66
|
+
// 2. Auto-instrument databases (optional — zero code tracing!)
|
|
67
|
+
mongoTracer(mongoose, { getTracer: debug.getTracer });
|
|
68
|
+
mysqlTracer(mysqlPool, { getTracer: debug.getTracer });
|
|
69
|
+
pgTracer(pgPool, { getTracer: debug.getTracer });
|
|
70
|
+
redisTracer(redisClient, { getTracer: debug.getTracer });
|
|
71
|
+
|
|
72
|
+
// 3. Use manual steps in your routes
|
|
73
|
+
app.post('/api/login', async (req, res) => {
|
|
74
|
+
const tracer = req.tracer;
|
|
75
|
+
|
|
76
|
+
const user = await tracer.step('DB find user', async () => {
|
|
77
|
+
return User.findOne({ email: req.body.email });
|
|
78
|
+
}, { service: 'mongo' });
|
|
79
|
+
|
|
80
|
+
await tracer.step('Redis cache session', async () => {
|
|
81
|
+
return redis.set(`session:${user.id}`, JSON.stringify(user));
|
|
82
|
+
}, { service: 'redis' });
|
|
83
|
+
|
|
84
|
+
const token = await tracer.step('JWT generate', async () => {
|
|
85
|
+
return jwt.sign({ id: user.id }, SECRET);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
res.json({ token, user });
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
app.listen(3000);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Console Output:
|
|
95
|
+
```
|
|
96
|
+
┌─── flow-debugger ── req_m3k2_abc123_1 ── POST /api/login ───
|
|
97
|
+
│ [0ms] Request start
|
|
98
|
+
│ [2ms] DB find user ✔ (14ms) [mongo]
|
|
99
|
+
│ [16ms] Redis cache session ✔ (3ms) [redis]
|
|
100
|
+
│ [20ms] JWT generate ✔ (1ms)
|
|
101
|
+
│ [21ms] Response 200
|
|
102
|
+
│
|
|
103
|
+
│ Classification: INFO
|
|
104
|
+
│ Total: 21ms
|
|
105
|
+
└──────────────────────────────────────────────────────
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 🧩 Auto-Instrument (Zero Code Tracing)
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { mongoTracer, mysqlTracer, pgTracer, redisTracer } from 'flow-debugger';
|
|
114
|
+
|
|
115
|
+
// Mongoose — patches Query.prototype.exec
|
|
116
|
+
mongoTracer(mongoose, { getTracer: debug.getTracer });
|
|
117
|
+
|
|
118
|
+
// mysql2 — patches pool.query() and pool.execute()
|
|
119
|
+
mysqlTracer(pool, { getTracer: debug.getTracer });
|
|
120
|
+
|
|
121
|
+
// pg — patches pool.query() and client.query()
|
|
122
|
+
pgTracer(pgPool, { getTracer: debug.getTracer });
|
|
123
|
+
|
|
124
|
+
// Redis — wraps get, set, del, hget, etc.
|
|
125
|
+
redisTracer(redisClient, { getTracer: debug.getTracer });
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**Auto output (no extra code needed):**
|
|
129
|
+
```
|
|
130
|
+
MySQL SELECT users → 12ms ✔
|
|
131
|
+
Postgres SELECT orders → 18ms ✔
|
|
132
|
+
Redis SET session → 3ms ✔
|
|
133
|
+
Mongo users.findOne → 22ms ✔
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## ⏱ Timeout Detection
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
await tracer.step('DB query', async () => {
|
|
142
|
+
return db.query('SELECT * FROM orders');
|
|
143
|
+
}, { service: 'postgres', timeout: 2000 });
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
If the query takes >2s:
|
|
147
|
+
```
|
|
148
|
+
CRITICAL: DB query timed out after 2000ms
|
|
149
|
+
Root cause: DB timeout
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## 🏷 Dependency Tagging
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
await tracer.step('Cache lookup', fn, { service: 'redis' });
|
|
158
|
+
await tracer.step('User query', fn, { service: 'postgres' });
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Dashboard grouping:
|
|
162
|
+
```
|
|
163
|
+
Top failures:
|
|
164
|
+
Redis 42%
|
|
165
|
+
Postgres 33%
|
|
166
|
+
External 12%
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## 📊 Dashboard
|
|
172
|
+
|
|
173
|
+
Access the live analytics dashboard at:
|
|
174
|
+
```
|
|
175
|
+
http://localhost:3000/__debugger/dashboard
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### API Endpoints:
|
|
179
|
+
| Route | Description |
|
|
180
|
+
|---|---|
|
|
181
|
+
| `GET /__debugger` | Full analytics JSON |
|
|
182
|
+
| `GET /__debugger/dashboard` | Live HTML dashboard |
|
|
183
|
+
| `GET /__debugger/health` | Service health status |
|
|
184
|
+
| `GET /__debugger/endpoint?path=/api/login` | Per-endpoint stats |
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## ⚙️ Configuration
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
flowDebugger({
|
|
192
|
+
enabled: true, // Enable/disable debugger
|
|
193
|
+
slowThreshold: 300, // ms — slow step threshold
|
|
194
|
+
slowQueryThreshold: 300, // ms — slow query threshold
|
|
195
|
+
defaultTimeout: 30000, // ms — default step timeout
|
|
196
|
+
samplingRate: 1, // 0-1 (1 = 100%)
|
|
197
|
+
alwaysSampleErrors: true, // Always trace errors even if sampled out
|
|
198
|
+
maxTraces: 1000, // Max traces in memory
|
|
199
|
+
enableTimeline: true, // Console timeline output
|
|
200
|
+
enableDashboard: true, // Serve /__debugger routes
|
|
201
|
+
logger: console.log, // Custom logger function
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## 🔍 Root Cause Detection
|
|
208
|
+
|
|
209
|
+
The package automatically identifies the most likely cause of failures:
|
|
210
|
+
|
|
211
|
+
| Scenario | Root Cause |
|
|
212
|
+
|---|---|
|
|
213
|
+
| Response 500 + Redis failed | `Redis GET failed: connection refused` |
|
|
214
|
+
| DB query 900ms + total latency high | `Slow PostgreSQL query: SELECT orders (900ms)` |
|
|
215
|
+
| Step timeout after 2s | `Payment API timed out after 2000ms` |
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## 📡 Subpath Imports
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
// Only import what you need
|
|
223
|
+
import { flowDebugger } from 'flow-debugger/express';
|
|
224
|
+
import { mongoTracer } from 'flow-debugger/mongo';
|
|
225
|
+
import { mysqlTracer } from 'flow-debugger/mysql';
|
|
226
|
+
import { pgTracer } from 'flow-debugger/postgres';
|
|
227
|
+
import { redisTracer } from 'flow-debugger/redis';
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## 🐍 Python Support (FastAPI)
|
|
233
|
+
|
|
234
|
+
Flow Debugger now supports Python applications with FastAPI integration:
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
from fastapi import FastAPI
|
|
238
|
+
from flow_debugger.fastapi_middleware import FlowDebuggerFastAPI
|
|
239
|
+
|
|
240
|
+
app = FastAPI()
|
|
241
|
+
|
|
242
|
+
# Initialize debugger
|
|
243
|
+
debugger = FlowDebuggerFastAPI(
|
|
244
|
+
app=app,
|
|
245
|
+
debugger_url="http://localhost:3500/__debugger",
|
|
246
|
+
enabled=True,
|
|
247
|
+
slow_threshold=300
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
@app.get("/api/users")
|
|
251
|
+
async def get_users(request):
|
|
252
|
+
tracer = request.state.tracer # Available via middleware
|
|
253
|
+
|
|
254
|
+
# Manual tracing
|
|
255
|
+
users = await trace_async_step(
|
|
256
|
+
request,
|
|
257
|
+
"DB query users",
|
|
258
|
+
lambda: database.fetch_users(),
|
|
259
|
+
service="postgres"
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
return {"users": users}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Python Manual Tracing
|
|
266
|
+
```python
|
|
267
|
+
from flow_debugger.fastapi_middleware import traced_step
|
|
268
|
+
|
|
269
|
+
@app.post("/api/orders")
|
|
270
|
+
async def create_order(request):
|
|
271
|
+
with traced_step(request.state.tracer, "Validate user", "auth"):
|
|
272
|
+
user = await validate_user(request.user_id)
|
|
273
|
+
|
|
274
|
+
with traced_step(request.state.tracer, "Create order", "postgres"):
|
|
275
|
+
order = await create_order_in_db(request.order_data)
|
|
276
|
+
|
|
277
|
+
return {"order": order}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## 📱 React Native Integration
|
|
283
|
+
|
|
284
|
+
For React Native applications, use the React Native SDK:
|
|
285
|
+
|
|
286
|
+
```typescript
|
|
287
|
+
import { DebuggerProvider, useDebugger, traceAsyncOperation } from 'flow-debugger/react_native';
|
|
288
|
+
|
|
289
|
+
// Wrap your app with the provider
|
|
290
|
+
export default function App() {
|
|
291
|
+
return (
|
|
292
|
+
<DebuggerProvider debuggerUrl="http://localhost:3500/__debugger">
|
|
293
|
+
<YourAppContent />
|
|
294
|
+
</DebuggerProvider>
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Use in your components
|
|
299
|
+
function MyComponent() {
|
|
300
|
+
const { step, startTrace } = useDebugger();
|
|
301
|
+
|
|
302
|
+
const fetchData = async () => {
|
|
303
|
+
const traceId = startTrace('/api/data', 'GET');
|
|
304
|
+
|
|
305
|
+
try {
|
|
306
|
+
// Trace an async operation
|
|
307
|
+
const result = await step(
|
|
308
|
+
traceId,
|
|
309
|
+
'API call',
|
|
310
|
+
() => fetch('https://api.example.com/data').then(r => r.json()),
|
|
311
|
+
{ service: 'external' }
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
// Send trace to dashboard
|
|
315
|
+
await sendTrace(traceId);
|
|
316
|
+
|
|
317
|
+
return result;
|
|
318
|
+
} catch (error) {
|
|
319
|
+
await sendTrace(traceId);
|
|
320
|
+
throw error;
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
// Or use the utility function
|
|
325
|
+
const fetchWithTrace = async () => {
|
|
326
|
+
return await traceAsyncOperation(
|
|
327
|
+
'/api/data',
|
|
328
|
+
'Fetch data',
|
|
329
|
+
() => fetch('https://api.example.com/data').then(r => r.json()),
|
|
330
|
+
'external'
|
|
331
|
+
);
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
return <View>...</View>;
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### React Native Fetch Interceptor
|
|
339
|
+
```typescript
|
|
340
|
+
import { createFetchInterceptor } from 'flow-debugger/react_native';
|
|
341
|
+
|
|
342
|
+
// Replace global fetch with intercepted version
|
|
343
|
+
global.fetch = createFetchInterceptor("http://localhost:3500/__debugger");
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
## 🏗 Architecture
|
|
349
|
+
|
|
350
|
+
```
|
|
351
|
+
core/
|
|
352
|
+
TraceEngine — request trace lifecycle
|
|
353
|
+
Classifier — INFO/WARN/ERROR/CRITICAL
|
|
354
|
+
RootCause — failure origin detection
|
|
355
|
+
Analytics — endpoint-level aggregation
|
|
356
|
+
HealthMonitor — dependency health tracking
|
|
357
|
+
Timeline — console renderer
|
|
358
|
+
|
|
359
|
+
integrations/
|
|
360
|
+
mongo — Mongoose auto-tracing
|
|
361
|
+
mysql — mysql2 auto-tracing
|
|
362
|
+
postgres — pg auto-tracing
|
|
363
|
+
redis — Redis auto-tracing
|
|
364
|
+
fetch — Global fetch tracing
|
|
365
|
+
axios — Axios interceptor
|
|
366
|
+
|
|
367
|
+
middleware/
|
|
368
|
+
express — Express middleware + dashboard
|
|
369
|
+
|
|
370
|
+
python-sdk/
|
|
371
|
+
fastapi_middleware — FastAPI integration
|
|
372
|
+
flow_debugger_core — Core Python classes
|
|
373
|
+
|
|
374
|
+
react-native/
|
|
375
|
+
react_native — React Native integration
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
## 🛡 Production Rules
|
|
381
|
+
|
|
382
|
+
1. **Debugger never blocks requests** — all logic is async & non-blocking
|
|
383
|
+
2. **Debugger never crashes your app** — every operation is try/catch wrapped
|
|
384
|
+
3. **Use sampling in high traffic** — set `samplingRate: 0.1` for 10% sampling
|
|
385
|
+
4. **Errors always get traced** — even when sampling drops a request
|
|
386
|
+
|
|
387
|
+
---
|
|
388
|
+
|
|
389
|
+
## 📄 License
|
|
390
|
+
|
|
391
|
+
MIT
|