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 ADDED
@@ -0,0 +1,416 @@
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
+
415
+
416
+