securenow 3.0.14 → 4.0.1

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 ADDED
@@ -0,0 +1,414 @@
1
+ # SecureNow Auto-Setup Guide
2
+
3
+ SecureNow can automatically create the instrumentation file for your Next.js project! Choose the method that works best for you.
4
+
5
+ ---
6
+
7
+ ## 🎯 Three Ways to Setup
8
+
9
+ ### 1. ✨ Automatic Setup (Recommended)
10
+
11
+ **Happens automatically when you install:**
12
+
13
+ ```bash
14
+ npm install securenow
15
+ ```
16
+
17
+ **What happens:**
18
+ 1. Installer detects Next.js project
19
+ 2. Asks: "Would you like to automatically create instrumentation file? (Y/n)"
20
+ 3. Creates `instrumentation.ts` (or `.js`) in the right location
21
+ 4. Creates `.env.local` template
22
+ 5. Shows next steps
23
+
24
+ **Example output:**
25
+ ```
26
+ ┌─────────────────────────────────────────────────┐
27
+ │ 🎉 SecureNow installed successfully! │
28
+ │ Next.js project detected │
29
+ └─────────────────────────────────────────────────┘
30
+
31
+ Would you like to automatically create instrumentation file? (Y/n) Y
32
+
33
+ ✅ Created instrumentation.ts
34
+ ✅ Created .env.local template
35
+
36
+ ┌─────────────────────────────────────────────────┐
37
+ │ 🚀 Next Steps: │
38
+ │ │
39
+ │ 1. Edit .env.local and set: │
40
+ │ SECURENOW_APPID=your-app-name │
41
+ │ SECURENOW_INSTANCE=http://signoz:4318 │
42
+ │ │
43
+ │ 2. Run your app: npm run dev │
44
+ │ │
45
+ │ 3. Check SigNoz for traces! │
46
+ └─────────────────────────────────────────────────┘
47
+ ```
48
+
49
+ ---
50
+
51
+ ### 2. 🛠️ CLI Command (Manual but Easy)
52
+
53
+ **If you skipped auto-setup or want to setup later:**
54
+
55
+ ```bash
56
+ npx securenow init
57
+ ```
58
+
59
+ **Options:**
60
+
61
+ ```bash
62
+ # Force TypeScript
63
+ npx securenow init --typescript
64
+
65
+ # Force JavaScript
66
+ npx securenow init --javascript
67
+
68
+ # Create in src/ folder
69
+ npx securenow init --src
70
+
71
+ # Create in root folder
72
+ npx securenow init --root
73
+
74
+ # Overwrite existing files
75
+ npx securenow init --force
76
+
77
+ # Combine options
78
+ npx securenow init --typescript --src
79
+ ```
80
+
81
+ **Example:**
82
+ ```bash
83
+ $ npx securenow init
84
+
85
+ 🚀 SecureNow Setup
86
+
87
+ ✅ Created instrumentation.ts
88
+ ✅ Created .env.local template
89
+
90
+ ┌─────────────────────────────────────────────────┐
91
+ │ 🎉 Setup Complete! │
92
+ │ │
93
+ │ Next steps: │
94
+ │ 1. Edit .env.local and configure │
95
+ │ 2. Start your app: npm run dev │
96
+ │ 3. Check SigNoz dashboard for traces! │
97
+ └─────────────────────────────────────────────────┘
98
+ ```
99
+
100
+ ---
101
+
102
+ ### 3. 📝 Manual Creation
103
+
104
+ **Create the file yourself:**
105
+
106
+ ```typescript
107
+ // instrumentation.ts (at project root)
108
+ import { registerSecureNow } from 'securenow/nextjs';
109
+
110
+ export function register() {
111
+ registerSecureNow();
112
+ }
113
+ ```
114
+
115
+ ```bash
116
+ # .env.local
117
+ SECURENOW_APPID=my-nextjs-app
118
+ SECURENOW_INSTANCE=http://your-signoz:4318
119
+ ```
120
+
121
+ ---
122
+
123
+ ## 🤖 Auto-Setup Behavior
124
+
125
+ ### Detection Logic
126
+
127
+ The postinstall script checks:
128
+
129
+ 1. **Is this a Next.js project?**
130
+ - Looks for `next` in package.json dependencies
131
+
132
+ 2. **Does instrumentation file already exist?**
133
+ - Checks for: `instrumentation.ts`, `instrumentation.js`
134
+ - Checks in: root and `src/` folder
135
+
136
+ 3. **Is this an interactive environment?**
137
+ - Skips in CI/CD environments
138
+ - Skips if stdin is not a TTY
139
+
140
+ ### Smart Defaults
141
+
142
+ - **TypeScript vs JavaScript**
143
+ - Detects `tsconfig.json` → creates `.ts` file
144
+ - No tsconfig → creates `.js` file
145
+
146
+ - **Root vs src/ folder**
147
+ - If `src/` folder exists → creates file there
148
+ - Otherwise → creates in root
149
+
150
+ - **.env.local handling**
151
+ - Only creates if it doesn't exist
152
+ - Never overwrites existing `.env.local`
153
+
154
+ ### Non-Interactive Environments
155
+
156
+ In CI/CD or non-interactive environments:
157
+
158
+ ```bash
159
+ [securenow] ℹ️ Non-interactive environment detected
160
+ [securenow] 💡 To complete setup, run: npx securenow init
161
+ ```
162
+
163
+ ---
164
+
165
+ ## 🎛️ CLI Reference
166
+
167
+ ### Commands
168
+
169
+ ```bash
170
+ npx securenow init # Initialize setup
171
+ npx securenow help # Show help
172
+ npx securenow version # Show version
173
+ ```
174
+
175
+ ### Flags
176
+
177
+ | Flag | Description |
178
+ |------|-------------|
179
+ | `--typescript`, `--ts` | Force TypeScript file |
180
+ | `--javascript`, `--js` | Force JavaScript file |
181
+ | `--src` | Create in src/ folder |
182
+ | `--root` | Create in root folder |
183
+ | `--force`, `-f` | Overwrite existing files |
184
+
185
+ ### Examples
186
+
187
+ **Basic setup:**
188
+ ```bash
189
+ npx securenow init
190
+ ```
191
+
192
+ **TypeScript in src folder:**
193
+ ```bash
194
+ npx securenow init --typescript --src
195
+ ```
196
+
197
+ **JavaScript in root:**
198
+ ```bash
199
+ npx securenow init --javascript --root
200
+ ```
201
+
202
+ **Force overwrite:**
203
+ ```bash
204
+ npx securenow init --force
205
+ ```
206
+
207
+ **Not a Next.js project but want to proceed:**
208
+ ```bash
209
+ npx securenow init --force
210
+ ```
211
+
212
+ ---
213
+
214
+ ## 🔧 Configuration
215
+
216
+ ### Disable Auto-Setup
217
+
218
+ If you never want auto-setup to run:
219
+
220
+ **Option 1: Environment variable**
221
+ ```bash
222
+ SECURENOW_NO_POSTINSTALL=1 npm install securenow
223
+ ```
224
+
225
+ **Option 2: npm config**
226
+ ```bash
227
+ npm install securenow --ignore-scripts
228
+ ```
229
+
230
+ **Option 3: Answer "n" when prompted**
231
+ ```
232
+ Would you like to automatically create instrumentation file? (Y/n) n
233
+
234
+ [securenow] No problem! To setup later, run: npx securenow init
235
+ ```
236
+
237
+ ---
238
+
239
+ ## 📂 File Locations
240
+
241
+ The installer chooses locations automatically:
242
+
243
+ ### TypeScript Projects
244
+
245
+ ```
246
+ my-nextjs-app/
247
+ ├── instrumentation.ts ← Created here (no src/)
248
+ └── .env.local ← Created here
249
+ ```
250
+
251
+ or with src/ folder:
252
+
253
+ ```
254
+ my-nextjs-app/
255
+ ├── src/
256
+ │ └── instrumentation.ts ← Created here (with src/)
257
+ └── .env.local ← Created here
258
+ ```
259
+
260
+ ### JavaScript Projects
261
+
262
+ ```
263
+ my-nextjs-app/
264
+ ├── instrumentation.js ← Created here
265
+ └── .env.local ← Created here
266
+ ```
267
+
268
+ ---
269
+
270
+ ## 🚨 Troubleshooting
271
+
272
+ ### Auto-setup didn't run
273
+
274
+ **Possible reasons:**
275
+
276
+ 1. **Not a Next.js project**
277
+ - Install `next` first, then install `securenow`
278
+ - Or use: `npx securenow init --force`
279
+
280
+ 2. **CI/CD environment**
281
+ - Run manually: `npx securenow init`
282
+
283
+ 3. **File already exists**
284
+ - Auto-setup skips if file exists
285
+ - Use: `npx securenow init --force` to overwrite
286
+
287
+ 4. **Installation with --ignore-scripts**
288
+ - Run: `npx securenow init`
289
+
290
+ ### CLI command not found
291
+
292
+ ```bash
293
+ # Make sure securenow is installed
294
+ npm list securenow
295
+
296
+ # Run with npx
297
+ npx securenow init
298
+ ```
299
+
300
+ ### Permission errors
301
+
302
+ ```bash
303
+ # On Unix systems, the CLI should be executable
304
+ chmod +x node_modules/securenow/cli.js
305
+
306
+ # Or use npx
307
+ npx securenow init
308
+ ```
309
+
310
+ ---
311
+
312
+ ## 🎯 Comparison
313
+
314
+ | Method | Speed | Flexibility | Best For |
315
+ |--------|-------|-------------|----------|
316
+ | **Auto-setup** | ⚡ Instant | Basic | First-time users |
317
+ | **CLI** | 🚀 Fast | High | Custom setups |
318
+ | **Manual** | 📝 Slow | Full | Advanced users |
319
+
320
+ ---
321
+
322
+ ## 💡 Best Practices
323
+
324
+ ### For Development
325
+
326
+ 1. **Let auto-setup run**
327
+ - Fastest way to get started
328
+ - Creates everything you need
329
+
330
+ 2. **Review generated files**
331
+ - Check `instrumentation.ts`
332
+ - Verify `.env.local` settings
333
+
334
+ 3. **Use CLI for adjustments**
335
+ - `npx securenow init --force` to regenerate
336
+
337
+ ### For Teams
338
+
339
+ 1. **Add to documentation**
340
+ ```md
341
+ ## Setup Observability
342
+ npm install securenow
343
+ # Answer "Y" when prompted
344
+ ```
345
+
346
+ 2. **Share .env.local template**
347
+ - Commit `.env.local.example`
348
+ - Team copies to `.env.local`
349
+
350
+ 3. **CI/CD setup**
351
+ ```bash
352
+ # In CI, skip auto-setup
353
+ npm install --ignore-scripts
354
+
355
+ # Or set env var
356
+ SECURENOW_NO_POSTINSTALL=1 npm install
357
+ ```
358
+
359
+ ### For Monorepos
360
+
361
+ ```bash
362
+ # In each Next.js app
363
+ cd apps/web
364
+ npx securenow init
365
+
366
+ cd apps/admin
367
+ npx securenow init
368
+ ```
369
+
370
+ ---
371
+
372
+ ## 🆘 Need Help?
373
+
374
+ ```bash
375
+ # Get help
376
+ npx securenow help
377
+
378
+ # Check version
379
+ npx securenow version
380
+
381
+ # Re-run setup
382
+ npx securenow init --force
383
+ ```
384
+
385
+ **Documentation:**
386
+ - [Quick Start](./NEXTJS-QUICKSTART.md)
387
+ - [Complete Guide](./NEXTJS-GUIDE.md)
388
+ - [Customer Guide](./CUSTOMER-GUIDE.md)
389
+
390
+ ---
391
+
392
+ ## ✨ Summary
393
+
394
+ **Simplest way:**
395
+ ```bash
396
+ npm install securenow
397
+ # Press Y when asked
398
+ ```
399
+
400
+ **If you need control:**
401
+ ```bash
402
+ npm install securenow
403
+ npx securenow init --typescript --src
404
+ ```
405
+
406
+ **For CI/CD:**
407
+ ```bash
408
+ npm install --ignore-scripts
409
+ npx securenow init
410
+ ```
411
+
412
+ **That's it!** 🎉
413
+
414
+
@@ -0,0 +1,326 @@
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
+ ### ✅ Next.js Built-in Spans
114
+ - HTTP requests
115
+ - API routes
116
+ - Page rendering
117
+ - Server-side props
118
+ - Metadata generation
119
+ - Time to First Byte (TTFB)
120
+
121
+ ### ✅ Backend Instrumentation
122
+ - **Databases:** PostgreSQL, MySQL, MongoDB, Redis
123
+ - **HTTP Calls:** fetch, axios, http/https
124
+ - **GraphQL** queries
125
+ - **gRPC** calls
126
+ - **And 30+ more libraries**
127
+
128
+ No additional code needed!
129
+
130
+ ---
131
+
132
+ ## ⚙️ Optional: Add Authentication
133
+
134
+ If your SigNoz server requires an API key:
135
+
136
+ ```bash
137
+ # Add to .env.local
138
+ OTEL_EXPORTER_OTLP_HEADERS="x-api-key=your-api-key-here"
139
+ ```
140
+
141
+ ---
142
+
143
+ ## 🔧 Optional: Advanced Configuration
144
+
145
+ Want more control? You can pass options:
146
+
147
+ ```typescript
148
+ import { registerSecureNow } from 'securenow/nextjs';
149
+
150
+ export function register() {
151
+ registerSecureNow({
152
+ serviceName: 'my-app',
153
+ endpoint: 'http://signoz:4318',
154
+ headers: {
155
+ 'x-api-key': process.env.SIGNOZ_API_KEY || '',
156
+ },
157
+ disableInstrumentations: ['fs'], // Optional: disable specific instrumentations
158
+ });
159
+ }
160
+ ```
161
+
162
+ ---
163
+
164
+ ## 🚨 Troubleshooting
165
+
166
+ ### Not seeing traces?
167
+
168
+ **1. Check the console output**
169
+ ```bash
170
+ npm run dev
171
+ # Look for: [securenow] ✅ OpenTelemetry started
172
+ ```
173
+
174
+ **2. Enable debug mode**
175
+ ```bash
176
+ # Add to .env.local
177
+ OTEL_LOG_LEVEL=debug
178
+ ```
179
+
180
+ **3. Create a test span**
181
+ ```bash
182
+ # Add to .env.local
183
+ SECURENOW_TEST_SPAN=1
184
+ ```
185
+
186
+ **4. Verify SigNoz is accessible**
187
+ ```bash
188
+ curl http://your-signoz-server:4318/v1/traces
189
+ ```
190
+
191
+ ---
192
+
193
+ ## 🎯 Next.js Version Requirements
194
+
195
+ | Next.js Version | Setup Required |
196
+ |----------------|----------------|
197
+ | **Next.js 15+** | ✅ Just create `instrumentation.ts` |
198
+ | **Next.js 14 and below** | ⚠️ Also add to `next.config.js`: |
199
+
200
+ For Next.js 14 and below, update `next.config.js`:
201
+
202
+ ```javascript
203
+ const nextConfig = {
204
+ experimental: {
205
+ instrumentationHook: true, // Required for Next.js 14 and below
206
+ },
207
+ };
208
+
209
+ module.exports = nextConfig;
210
+ ```
211
+
212
+ ---
213
+
214
+ ## ☁️ Deployment
215
+
216
+ ### Vercel
217
+
218
+ 1. Go to your Vercel project settings
219
+ 2. Add environment variables:
220
+ - `SECURENOW_APPID=my-nextjs-app`
221
+ - `SECURENOW_INSTANCE=http://your-signoz:4318`
222
+ 3. Redeploy
223
+
224
+ **Done!** Traces will appear in SigNoz.
225
+
226
+ ### Docker
227
+
228
+ ```dockerfile
229
+ FROM node:20-alpine
230
+ WORKDIR /app
231
+
232
+ COPY package*.json ./
233
+ RUN npm ci --production
234
+
235
+ COPY . .
236
+ RUN npm run build
237
+
238
+ ENV SECURENOW_APPID=my-nextjs-app
239
+ ENV SECURENOW_INSTANCE=http://signoz:4318
240
+
241
+ EXPOSE 3000
242
+ CMD ["npm", "start"]
243
+ ```
244
+
245
+ ### Self-Hosted / VPS
246
+
247
+ ```bash
248
+ export SECURENOW_APPID=my-nextjs-app
249
+ export SECURENOW_INSTANCE=http://your-signoz:4318
250
+ npm start
251
+ ```
252
+
253
+ ---
254
+
255
+ ## 🎓 Environment Variables Reference
256
+
257
+ ```bash
258
+ # ===== REQUIRED =====
259
+ SECURENOW_APPID=my-app-name # Your app identifier
260
+ SECURENOW_INSTANCE=http://host:4318 # SigNoz endpoint
261
+
262
+ # ===== OPTIONAL =====
263
+ OTEL_EXPORTER_OTLP_HEADERS="key=val" # API keys/headers
264
+ SECURENOW_NO_UUID=1 # Don't append UUID
265
+ OTEL_LOG_LEVEL=info # debug|info|warn|error
266
+ SECURENOW_DISABLE_INSTRUMENTATIONS=fs # Comma-separated
267
+ SECURENOW_TEST_SPAN=1 # Test span on startup
268
+ ```
269
+
270
+ ---
271
+
272
+ ## 💡 Best Practices
273
+
274
+ ### ✅ DO
275
+ - Use descriptive app names: `checkout-service`, `user-api`
276
+ - Set `SECURENOW_APPID` in production
277
+ - Keep UUID enabled in production (unique per deployment)
278
+ - Use `OTEL_LOG_LEVEL=info` or `warn` in production
279
+
280
+ ### ❌ DON'T
281
+ - Use generic names: `app`, `test`, `api`
282
+ - Hardcode API keys in code
283
+ - Disable important instrumentations without reason
284
+ - Use `OTEL_LOG_LEVEL=debug` in production (too verbose)
285
+
286
+ ---
287
+
288
+ ## 📚 More Resources
289
+
290
+ - **[Complete Guide](./NEXTJS-GUIDE.md)** - In-depth documentation
291
+ - **[Quick Start](./NEXTJS-QUICKSTART.md)** - Condensed version
292
+ - **[Examples](./examples/)** - Code examples
293
+ - **[Architecture](./ARCHITECTURE.md)** - How it works
294
+
295
+ ---
296
+
297
+ ## 🆘 Need Help?
298
+
299
+ - **Documentation:** [Full guides](./NEXTJS-GUIDE.md)
300
+ - **Examples:** See `examples/` folder
301
+ - **SigNoz Docs:** [signoz.io/docs](https://signoz.io/docs/)
302
+
303
+ ---
304
+
305
+ ## ✨ Why SecureNow?
306
+
307
+ | Feature | SecureNow | Manual Setup | @vercel/otel |
308
+ |---------|-----------|--------------|--------------|
309
+ | Lines of code | 3 | 100+ | 20+ |
310
+ | Setup time | 2 min | 1-2 hours | 30 min |
311
+ | Auto-instrumentation | 30+ libs | Manual | Limited |
312
+ | Configuration | Env vars | Complex | Medium |
313
+ | Production ready | ✅ Yes | Depends | ✅ Yes |
314
+
315
+ **Choose SecureNow for the easiest setup!**
316
+
317
+ ---
318
+
319
+ <div align="center">
320
+
321
+ **Made with ❤️ for Next.js and SigNoz**
322
+
323
+ [Website](http://securenow.ai/) • [NPM](https://www.npmjs.com/package/securenow) • [Documentation](./NEXTJS-GUIDE.md)
324
+
325
+ </div>
326
+