securenow 7.6.7 → 7.6.8
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/NPM_README.md +13 -13
- package/README.md +21 -37
- package/app-config.js +5 -3
- package/cli/config.js +4 -3
- package/cli/diagnostics.js +54 -15
- package/cli/run.js +40 -11
- package/firewall-only.js +1 -1
- package/mcp/catalog.js +1 -1
- package/nextjs-webpack-config.js +3 -15
- package/nextjs.js +21 -23
- package/nuxt-server-plugin.mjs +20 -10
- package/package.json +33 -34
- package/register.js +1 -1
- package/tracing.js +17 -7
- package/web-vite.mjs +23 -13
- package/CONSUMING-APPS-GUIDE.md +0 -463
- package/docs/ALL-FRAMEWORKS-QUICKSTART.md +0 -1388
- package/docs/API-KEYS-GUIDE.md +0 -278
- package/docs/ARCHITECTURE.md +0 -408
- package/docs/AUTO-BODY-CAPTURE.md +0 -412
- package/docs/AUTO-SETUP-SUMMARY.md +0 -331
- package/docs/AUTO-SETUP.md +0 -419
- package/docs/AUTOMATIC-IP-CAPTURE.md +0 -359
- package/docs/BODY-CAPTURE-FIX.md +0 -261
- package/docs/BODY-CAPTURE-QUICKSTART.md +0 -147
- package/docs/CHANGELOG-NEXTJS.md +0 -235
- package/docs/COMPLETION-REPORT.md +0 -408
- package/docs/CUSTOMER-GUIDE.md +0 -364
- package/docs/EASIEST-SETUP.md +0 -342
- package/docs/ENVIRONMENT-VARIABLES.md +0 -166
- package/docs/ENVIRONMENTS.md +0 -60
- package/docs/EXPRESS-BODY-CAPTURE.md +0 -1028
- package/docs/EXPRESS-SETUP-GUIDE.md +0 -722
- package/docs/FINAL-SOLUTION.md +0 -335
- package/docs/FIREWALL-GUIDE.md +0 -440
- package/docs/IMPLEMENTATION-SUMMARY.md +0 -410
- package/docs/INDEX.md +0 -222
- package/docs/LOGGING-GUIDE.md +0 -704
- package/docs/LOGGING-QUICKSTART.md +0 -221
- package/docs/MCP-GUIDE.md +0 -58
- package/docs/NEXTJS-BODY-CAPTURE-COMPARISON.md +0 -323
- package/docs/NEXTJS-BODY-CAPTURE.md +0 -368
- package/docs/NEXTJS-GUIDE.md +0 -392
- package/docs/NEXTJS-QUICKSTART.md +0 -83
- package/docs/NEXTJS-SETUP-COMPLETE.md +0 -795
- package/docs/NEXTJS-WEBPACK-WARNINGS.md +0 -267
- package/docs/NEXTJS-WRAPPER-APPROACH.md +0 -414
- package/docs/NUXT-GUIDE.md +0 -173
- package/docs/QUICKSTART-BODY-CAPTURE.md +0 -293
- package/docs/REDACTION-EXAMPLES.md +0 -484
- package/docs/REQUEST-BODY-CAPTURE.md +0 -587
- package/docs/SOLUTION-SUMMARY.md +0 -312
- package/docs/VERCEL-OTEL-MIGRATION.md +0 -255
- package/examples/README.md +0 -265
- package/examples/express-with-logging.js +0 -137
- package/examples/instrumentation-with-auto-capture.ts +0 -41
- package/examples/next.config.js +0 -37
- package/examples/nextjs-api-route-with-body-capture.ts +0 -54
- package/examples/nextjs-env-example.txt +0 -32
- package/examples/nextjs-instrumentation.js +0 -36
- package/examples/nextjs-instrumentation.ts +0 -36
- package/examples/nextjs-middleware.js +0 -37
- package/examples/nextjs-middleware.ts +0 -37
- package/examples/nextjs-with-logging-example.md +0 -301
- package/examples/nextjs-with-options.ts +0 -36
- package/examples/test-nextjs-setup.js +0 -70
- package/postinstall.js +0 -296
package/docs/CUSTOMER-GUIDE.md
DELETED
|
@@ -1,364 +0,0 @@
|
|
|
1
|
-
# 🚀 Add Observability to Your Next.js App in 2 Minutes
|
|
2
|
-
|
|
3
|
-
**Send traces to SecureNow with just 1-2 steps. No webpack warnings!**
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## Step 1: Install SecureNow
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install securenow
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
**🎉 That's it!** The installer will automatically:
|
|
14
|
-
- Detect your Next.js project
|
|
15
|
-
- Offer to create `instrumentation.ts` (or `.js`)
|
|
16
|
-
- Create `.env.local` template
|
|
17
|
-
- **No webpack bundling warnings** (uses @vercel/otel)
|
|
18
|
-
|
|
19
|
-
Just answer **"Y"** when prompted!
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
## Step 2: Configure Environment Variables
|
|
24
|
-
|
|
25
|
-
The installer created `.env.local` for you. Just edit it:
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
import { registerSecureNow } from 'securenow/nextjs';
|
|
29
|
-
|
|
30
|
-
export function register() {
|
|
31
|
-
registerSecureNow();
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
**Using JavaScript?** Create `instrumentation.js` instead:
|
|
36
|
-
|
|
37
|
-
```javascript
|
|
38
|
-
const { registerSecureNow } = require('securenow/nextjs');
|
|
39
|
-
|
|
40
|
-
export function register() {
|
|
41
|
-
registerSecureNow();
|
|
42
|
-
}
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
---
|
|
46
|
-
|
|
47
|
-
## Step 3: Add Environment Variables
|
|
48
|
-
|
|
49
|
-
Create or update `.env.local`:
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
# Just update these two values:
|
|
53
|
-
SECURENOW_APPID=my-nextjs-app # Your app name
|
|
54
|
-
SECURENOW_INSTANCE=http://your-otlp-backend:4318 # Your OTLP / SecureNow URL
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
---
|
|
58
|
-
|
|
59
|
-
## That's It! 🎉
|
|
60
|
-
|
|
61
|
-
---
|
|
62
|
-
|
|
63
|
-
## Alternative Setup Methods
|
|
64
|
-
|
|
65
|
-
### If You Skipped Auto-Setup
|
|
66
|
-
|
|
67
|
-
**Option 1: Use the CLI (Recommended)**
|
|
68
|
-
|
|
69
|
-
```bash
|
|
70
|
-
npx securenow init
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
**Option 2: Create Manually**
|
|
74
|
-
|
|
75
|
-
Create `instrumentation.ts` at project root:
|
|
76
|
-
|
|
77
|
-
```typescript
|
|
78
|
-
import { registerSecureNow } from 'securenow/nextjs';
|
|
79
|
-
export function register() { registerSecureNow(); }
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
Then create `.env.local`:
|
|
83
|
-
|
|
84
|
-
```bash
|
|
85
|
-
SECURENOW_APPID=my-nextjs-app
|
|
86
|
-
SECURENOW_INSTANCE=http://your-otlp-backend:4318
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
---
|
|
90
|
-
|
|
91
|
-
## Run Your App
|
|
92
|
-
|
|
93
|
-
Run your app:
|
|
94
|
-
|
|
95
|
-
```bash
|
|
96
|
-
npm run dev
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
You should see:
|
|
100
|
-
|
|
101
|
-
```
|
|
102
|
-
[securenow] Next.js integration loading
|
|
103
|
-
[securenow] 🚀 Next.js App → service.name=my-nextjs-app
|
|
104
|
-
[securenow] ✅ OpenTelemetry started for Next.js
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
Open your **SecureNow dashboard** and you'll see traces immediately!
|
|
108
|
-
|
|
109
|
-
---
|
|
110
|
-
|
|
111
|
-
## 📊 What You Get Automatically
|
|
112
|
-
|
|
113
|
-
### 🌐 User & Request Data (NEW!)
|
|
114
|
-
- **IP Addresses** - Automatically captured from all sources
|
|
115
|
-
- **User Agents** - Browser/device information
|
|
116
|
-
- **Referers** - Traffic sources
|
|
117
|
-
- **Geographic Data** - Country, region, city (on Vercel/Cloudflare)
|
|
118
|
-
- **Request Headers** - Host, scheme, request IDs
|
|
119
|
-
- **Response Codes** - 200, 404, 500, etc.
|
|
120
|
-
|
|
121
|
-
**Perfect for:**
|
|
122
|
-
- Debugging location-specific issues
|
|
123
|
-
- Tracking user journeys
|
|
124
|
-
- Bot detection
|
|
125
|
-
- Performance analysis by region
|
|
126
|
-
- Marketing attribution
|
|
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
|
-
|
|
151
|
-
### ✅ Next.js Built-in Spans
|
|
152
|
-
- HTTP requests
|
|
153
|
-
- API routes
|
|
154
|
-
- Page rendering
|
|
155
|
-
- Server-side props
|
|
156
|
-
- Metadata generation
|
|
157
|
-
- Time to First Byte (TTFB)
|
|
158
|
-
|
|
159
|
-
### ✅ Backend Instrumentation
|
|
160
|
-
- **Databases:** PostgreSQL, MySQL, MongoDB, Redis
|
|
161
|
-
- **HTTP Calls:** fetch, axios, http/https
|
|
162
|
-
- **GraphQL** queries
|
|
163
|
-
- **gRPC** calls
|
|
164
|
-
- **And 30+ more libraries**
|
|
165
|
-
|
|
166
|
-
No additional code needed!
|
|
167
|
-
|
|
168
|
-
---
|
|
169
|
-
|
|
170
|
-
## ⚙️ Optional: Add Authentication
|
|
171
|
-
|
|
172
|
-
If your OTLP backend requires an API key:
|
|
173
|
-
|
|
174
|
-
```bash
|
|
175
|
-
# Add to .env.local
|
|
176
|
-
OTEL_EXPORTER_OTLP_HEADERS="x-api-key=your-api-key-here"
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
---
|
|
180
|
-
|
|
181
|
-
## 🔧 Optional: Advanced Configuration
|
|
182
|
-
|
|
183
|
-
Want more control? You can pass options:
|
|
184
|
-
|
|
185
|
-
```typescript
|
|
186
|
-
import { registerSecureNow } from 'securenow/nextjs';
|
|
187
|
-
|
|
188
|
-
export function register() {
|
|
189
|
-
registerSecureNow({
|
|
190
|
-
serviceName: 'my-app',
|
|
191
|
-
endpoint: 'http://otel-collector:4318',
|
|
192
|
-
headers: {
|
|
193
|
-
'x-api-key': process.env.SECURENOW_API_KEY || '',
|
|
194
|
-
},
|
|
195
|
-
disableInstrumentations: ['fs'], // Optional: disable specific instrumentations
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
---
|
|
201
|
-
|
|
202
|
-
## 🚨 Troubleshooting
|
|
203
|
-
|
|
204
|
-
### Not seeing traces?
|
|
205
|
-
|
|
206
|
-
**1. Check the console output**
|
|
207
|
-
```bash
|
|
208
|
-
npm run dev
|
|
209
|
-
# Look for: [securenow] ✅ OpenTelemetry started
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
**2. Enable debug mode**
|
|
213
|
-
```bash
|
|
214
|
-
# Add to .env.local
|
|
215
|
-
OTEL_LOG_LEVEL=debug
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
**3. Create a test span**
|
|
219
|
-
```bash
|
|
220
|
-
# Add to .env.local
|
|
221
|
-
SECURENOW_TEST_SPAN=1
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
**4. Verify your OTLP endpoint is accessible**
|
|
225
|
-
```bash
|
|
226
|
-
curl http://your-otlp-backend:4318/v1/traces
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
---
|
|
230
|
-
|
|
231
|
-
## 🎯 Next.js Version Requirements
|
|
232
|
-
|
|
233
|
-
| Next.js Version | Setup Required |
|
|
234
|
-
|----------------|----------------|
|
|
235
|
-
| **Next.js 15+** | ✅ Just create `instrumentation.ts` |
|
|
236
|
-
| **Next.js 14 and below** | ⚠️ Also add to `next.config.js`: |
|
|
237
|
-
|
|
238
|
-
For Next.js 14 and below, update `next.config.js`:
|
|
239
|
-
|
|
240
|
-
```javascript
|
|
241
|
-
const nextConfig = {
|
|
242
|
-
experimental: {
|
|
243
|
-
instrumentationHook: true, // Required for Next.js 14 and below
|
|
244
|
-
},
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
module.exports = nextConfig;
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
---
|
|
251
|
-
|
|
252
|
-
## ☁️ Deployment
|
|
253
|
-
|
|
254
|
-
### Vercel
|
|
255
|
-
|
|
256
|
-
1. Go to your Vercel project settings
|
|
257
|
-
2. Add environment variables:
|
|
258
|
-
- `SECURENOW_APPID=my-nextjs-app`
|
|
259
|
-
- `SECURENOW_INSTANCE=http://your-otlp-backend:4318`
|
|
260
|
-
3. Redeploy
|
|
261
|
-
|
|
262
|
-
**Done!** Traces will appear in SecureNow.
|
|
263
|
-
|
|
264
|
-
### Docker
|
|
265
|
-
|
|
266
|
-
```dockerfile
|
|
267
|
-
FROM node:20-alpine
|
|
268
|
-
WORKDIR /app
|
|
269
|
-
|
|
270
|
-
COPY package*.json ./
|
|
271
|
-
RUN npm ci --production
|
|
272
|
-
|
|
273
|
-
COPY . .
|
|
274
|
-
RUN npm run build
|
|
275
|
-
|
|
276
|
-
ENV SECURENOW_APPID=my-nextjs-app
|
|
277
|
-
ENV SECURENOW_INSTANCE=http://otel-collector:4318
|
|
278
|
-
|
|
279
|
-
EXPOSE 3000
|
|
280
|
-
CMD ["npm", "start"]
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
### Self-Hosted / VPS
|
|
284
|
-
|
|
285
|
-
```bash
|
|
286
|
-
export SECURENOW_APPID=my-nextjs-app
|
|
287
|
-
export SECURENOW_INSTANCE=http://your-otlp-backend:4318
|
|
288
|
-
npm start
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
---
|
|
292
|
-
|
|
293
|
-
## 🎓 Environment Variables Reference
|
|
294
|
-
|
|
295
|
-
```bash
|
|
296
|
-
# ===== REQUIRED =====
|
|
297
|
-
SECURENOW_APPID=my-app-name # Your app identifier
|
|
298
|
-
SECURENOW_INSTANCE=http://host:4318 # OTLP / SecureNow endpoint
|
|
299
|
-
|
|
300
|
-
# ===== OPTIONAL =====
|
|
301
|
-
OTEL_EXPORTER_OTLP_HEADERS="key=val" # API keys/headers
|
|
302
|
-
SECURENOW_NO_UUID=1 # Don't append UUID
|
|
303
|
-
OTEL_LOG_LEVEL=info # debug|info|warn|error
|
|
304
|
-
SECURENOW_DISABLE_INSTRUMENTATIONS=fs # Comma-separated
|
|
305
|
-
SECURENOW_TEST_SPAN=1 # Test span on startup
|
|
306
|
-
```
|
|
307
|
-
|
|
308
|
-
---
|
|
309
|
-
|
|
310
|
-
## 💡 Best Practices
|
|
311
|
-
|
|
312
|
-
### ✅ DO
|
|
313
|
-
- Use descriptive app names: `checkout-service`, `user-api`
|
|
314
|
-
- Set `SECURENOW_APPID` in production
|
|
315
|
-
- Keep UUID enabled in production (unique per deployment)
|
|
316
|
-
- Use `OTEL_LOG_LEVEL=info` or `warn` in production
|
|
317
|
-
|
|
318
|
-
### ❌ DON'T
|
|
319
|
-
- Use generic names: `app`, `test`, `api`
|
|
320
|
-
- Hardcode API keys in code
|
|
321
|
-
- Disable important instrumentations without reason
|
|
322
|
-
- Use `OTEL_LOG_LEVEL=debug` in production (too verbose)
|
|
323
|
-
|
|
324
|
-
---
|
|
325
|
-
|
|
326
|
-
## 📚 More Resources
|
|
327
|
-
|
|
328
|
-
- **[Complete Guide](./NEXTJS-GUIDE.md)** - In-depth documentation
|
|
329
|
-
- **[Quick Start](./NEXTJS-QUICKSTART.md)** - Condensed version
|
|
330
|
-
- **[Examples](./examples/)** - Code examples
|
|
331
|
-
- **[Architecture](./ARCHITECTURE.md)** - How it works
|
|
332
|
-
|
|
333
|
-
---
|
|
334
|
-
|
|
335
|
-
## 🆘 Need Help?
|
|
336
|
-
|
|
337
|
-
- **Documentation:** [Full guides](./NEXTJS-GUIDE.md)
|
|
338
|
-
- **Examples:** See `examples/` folder
|
|
339
|
-
- **SecureNow:** [securenow.ai](https://securenow.ai/)
|
|
340
|
-
|
|
341
|
-
---
|
|
342
|
-
|
|
343
|
-
## ✨ Why SecureNow?
|
|
344
|
-
|
|
345
|
-
| Feature | SecureNow | Manual Setup | @vercel/otel |
|
|
346
|
-
|---------|-----------|--------------|--------------|
|
|
347
|
-
| Lines of code | 3 | 100+ | 20+ |
|
|
348
|
-
| Setup time | 2 min | 1-2 hours | 30 min |
|
|
349
|
-
| Auto-instrumentation | 30+ libs | Manual | Limited |
|
|
350
|
-
| Configuration | Env vars | Complex | Medium |
|
|
351
|
-
| Production ready | ✅ Yes | Depends | ✅ Yes |
|
|
352
|
-
|
|
353
|
-
**Choose SecureNow for the easiest setup!**
|
|
354
|
-
|
|
355
|
-
---
|
|
356
|
-
|
|
357
|
-
<div align="center">
|
|
358
|
-
|
|
359
|
-
**Made with ❤️ for Next.js and SecureNow**
|
|
360
|
-
|
|
361
|
-
[Website](http://securenow.ai/) • [NPM](https://www.npmjs.com/package/securenow) • [Documentation](./NEXTJS-GUIDE.md)
|
|
362
|
-
|
|
363
|
-
</div>
|
|
364
|
-
|
package/docs/EASIEST-SETUP.md
DELETED
|
@@ -1,342 +0,0 @@
|
|
|
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-otlp-backend: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 SecureNow (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://otel-collector: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://otel-collector:4318
|
|
252
|
-
SECURENOW_CAPTURE_BODY=1
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
### 4. Run App
|
|
256
|
-
|
|
257
|
-
```bash
|
|
258
|
-
npm run dev
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
### 5. Check SecureNow
|
|
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
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|