securenow 3.0.14 → 4.0.2
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 +416 -0
- package/AUTOMATIC-IP-CAPTURE.md +356 -0
- package/CUSTOMER-GUIDE.md +341 -0
- package/NEXTJS-GUIDE.md +379 -0
- package/NEXTJS-QUICKSTART.md +67 -0
- package/README.md +145 -22
- package/cli.js +264 -0
- package/examples/README.md +262 -0
- package/examples/next.config.js +34 -0
- package/examples/nextjs-env-example.txt +31 -0
- package/examples/nextjs-instrumentation.js +33 -0
- package/examples/nextjs-instrumentation.ts +33 -0
- package/examples/nextjs-with-options.ts +33 -0
- package/examples/test-nextjs-setup.js +67 -0
- package/nextjs.js +203 -0
- package/package.json +90 -44
- package/postinstall.js +215 -0
|
@@ -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,341 @@
|
|
|
1
|
+
# 🚀 Add Observability to Your Next.js App in 2 Minutes
|
|
2
|
+
|
|
3
|
+
**Send traces to SigNoz 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-signoz:4318 # Your SigNoz 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-signoz: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 **SigNoz 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
|
+
### ✅ Next.js Built-in Spans
|
|
129
|
+
- HTTP requests
|
|
130
|
+
- API routes
|
|
131
|
+
- Page rendering
|
|
132
|
+
- Server-side props
|
|
133
|
+
- Metadata generation
|
|
134
|
+
- Time to First Byte (TTFB)
|
|
135
|
+
|
|
136
|
+
### ✅ Backend Instrumentation
|
|
137
|
+
- **Databases:** PostgreSQL, MySQL, MongoDB, Redis
|
|
138
|
+
- **HTTP Calls:** fetch, axios, http/https
|
|
139
|
+
- **GraphQL** queries
|
|
140
|
+
- **gRPC** calls
|
|
141
|
+
- **And 30+ more libraries**
|
|
142
|
+
|
|
143
|
+
No additional code needed!
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## ⚙️ Optional: Add Authentication
|
|
148
|
+
|
|
149
|
+
If your SigNoz server requires an API key:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# Add to .env.local
|
|
153
|
+
OTEL_EXPORTER_OTLP_HEADERS="x-api-key=your-api-key-here"
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## 🔧 Optional: Advanced Configuration
|
|
159
|
+
|
|
160
|
+
Want more control? You can pass options:
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import { registerSecureNow } from 'securenow/nextjs';
|
|
164
|
+
|
|
165
|
+
export function register() {
|
|
166
|
+
registerSecureNow({
|
|
167
|
+
serviceName: 'my-app',
|
|
168
|
+
endpoint: 'http://signoz:4318',
|
|
169
|
+
headers: {
|
|
170
|
+
'x-api-key': process.env.SIGNOZ_API_KEY || '',
|
|
171
|
+
},
|
|
172
|
+
disableInstrumentations: ['fs'], // Optional: disable specific instrumentations
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## 🚨 Troubleshooting
|
|
180
|
+
|
|
181
|
+
### Not seeing traces?
|
|
182
|
+
|
|
183
|
+
**1. Check the console output**
|
|
184
|
+
```bash
|
|
185
|
+
npm run dev
|
|
186
|
+
# Look for: [securenow] ✅ OpenTelemetry started
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**2. Enable debug mode**
|
|
190
|
+
```bash
|
|
191
|
+
# Add to .env.local
|
|
192
|
+
OTEL_LOG_LEVEL=debug
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**3. Create a test span**
|
|
196
|
+
```bash
|
|
197
|
+
# Add to .env.local
|
|
198
|
+
SECURENOW_TEST_SPAN=1
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
**4. Verify SigNoz is accessible**
|
|
202
|
+
```bash
|
|
203
|
+
curl http://your-signoz-server:4318/v1/traces
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## 🎯 Next.js Version Requirements
|
|
209
|
+
|
|
210
|
+
| Next.js Version | Setup Required |
|
|
211
|
+
|----------------|----------------|
|
|
212
|
+
| **Next.js 15+** | ✅ Just create `instrumentation.ts` |
|
|
213
|
+
| **Next.js 14 and below** | ⚠️ Also add to `next.config.js`: |
|
|
214
|
+
|
|
215
|
+
For Next.js 14 and below, update `next.config.js`:
|
|
216
|
+
|
|
217
|
+
```javascript
|
|
218
|
+
const nextConfig = {
|
|
219
|
+
experimental: {
|
|
220
|
+
instrumentationHook: true, // Required for Next.js 14 and below
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
module.exports = nextConfig;
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## ☁️ Deployment
|
|
230
|
+
|
|
231
|
+
### Vercel
|
|
232
|
+
|
|
233
|
+
1. Go to your Vercel project settings
|
|
234
|
+
2. Add environment variables:
|
|
235
|
+
- `SECURENOW_APPID=my-nextjs-app`
|
|
236
|
+
- `SECURENOW_INSTANCE=http://your-signoz:4318`
|
|
237
|
+
3. Redeploy
|
|
238
|
+
|
|
239
|
+
**Done!** Traces will appear in SigNoz.
|
|
240
|
+
|
|
241
|
+
### Docker
|
|
242
|
+
|
|
243
|
+
```dockerfile
|
|
244
|
+
FROM node:20-alpine
|
|
245
|
+
WORKDIR /app
|
|
246
|
+
|
|
247
|
+
COPY package*.json ./
|
|
248
|
+
RUN npm ci --production
|
|
249
|
+
|
|
250
|
+
COPY . .
|
|
251
|
+
RUN npm run build
|
|
252
|
+
|
|
253
|
+
ENV SECURENOW_APPID=my-nextjs-app
|
|
254
|
+
ENV SECURENOW_INSTANCE=http://signoz:4318
|
|
255
|
+
|
|
256
|
+
EXPOSE 3000
|
|
257
|
+
CMD ["npm", "start"]
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Self-Hosted / VPS
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
export SECURENOW_APPID=my-nextjs-app
|
|
264
|
+
export SECURENOW_INSTANCE=http://your-signoz:4318
|
|
265
|
+
npm start
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## 🎓 Environment Variables Reference
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
# ===== REQUIRED =====
|
|
274
|
+
SECURENOW_APPID=my-app-name # Your app identifier
|
|
275
|
+
SECURENOW_INSTANCE=http://host:4318 # SigNoz endpoint
|
|
276
|
+
|
|
277
|
+
# ===== OPTIONAL =====
|
|
278
|
+
OTEL_EXPORTER_OTLP_HEADERS="key=val" # API keys/headers
|
|
279
|
+
SECURENOW_NO_UUID=1 # Don't append UUID
|
|
280
|
+
OTEL_LOG_LEVEL=info # debug|info|warn|error
|
|
281
|
+
SECURENOW_DISABLE_INSTRUMENTATIONS=fs # Comma-separated
|
|
282
|
+
SECURENOW_TEST_SPAN=1 # Test span on startup
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## 💡 Best Practices
|
|
288
|
+
|
|
289
|
+
### ✅ DO
|
|
290
|
+
- Use descriptive app names: `checkout-service`, `user-api`
|
|
291
|
+
- Set `SECURENOW_APPID` in production
|
|
292
|
+
- Keep UUID enabled in production (unique per deployment)
|
|
293
|
+
- Use `OTEL_LOG_LEVEL=info` or `warn` in production
|
|
294
|
+
|
|
295
|
+
### ❌ DON'T
|
|
296
|
+
- Use generic names: `app`, `test`, `api`
|
|
297
|
+
- Hardcode API keys in code
|
|
298
|
+
- Disable important instrumentations without reason
|
|
299
|
+
- Use `OTEL_LOG_LEVEL=debug` in production (too verbose)
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## 📚 More Resources
|
|
304
|
+
|
|
305
|
+
- **[Complete Guide](./NEXTJS-GUIDE.md)** - In-depth documentation
|
|
306
|
+
- **[Quick Start](./NEXTJS-QUICKSTART.md)** - Condensed version
|
|
307
|
+
- **[Examples](./examples/)** - Code examples
|
|
308
|
+
- **[Architecture](./ARCHITECTURE.md)** - How it works
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## 🆘 Need Help?
|
|
313
|
+
|
|
314
|
+
- **Documentation:** [Full guides](./NEXTJS-GUIDE.md)
|
|
315
|
+
- **Examples:** See `examples/` folder
|
|
316
|
+
- **SigNoz Docs:** [signoz.io/docs](https://signoz.io/docs/)
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
## ✨ Why SecureNow?
|
|
321
|
+
|
|
322
|
+
| Feature | SecureNow | Manual Setup | @vercel/otel |
|
|
323
|
+
|---------|-----------|--------------|--------------|
|
|
324
|
+
| Lines of code | 3 | 100+ | 20+ |
|
|
325
|
+
| Setup time | 2 min | 1-2 hours | 30 min |
|
|
326
|
+
| Auto-instrumentation | 30+ libs | Manual | Limited |
|
|
327
|
+
| Configuration | Env vars | Complex | Medium |
|
|
328
|
+
| Production ready | ✅ Yes | Depends | ✅ Yes |
|
|
329
|
+
|
|
330
|
+
**Choose SecureNow for the easiest setup!**
|
|
331
|
+
|
|
332
|
+
---
|
|
333
|
+
|
|
334
|
+
<div align="center">
|
|
335
|
+
|
|
336
|
+
**Made with ❤️ for Next.js and SigNoz**
|
|
337
|
+
|
|
338
|
+
[Website](http://securenow.ai/) • [NPM](https://www.npmjs.com/package/securenow) • [Documentation](./NEXTJS-GUIDE.md)
|
|
339
|
+
|
|
340
|
+
</div>
|
|
341
|
+
|