securenow 4.0.1 → 4.0.3

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/AUTO-SETUP.md CHANGED
@@ -412,3 +412,5 @@ npx securenow init
412
412
  **That's it!** 🎉
413
413
 
414
414
 
415
+
416
+
@@ -0,0 +1,356 @@
1
+ # 📊 Automatic IP and Request Metadata Capture
2
+
3
+ SecureNow automatically captures user IP addresses and detailed request metadata in your Next.js traces!
4
+
5
+ ---
6
+
7
+ ## ✅ What Gets Captured Automatically
8
+
9
+ ### 🌐 Client Information
10
+ - **IP Address** (`http.client_ip`)
11
+ - From `x-forwarded-for` (Vercel, most proxies)
12
+ - From `x-real-ip`
13
+ - From `cf-connecting-ip` (Cloudflare)
14
+ - From `x-client-ip`
15
+ - From socket `remoteAddress`
16
+
17
+ ### 📱 Request Details
18
+ - **User Agent** (`http.user_agent`) - Browser/device info
19
+ - **Referer** (`http.referer`) - Where the user came from
20
+ - **Host** (`http.host`) - Your domain
21
+ - **Scheme** (`http.scheme`) - http or https
22
+ - **Request ID** (`http.request_id`) - Correlation ID if present
23
+
24
+ ### 🌍 Geographic Data (when available)
25
+ - **Country** (`http.geo.country`)
26
+ - From Vercel: `x-vercel-ip-country`
27
+ - From Cloudflare: `cf-ipcountry`
28
+ - **Region** (`http.geo.region`) - From `x-vercel-ip-country-region`
29
+ - **City** (`http.geo.city`) - From `x-vercel-ip-city`
30
+
31
+ ### 📊 Response Data
32
+ - **Status Code** (`http.status_code`) - 200, 404, 500, etc.
33
+
34
+ ---
35
+
36
+ ## 🚀 Usage
37
+
38
+ **No configuration needed!** Just use SecureNow:
39
+
40
+ ```typescript
41
+ // instrumentation.ts
42
+ import { registerSecureNow } from 'securenow/nextjs';
43
+
44
+ export function register() {
45
+ registerSecureNow();
46
+ }
47
+ ```
48
+
49
+ That's it! All request metadata is automatically captured.
50
+
51
+ ---
52
+
53
+ ## 📈 View in SigNoz
54
+
55
+ In your SigNoz dashboard, you'll see these attributes on every span:
56
+
57
+ ```json
58
+ {
59
+ "http.client_ip": "203.0.113.45",
60
+ "http.user_agent": "Mozilla/5.0...",
61
+ "http.referer": "https://google.com",
62
+ "http.host": "your-app.vercel.app",
63
+ "http.scheme": "https",
64
+ "http.status_code": 200,
65
+ "http.geo.country": "US",
66
+ "http.geo.region": "CA",
67
+ "http.geo.city": "San Francisco"
68
+ }
69
+ ```
70
+
71
+ ---
72
+
73
+ ## 🔍 Use Cases
74
+
75
+ ### 1. Debug Location-Specific Issues
76
+ Filter traces by country/region to debug geographic problems:
77
+ ```
78
+ http.geo.country = "JP" AND http.status_code >= 500
79
+ ```
80
+
81
+ ### 2. Track User Journey
82
+ Follow a specific user through your app using IP:
83
+ ```
84
+ http.client_ip = "203.0.113.45"
85
+ ```
86
+
87
+ ### 3. Monitor Bot Traffic
88
+ Identify and filter bot requests:
89
+ ```
90
+ http.user_agent CONTAINS "bot" OR http.user_agent CONTAINS "crawler"
91
+ ```
92
+
93
+ ### 4. Analyze Referer Sources
94
+ See where your traffic comes from:
95
+ ```
96
+ GROUP BY http.referer
97
+ ```
98
+
99
+ ### 5. Performance by Region
100
+ Compare response times across regions:
101
+ ```
102
+ AVG(duration) GROUP BY http.geo.country
103
+ ```
104
+
105
+ ---
106
+
107
+ ## 🛠️ Customization
108
+
109
+ ### Option 1: Add More Attributes
110
+
111
+ You can add custom attributes in your Next.js code:
112
+
113
+ ```typescript
114
+ // In your API route or server component
115
+ import { trace } from '@opentelemetry/api';
116
+
117
+ export async function GET(request: Request) {
118
+ const span = trace.getActiveSpan();
119
+
120
+ if (span) {
121
+ // Add custom attributes
122
+ span.setAttributes({
123
+ 'user.id': getUserId(request),
124
+ 'user.subscription': 'premium',
125
+ 'request.path': new URL(request.url).pathname,
126
+ });
127
+ }
128
+
129
+ // Your code...
130
+ }
131
+ ```
132
+
133
+ ### Option 2: Disable Auto-Capture
134
+
135
+ If you don't want automatic IP capture, you can use a simpler configuration:
136
+
137
+ ```typescript
138
+ // instrumentation.ts
139
+ import { registerSecureNow } from 'securenow/nextjs';
140
+
141
+ export function register() {
142
+ // This will use the simple @vercel/otel default
143
+ // (no automatic IP capture)
144
+ process.env.SECURENOW_SIMPLE_MODE = '1';
145
+ registerSecureNow();
146
+ }
147
+ ```
148
+
149
+ ---
150
+
151
+ ## 🔒 Privacy Considerations
152
+
153
+ ### IP Address Handling
154
+
155
+ **By default, SecureNow captures IP addresses.** Consider these privacy aspects:
156
+
157
+ 1. **GDPR Compliance**
158
+ - IP addresses are considered personal data under GDPR
159
+ - Ensure you have legal basis for processing
160
+ - Consider anonymizing IPs in some regions
161
+
162
+ 2. **Data Retention**
163
+ - Configure SigNoz retention policies
164
+ - Consider shorter retention for IP data
165
+
166
+ 3. **Anonymization Option**
167
+
168
+ ```typescript
169
+ // Custom middleware to anonymize IPs
170
+ import { trace } from '@opentelemetry/api';
171
+
172
+ export function middleware(request: NextRequest) {
173
+ const span = trace.getActiveSpan();
174
+
175
+ if (span) {
176
+ const ip = request.ip || 'unknown';
177
+ // Anonymize last octet: 203.0.113.45 → 203.0.113.0
178
+ const anonymized = ip.replace(/\.\d+$/, '.0');
179
+ span.setAttribute('http.client_ip', anonymized);
180
+ }
181
+
182
+ return NextResponse.next();
183
+ }
184
+ ```
185
+
186
+ ---
187
+
188
+ ## 🎯 Examples
189
+
190
+ ### Example 1: Geographic Load Balancing Debugging
191
+
192
+ **Problem:** Users in Asia report slow performance
193
+
194
+ **Solution:** Query traces by region
195
+ ```
196
+ http.geo.country IN ["JP", "CN", "KR"]
197
+ AND duration > 1000ms
198
+ ```
199
+
200
+ ### Example 2: Bot Detection
201
+
202
+ **Problem:** Suspicious traffic patterns
203
+
204
+ **Solution:** Filter by user agent
205
+ ```
206
+ http.user_agent CONTAINS "bot"
207
+ OR http.user_agent CONTAINS "crawler"
208
+ OR http.user_agent CONTAINS "spider"
209
+ ```
210
+
211
+ ### Example 3: Referer Analysis
212
+
213
+ **Problem:** Want to track marketing campaigns
214
+
215
+ **Solution:** Group by referer
216
+ ```
217
+ http.referer CONTAINS "utm_source"
218
+ GROUP BY http.referer
219
+ ```
220
+
221
+ ### Example 4: Rate Limiting Analysis
222
+
223
+ **Problem:** Need to identify IPs hitting rate limits
224
+
225
+ **Solution:** Track by IP and status
226
+ ```
227
+ http.status_code = 429
228
+ GROUP BY http.client_ip
229
+ ORDER BY COUNT DESC
230
+ ```
231
+
232
+ ---
233
+
234
+ ## 📊 Dashboard Queries
235
+
236
+ ### Top Countries by Traffic
237
+ ```sql
238
+ SELECT
239
+ http.geo.country,
240
+ COUNT(*) as requests,
241
+ AVG(duration) as avg_duration
242
+ FROM spans
243
+ WHERE http.geo.country IS NOT NULL
244
+ GROUP BY http.geo.country
245
+ ORDER BY requests DESC
246
+ LIMIT 10
247
+ ```
248
+
249
+ ### Slowest Requests by Region
250
+ ```sql
251
+ SELECT
252
+ http.geo.country,
253
+ http.target,
254
+ MAX(duration) as max_duration
255
+ FROM spans
256
+ WHERE http.geo.country IS NOT NULL
257
+ GROUP BY http.geo.country, http.target
258
+ ORDER BY max_duration DESC
259
+ LIMIT 20
260
+ ```
261
+
262
+ ### Error Rate by User Agent
263
+ ```sql
264
+ SELECT
265
+ http.user_agent,
266
+ COUNT(*) as total,
267
+ SUM(CASE WHEN http.status_code >= 400 THEN 1 ELSE 0 END) as errors,
268
+ (errors / total * 100) as error_rate
269
+ FROM spans
270
+ GROUP BY http.user_agent
271
+ ORDER BY error_rate DESC
272
+ LIMIT 10
273
+ ```
274
+
275
+ ---
276
+
277
+ ## 🔧 Technical Details
278
+
279
+ ### How It Works
280
+
281
+ 1. **HttpInstrumentation** intercepts incoming HTTP requests
282
+ 2. **requestHook** extracts headers and metadata
283
+ 3. **Attributes** are added to the active span
284
+ 4. **Data flows** to SigNoz with the trace
285
+
286
+ ### Headers Priority
287
+
288
+ IP address is extracted in this order:
289
+ 1. `x-forwarded-for` (first IP in list)
290
+ 2. `x-real-ip`
291
+ 3. `cf-connecting-ip` (Cloudflare)
292
+ 4. `x-client-ip`
293
+ 5. `socket.remoteAddress`
294
+
295
+ ### Performance Impact
296
+
297
+ - **Minimal overhead:** < 1ms per request
298
+ - **No blocking:** Runs async with request processing
299
+ - **Fail-safe:** Errors don't break requests
300
+
301
+ ---
302
+
303
+ ## ❓ FAQ
304
+
305
+ ### Q: Is this GDPR compliant?
306
+
307
+ **A:** IP addresses are personal data. Ensure you:
308
+ - Have legal basis (legitimate interest, consent, etc.)
309
+ - Document in privacy policy
310
+ - Configure appropriate retention
311
+ - Consider anonymization for EU users
312
+
313
+ ### Q: Can I disable IP capture?
314
+
315
+ **A:** Yes, use simple mode:
316
+ ```typescript
317
+ process.env.SECURENOW_SIMPLE_MODE = '1';
318
+ registerSecureNow();
319
+ ```
320
+
321
+ ### Q: Does this work on Edge Runtime?
322
+
323
+ **A:** Currently only Node.js runtime is supported. Edge runtime support coming soon.
324
+
325
+ ### Q: What about bot traffic?
326
+
327
+ **A:** Bot traffic is captured automatically. Filter using:
328
+ ```
329
+ http.user_agent NOT CONTAINS "bot"
330
+ ```
331
+
332
+ ### Q: Can I capture custom headers?
333
+
334
+ **A:** Yes! Use OpenTelemetry API:
335
+ ```typescript
336
+ import { trace } from '@opentelemetry/api';
337
+
338
+ const span = trace.getActiveSpan();
339
+ span.setAttribute('custom.header', request.headers.get('x-custom'));
340
+ ```
341
+
342
+ ---
343
+
344
+ ## 🎉 Summary
345
+
346
+ SecureNow automatically captures:
347
+ - ✅ IP addresses (multiple sources)
348
+ - ✅ User agents
349
+ - ✅ Referers
350
+ - ✅ Geographic data (Vercel/Cloudflare)
351
+ - ✅ Request/response metadata
352
+
353
+ **Zero configuration required** - it just works!
354
+
355
+ View everything in SigNoz for powerful analytics and debugging.
356
+
@@ -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
@@ -110,6 +110,40 @@ Open your **SigNoz dashboard** and you'll see traces immediately!
110
110
 
111
111
  ## 📊 What You Get Automatically
112
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:** `SECURENOW_CAPTURE_BODY=1` in `.env.local`
137
+
138
+ **Perfect for:**
139
+ - Debugging API issues with exact inputs
140
+ - Monitoring GraphQL query patterns
141
+ - Understanding user input behavior
142
+ - Validating request schemas
143
+ - Troubleshooting edge cases
144
+
145
+ See [REQUEST-BODY-CAPTURE.md](./REQUEST-BODY-CAPTURE.md)
146
+
113
147
  ### ✅ Next.js Built-in Spans
114
148
  - HTTP requests
115
149
  - API routes
package/NEXTJS-GUIDE.md CHANGED
@@ -99,9 +99,29 @@ You should see:
99
99
 
100
100
  ---
101
101
 
102
- ## 📊 What Gets Automatically Instrumented?
102
+ ## 📊 What Gets Automatically Captured?
103
103
 
104
- SecureNow uses OpenTelemetry's auto-instrumentation to capture:
104
+ SecureNow automatically captures comprehensive request data:
105
+
106
+ ### 🌐 User Information (Automatic!)
107
+ - **IP Address** - From x-forwarded-for, x-real-ip, etc.
108
+ - **User Agent** - Browser and device info
109
+ - **Referer** - Where users came from
110
+ - **Geographic Data** - Country, region, city (Vercel/Cloudflare)
111
+ - **Request Metadata** - Headers, host, scheme
112
+ - **Response Data** - Status codes, timing
113
+
114
+ See [AUTOMATIC-IP-CAPTURE.md](./AUTOMATIC-IP-CAPTURE.md) for full details.
115
+
116
+ ### 📝 Request Body Capture (Optional!)
117
+ - **JSON Bodies** - API payloads with sensitive fields redacted
118
+ - **GraphQL Queries** - Full query capture
119
+ - **Form Data** - Form submissions
120
+ - **Auto-Redaction** - Passwords, tokens, cards automatically hidden
121
+
122
+ Enable with: `SECURENOW_CAPTURE_BODY=1`
123
+
124
+ See [REQUEST-BODY-CAPTURE.md](./REQUEST-BODY-CAPTURE.md) for full details.
105
125
 
106
126
  ### Next.js Built-in Spans
107
127
  - ✅ HTTP requests (`[http.method] [next.route]`)
@@ -35,7 +35,7 @@ export function register() { registerSecureNow(); }
35
35
 
36
36
  ```bash
37
37
  SECURENOW_APPID=my-nextjs-app
38
- SECURENOW_INSTANCE=http://your-signoz:4318
38
+ SECURENOW_INSTANCE=http://your-securenow:4318
39
39
  ```
40
40
 
41
41
  ### 3. (Next.js 14 only) Update `next.config.js`: