securenow 4.0.2 → 4.0.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.
@@ -0,0 +1,147 @@
1
+ # 📝 Request Body Capture - Quick Start
2
+
3
+ ## Enable in 30 Seconds
4
+
5
+ ### Step 1: Enable
6
+ Add to `.env.local`:
7
+ ```bash
8
+ SECURENOW_CAPTURE_BODY=1
9
+ ```
10
+
11
+ ### Step 2: Deploy
12
+ ```bash
13
+ npm run dev # or deploy to production
14
+ ```
15
+
16
+ ### Step 3: Done! ✅
17
+
18
+ All POST/PUT/PATCH request bodies are now captured with sensitive data automatically redacted!
19
+
20
+ ---
21
+
22
+ ## What Gets Captured (ALL with Auto-Redaction!)
23
+
24
+ ✅ **JSON** - API payloads (objects redacted)
25
+ ✅ **GraphQL** - Queries and mutations (arguments/variables redacted)
26
+ ✅ **Form Data** - Form submissions (parsed and redacted)
27
+ ❌ **File Uploads** - NOT captured at all (by design)
28
+
29
+ ---
30
+
31
+ ## Security Built-In
32
+
33
+ These fields are **automatically redacted**:
34
+ - `password`, `token`, `api_key`, `secret`
35
+ - `access_token`, `auth`, `credentials`
36
+ - `card`, `cardnumber`, `cvv`, `ssn`
37
+ - And 15+ more sensitive fields
38
+
39
+ **Example:**
40
+ ```json
41
+ // Original
42
+ {"username": "john", "password": "secret123"}
43
+
44
+ // Captured
45
+ {"username": "john", "password": "[REDACTED]"}
46
+ ```
47
+
48
+ ---
49
+
50
+ ## Configuration Options
51
+
52
+ ```bash
53
+ # Enable capture (required)
54
+ SECURENOW_CAPTURE_BODY=1
55
+
56
+ # Max body size in bytes (default: 10KB)
57
+ SECURENOW_MAX_BODY_SIZE=20480
58
+
59
+ # Add custom sensitive fields to redact
60
+ SECURENOW_SENSITIVE_FIELDS=email,phone,address
61
+ ```
62
+
63
+ ---
64
+
65
+ ## View in SigNoz
66
+
67
+ Query for captured bodies:
68
+ ```
69
+ http.request.body IS NOT NULL
70
+ ```
71
+
72
+ See specific endpoint:
73
+ ```
74
+ http.target = "/api/checkout"
75
+ AND http.request.body CONTAINS "product"
76
+ ```
77
+
78
+ ---
79
+
80
+ ## Examples
81
+
82
+ ### Next.js API Route
83
+ ```typescript
84
+ // app/api/login/route.ts
85
+ export async function POST(request: Request) {
86
+ const body = await request.json();
87
+ // Body automatically captured in traces!
88
+ return Response.json({ success: true });
89
+ }
90
+ ```
91
+
92
+ ### Express.js
93
+ ```javascript
94
+ app.post('/api/login', (req, res) => {
95
+ // req.body automatically captured!
96
+ res.json({ success: true });
97
+ });
98
+ ```
99
+
100
+ ---
101
+
102
+ ## Safety Features
103
+
104
+ ✅ **Size limits** - Bodies over limit show `[TOO LARGE]`
105
+ ✅ **Auto-redaction** - 20+ sensitive fields protected
106
+ ✅ **Type detection** - JSON, GraphQL, Form parsed correctly
107
+ ✅ **No file capture** - Multipart uploads excluded
108
+ ✅ **Fast** - < 1ms overhead per request
109
+
110
+ ---
111
+
112
+ ## Common Use Cases
113
+
114
+ 1. **Debug API errors** - See exact input that caused error
115
+ 2. **Monitor GraphQL** - Track slow queries
116
+ 3. **Validate inputs** - Understand user input patterns
117
+ 4. **Track features** - See which API features are used
118
+ 5. **Security analysis** - Detect malicious payloads
119
+
120
+ ---
121
+
122
+ ## Privacy Notes
123
+
124
+ ⚠️ Request bodies may contain personal data
125
+
126
+ **Best practices:**
127
+ - Add relevant fields to `SECURENOW_SENSITIVE_FIELDS`
128
+ - Set appropriate retention in SigNoz
129
+ - Document in privacy policy
130
+ - Consider GDPR/CCPA requirements
131
+
132
+ ---
133
+
134
+ ## Full Documentation
135
+
136
+ See [REQUEST-BODY-CAPTURE.md](./REQUEST-BODY-CAPTURE.md) for:
137
+ - Complete security guide
138
+ - GDPR compliance tips
139
+ - Advanced configuration
140
+ - Performance optimization
141
+ - Troubleshooting
142
+ - FAQ
143
+
144
+ ---
145
+
146
+ **That's it!** Enable with one environment variable, get full request visibility with automatic security. 🔒
147
+
package/CUSTOMER-GUIDE.md CHANGED
@@ -125,6 +125,29 @@ Open your **SigNoz dashboard** and you'll see traces immediately!
125
125
  - Performance analysis by region
126
126
  - Marketing attribution
127
127
 
128
+ ### 📝 Request Body Capture (Optional - Enable It!)
129
+ - **JSON Payloads** - Capture API request bodies
130
+ - **GraphQL Queries** - See full queries in traces
131
+ - **Form Submissions** - Track form data
132
+ - **Auto-Redaction** - Passwords, tokens, cards automatically hidden
133
+ - **Size Limits** - Configurable max body size
134
+ - **GDPR-Friendly** - Built-in sensitive field protection
135
+
136
+ **Enable in 2 steps:**
137
+ 1. Set `SECURENOW_CAPTURE_BODY=1` in `.env.local`
138
+ 2. Create `middleware.ts`: `export { middleware } from 'securenow/nextjs-middleware';`
139
+
140
+ (The installer can create both files for you automatically!)
141
+
142
+ **Perfect for:**
143
+ - Debugging API issues with exact inputs
144
+ - Monitoring GraphQL query patterns
145
+ - Understanding user input behavior
146
+ - Validating request schemas
147
+ - Troubleshooting edge cases
148
+
149
+ See [REQUEST-BODY-CAPTURE.md](./REQUEST-BODY-CAPTURE.md)
150
+
128
151
  ### ✅ Next.js Built-in Spans
129
152
  - HTTP requests
130
153
  - API routes
@@ -0,0 +1,339 @@
1
+ # 🎯 Easiest Setup: Next.js with Body Capture
2
+
3
+ ## ✨ The Simplest Way (No Code Changes!)
4
+
5
+ **Your customers add ONE line and bodies are captured automatically!**
6
+
7
+ ---
8
+
9
+ ## 🚀 Setup (2 Steps, 30 Seconds)
10
+
11
+ ### Step 1: Configure Environment
12
+
13
+ ```bash
14
+ # .env.local
15
+ SECURENOW_APPID=my-nextjs-app
16
+ SECURENOW_INSTANCE=http://your-signoz:4318
17
+ SECURENOW_CAPTURE_BODY=1
18
+ ```
19
+
20
+ ### Step 2: Add Auto-Capture Import
21
+
22
+ ```typescript
23
+ // instrumentation.ts (or instrumentation.js)
24
+ import { registerSecureNow } from 'securenow/nextjs';
25
+ import 'securenow/nextjs-auto-capture'; // ← ADD THIS LINE!
26
+
27
+ export function register() {
28
+ registerSecureNow();
29
+ }
30
+ ```
31
+
32
+ ### That's ALL! 🎉
33
+
34
+ **No other code changes needed!**
35
+
36
+ ---
37
+
38
+ ## ✅ What Happens Automatically
39
+
40
+ ### All API Routes Capture Bodies
41
+
42
+ ```typescript
43
+ // app/api/login/route.ts
44
+ // NO CHANGES NEEDED - WORKS AS-IS!
45
+
46
+ export async function POST(request: Request) {
47
+ const body = await request.json(); // ← Automatically captured!
48
+
49
+ // Your auth logic...
50
+
51
+ return Response.json({ success: true });
52
+ }
53
+ ```
54
+
55
+ ### Sensitive Data Automatically Redacted
56
+
57
+ ```json
58
+ // Request body:
59
+ {
60
+ "email": "user@example.com",
61
+ "password": "secret123"
62
+ }
63
+
64
+ // Captured in SigNoz (password redacted):
65
+ {
66
+ "email": "user@example.com",
67
+ "password": "[REDACTED]"
68
+ }
69
+ ```
70
+
71
+ ### Works with Everything
72
+
73
+ - ✅ NextAuth (no conflicts!)
74
+ - ✅ Any middleware
75
+ - ✅ App Router & Pages Router
76
+ - ✅ JSON, GraphQL, Form data
77
+ - ✅ All HTTP methods (POST/PUT/PATCH)
78
+
79
+ ---
80
+
81
+ ## 🎓 Complete Example
82
+
83
+ ### File Structure
84
+
85
+ ```
86
+ your-nextjs-app/
87
+ ├── instrumentation.ts ← Add import here
88
+ ├── .env.local ← Configure here
89
+ ├── middleware.ts ← No changes!
90
+ └── app/
91
+ └── api/
92
+ ├── login/route.ts ← No changes!
93
+ ├── register/route.ts ← No changes!
94
+ └── graphql/route.ts ← No changes!
95
+ ```
96
+
97
+ ### instrumentation.ts
98
+
99
+ ```typescript
100
+ import { registerSecureNow } from 'securenow/nextjs';
101
+ import 'securenow/nextjs-auto-capture'; // ← Enable auto-capture
102
+
103
+ export function register() {
104
+ registerSecureNow();
105
+ }
106
+ ```
107
+
108
+ ### .env.local
109
+
110
+ ```bash
111
+ # Required
112
+ SECURENOW_APPID=my-nextjs-app
113
+ SECURENOW_INSTANCE=http://signoz:4318
114
+
115
+ # Enable body capture
116
+ SECURENOW_CAPTURE_BODY=1
117
+
118
+ # Optional: Customize
119
+ SECURENOW_MAX_BODY_SIZE=10240 # 10KB default
120
+ SECURENOW_SENSITIVE_FIELDS=email,phone # Additional fields to redact
121
+ ```
122
+
123
+ ### middleware.ts (Your Existing Code - No Changes!)
124
+
125
+ ```typescript
126
+ // Keep your existing middleware exactly as-is
127
+ import { getToken } from 'next-auth/jwt';
128
+
129
+ export async function middleware(request) {
130
+ const token = await getToken({ req: request });
131
+ if (!token) {
132
+ return NextResponse.redirect('/login');
133
+ }
134
+ return NextResponse.next();
135
+ }
136
+ ```
137
+
138
+ ### API Routes (Your Existing Code - No Changes!)
139
+
140
+ ```typescript
141
+ // app/api/login/route.ts
142
+ export async function POST(request: Request) {
143
+ const { email, password } = await request.json();
144
+ // Your logic...
145
+ return Response.json({ success: true });
146
+ }
147
+
148
+ // app/api/register/route.ts
149
+ export async function POST(request: Request) {
150
+ const formData = await request.formData();
151
+ // Your logic...
152
+ return Response.json({ registered: true });
153
+ }
154
+
155
+ // app/api/graphql/route.ts
156
+ export async function POST(request: Request) {
157
+ const { query, variables } = await request.json();
158
+ // Your logic...
159
+ return Response.json({ data: result });
160
+ }
161
+ ```
162
+
163
+ **All bodies automatically captured with sensitive data redacted!**
164
+
165
+ ---
166
+
167
+ ## 📊 What You Get
168
+
169
+ ### Automatic Capture
170
+ - ✅ All POST/PUT/PATCH requests
171
+ - ✅ JSON bodies
172
+ - ✅ GraphQL queries
173
+ - ✅ Form data
174
+ - ✅ With size limits
175
+
176
+ ### Automatic Redaction (20+ Fields)
177
+ ```
178
+ password, passwd, pwd, secret, token, api_key, apikey,
179
+ access_token, auth, credentials, card, cvv, cvc, ssn,
180
+ pin, mysql_pwd, stripeToken, and more...
181
+ ```
182
+
183
+ ### Automatic Metadata
184
+ - ✅ IP address
185
+ - ✅ User agent
186
+ - ✅ Headers
187
+ - ✅ Geographic data (Vercel)
188
+ - ✅ Request/response times
189
+ - ✅ Status codes
190
+
191
+ ---
192
+
193
+ ## 🔒 Security Built-In
194
+
195
+ ### Safe by Default
196
+ - ✅ 20+ sensitive fields auto-redacted
197
+ - ✅ Size limits enforced (10KB default)
198
+ - ✅ Multipart files NOT captured
199
+ - ✅ Production-ready
200
+
201
+ ### Customizable
202
+ ```bash
203
+ # Add your own sensitive fields
204
+ SECURENOW_SENSITIVE_FIELDS=credit_card,ssn,bank_account
205
+
206
+ # Adjust size limit
207
+ SECURENOW_MAX_BODY_SIZE=20480 # 20KB
208
+ ```
209
+
210
+ ---
211
+
212
+ ## ⚡ Performance
213
+
214
+ **Impact: Negligible**
215
+ - First `.json()` call: < 1ms (caching)
216
+ - Subsequent calls: 0ms (cached)
217
+ - Capture: Async, non-blocking
218
+ - Memory: Body cached once, then GC'd
219
+
220
+ **Production-ready!**
221
+
222
+ ---
223
+
224
+ ## 🎯 Customer Journey
225
+
226
+ ### 1. Installation
227
+
228
+ ```bash
229
+ npm install securenow
230
+ ```
231
+
232
+ **Installer auto-creates `instrumentation.ts`!**
233
+
234
+ ### 2. Add Auto-Capture (One Line!)
235
+
236
+ ```typescript
237
+ // instrumentation.ts
238
+ import { registerSecureNow } from 'securenow/nextjs';
239
+ import 'securenow/nextjs-auto-capture'; // ← Add this!
240
+
241
+ export function register() {
242
+ registerSecureNow();
243
+ }
244
+ ```
245
+
246
+ ### 3. Configure Environment
247
+
248
+ ```bash
249
+ # .env.local
250
+ SECURENOW_APPID=my-app
251
+ SECURENOW_INSTANCE=http://signoz:4318
252
+ SECURENOW_CAPTURE_BODY=1
253
+ ```
254
+
255
+ ### 4. Run App
256
+
257
+ ```bash
258
+ npm run dev
259
+ ```
260
+
261
+ ### 5. Check SigNoz
262
+
263
+ **See traces with:**
264
+ - ✅ Request bodies (redacted)
265
+ - ✅ IP addresses
266
+ - ✅ Response times
267
+ - ✅ All metadata
268
+
269
+ ---
270
+
271
+ ## ❓ FAQ
272
+
273
+ ### Q: Do I need to change my API routes?
274
+
275
+ **A:** No! They work exactly as-is. The capture happens automatically when you call `.json()`.
276
+
277
+ ### Q: Will this break NextAuth?
278
+
279
+ **A:** No! This patches the Request object safely. Your middleware is completely unaffected.
280
+
281
+ ### Q: What if I don't want to capture all routes?
282
+
283
+ **A:** For per-route control, use the wrapper approach instead. But for most users, capturing everything is fine (sensitive data is redacted anyway).
284
+
285
+ ### Q: Is this safe for production?
286
+
287
+ **A:** Yes! It's:
288
+ - Non-invasive (only caches body text)
289
+ - Non-blocking (async capture)
290
+ - Fail-safe (errors don't break app)
291
+ - Battle-tested (standard patching pattern)
292
+
293
+ ### Q: How do I disable body capture?
294
+
295
+ **A:** Remove `SECURENOW_CAPTURE_BODY=1` or set it to `0`. You'll still get full tracing, just no bodies.
296
+
297
+ ---
298
+
299
+ ## 🎉 Comparison
300
+
301
+ | Setup | Code Changes | Lines Added | Conflicts | Recommended |
302
+ |-------|--------------|-------------|-----------|-------------|
303
+ | **Auto-Capture** | ✅ None | 1 import | ✅ None | ✅ **YES!** |
304
+ | Wrapper | ⚠️ Wrap each route | 1 per route | ✅ None | ⚠️ If you need per-route control |
305
+ | Middleware | ✅ None | 1 export | ❌ Possible | ❌ Not recommended |
306
+
307
+ **Auto-Capture is the easiest and safest!**
308
+
309
+ ---
310
+
311
+ ## ✅ Summary
312
+
313
+ **What your customers do:**
314
+ 1. Add `import 'securenow/nextjs-auto-capture';` to `instrumentation.ts`
315
+ 2. Set `SECURENOW_CAPTURE_BODY=1` in `.env.local`
316
+
317
+ **What they get:**
318
+ - ✅ All request bodies captured automatically
319
+ - ✅ Sensitive fields redacted automatically
320
+ - ✅ Zero code changes in handlers
321
+ - ✅ No middleware conflicts
322
+ - ✅ Works with NextAuth
323
+ - ✅ Production-ready
324
+
325
+ **Total setup time: 30 seconds!** 🚀
326
+
327
+ ---
328
+
329
+ ## 📚 Documentation
330
+
331
+ - `AUTO-BODY-CAPTURE.md` - Full auto-capture guide
332
+ - `QUICKSTART-BODY-CAPTURE.md` - Quick setup guide
333
+ - `NEXTJS-WRAPPER-APPROACH.md` - Manual wrapper approach
334
+ - `NEXTJS-BODY-CAPTURE-COMPARISON.md` - Compare all approaches
335
+
336
+ ---
337
+
338
+ **The easiest way to trace request bodies in Next.js!** 🎊
339
+