securenow 5.0.0 → 5.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.
@@ -0,0 +1,455 @@
1
+ # Quick Start Guide - All Frameworks
2
+
3
+ Fast setup guide for SecureNow with any Node.js framework in under 5 minutes.
4
+
5
+ ---
6
+
7
+ ## Universal Setup (Works with Any Framework)
8
+
9
+ ### Step 1: Install
10
+
11
+ ```bash
12
+ npm install securenow
13
+ ```
14
+
15
+ ### Step 2: Set Environment Variables
16
+
17
+ ```bash
18
+ export SECURENOW_APPID=my-app
19
+ export SECURENOW_INSTANCE=http://localhost:4318
20
+ export SECURENOW_LOGGING_ENABLED=1
21
+ ```
22
+
23
+ ### Step 3: Initialize
24
+
25
+ **Option A: Using NODE_OPTIONS (No code changes)**
26
+
27
+ ```bash
28
+ NODE_OPTIONS="-r securenow/register -r securenow/console-instrumentation" node app.js
29
+ ```
30
+
31
+ **Option B: Add to your code**
32
+
33
+ ```javascript
34
+ // At the very top of your main file
35
+ require('securenow/register');
36
+ require('securenow/console-instrumentation');
37
+
38
+ // Rest of your application
39
+ ```
40
+
41
+ **Done!** Your app is now sending traces and logs.
42
+
43
+ ---
44
+
45
+ ## Framework-Specific Quick Starts
46
+
47
+ ### Express.js
48
+
49
+ ```javascript
50
+ // app.js
51
+ require('securenow/register');
52
+ require('securenow/console-instrumentation');
53
+
54
+ const express = require('express');
55
+ const app = express();
56
+
57
+ app.get('/', (req, res) => {
58
+ console.log('Request received');
59
+ res.send('Hello World');
60
+ });
61
+
62
+ app.listen(3000);
63
+ ```
64
+
65
+ **Run:**
66
+ ```bash
67
+ SECURENOW_APPID=express-app \
68
+ SECURENOW_INSTANCE=http://localhost:4318 \
69
+ node app.js
70
+ ```
71
+
72
+ [Full Express Guide →](./EXPRESS-SETUP-GUIDE.md)
73
+
74
+ ---
75
+
76
+ ### Next.js (App Router)
77
+
78
+ **1. Create `instrumentation.ts` in project root:**
79
+
80
+ ```typescript
81
+ export async function register() {
82
+ if (process.env.NEXT_RUNTIME === 'nodejs') {
83
+ process.env.SECURENOW_LOGGING_ENABLED = '1';
84
+ await import('securenow/register');
85
+ await import('securenow/console-instrumentation');
86
+ }
87
+ }
88
+ ```
89
+
90
+ **2. Enable in `next.config.js`:**
91
+
92
+ ```javascript
93
+ module.exports = {
94
+ experimental: {
95
+ instrumentationHook: true,
96
+ },
97
+ };
98
+ ```
99
+
100
+ **3. Create `.env.local`:**
101
+
102
+ ```env
103
+ SECURENOW_APPID=nextjs-app
104
+ SECURENOW_INSTANCE=http://localhost:4318
105
+ ```
106
+
107
+ **4. Run:**
108
+
109
+ ```bash
110
+ npm run dev
111
+ ```
112
+
113
+ [Full Next.js Guide →](./NEXTJS-SETUP-COMPLETE.md)
114
+
115
+ ---
116
+
117
+ ### Fastify
118
+
119
+ ```javascript
120
+ // server.js
121
+ require('securenow/register');
122
+ require('securenow/console-instrumentation');
123
+
124
+ const fastify = require('fastify')();
125
+
126
+ fastify.get('/', async () => {
127
+ console.log('Route called');
128
+ return { hello: 'world' };
129
+ });
130
+
131
+ fastify.listen({ port: 3000 });
132
+ ```
133
+
134
+ **Run:**
135
+ ```bash
136
+ SECURENOW_APPID=fastify-app node server.js
137
+ ```
138
+
139
+ ---
140
+
141
+ ### NestJS
142
+
143
+ ```typescript
144
+ // src/main.ts
145
+ require('securenow/register');
146
+ require('securenow/console-instrumentation');
147
+
148
+ import { NestFactory } from '@nestjs/core';
149
+ import { AppModule } from './app.module';
150
+
151
+ async function bootstrap() {
152
+ const app = await NestFactory.create(AppModule);
153
+ await app.listen(3000);
154
+ }
155
+
156
+ bootstrap();
157
+ ```
158
+
159
+ **Run:**
160
+ ```bash
161
+ npm run start
162
+ ```
163
+
164
+ ---
165
+
166
+ ### Koa
167
+
168
+ ```javascript
169
+ // app.js
170
+ require('securenow/register');
171
+ require('securenow/console-instrumentation');
172
+
173
+ const Koa = require('koa');
174
+ const app = new Koa();
175
+
176
+ app.use(async ctx => {
177
+ console.log('Request received');
178
+ ctx.body = 'Hello World';
179
+ });
180
+
181
+ app.listen(3000);
182
+ ```
183
+
184
+ ---
185
+
186
+ ### Hapi
187
+
188
+ ```javascript
189
+ // server.js
190
+ require('securenow/register');
191
+ require('securenow/console-instrumentation');
192
+
193
+ const Hapi = require('@hapi/hapi');
194
+
195
+ const init = async () => {
196
+ const server = Hapi.server({ port: 3000 });
197
+
198
+ server.route({
199
+ method: 'GET',
200
+ path: '/',
201
+ handler: () => {
202
+ console.log('Route called');
203
+ return 'Hello World';
204
+ }
205
+ });
206
+
207
+ await server.start();
208
+ };
209
+
210
+ init();
211
+ ```
212
+
213
+ ---
214
+
215
+ ## Environment Variables
216
+
217
+ ### Minimal Setup
218
+
219
+ ```bash
220
+ SECURENOW_APPID=my-app
221
+ SECURENOW_INSTANCE=http://localhost:4318
222
+ ```
223
+
224
+ ### Recommended Setup
225
+
226
+ ```bash
227
+ SECURENOW_APPID=my-app
228
+ SECURENOW_INSTANCE=http://localhost:4318
229
+ SECURENOW_LOGGING_ENABLED=1
230
+ SECURENOW_CAPTURE_BODY=1
231
+ NODE_ENV=development
232
+ ```
233
+
234
+ ### Production Setup
235
+
236
+ ```bash
237
+ SECURENOW_APPID=my-app-prod
238
+ SECURENOW_INSTANCE=http://collector.prod:4318
239
+ OTEL_EXPORTER_OTLP_HEADERS=x-api-key=your-key
240
+ SECURENOW_LOGGING_ENABLED=1
241
+ SECURENOW_NO_UUID=1
242
+ SECURENOW_CAPTURE_BODY=0
243
+ NODE_ENV=production
244
+ ```
245
+
246
+ [Complete Environment Variables Reference →](./ENVIRONMENT-VARIABLES.md)
247
+
248
+ ---
249
+
250
+ ## Logging Examples
251
+
252
+ ### Automatic Console Logging
253
+
254
+ ```javascript
255
+ // All console methods are automatically captured
256
+ console.log('Application started');
257
+ console.info('User action', { userId: 123 });
258
+ console.warn('Warning message');
259
+ console.error('Error occurred', { error: 'details' });
260
+ ```
261
+
262
+ ### Direct Logger API
263
+
264
+ ```javascript
265
+ const { getLogger } = require('securenow/tracing');
266
+ const logger = getLogger('my-module', '1.0.0');
267
+
268
+ logger.emit({
269
+ severityNumber: 9,
270
+ severityText: 'INFO',
271
+ body: 'Custom log message',
272
+ attributes: {
273
+ userId: 123,
274
+ action: 'login',
275
+ },
276
+ });
277
+ ```
278
+
279
+ [Complete Logging Guide →](./LOGGING-GUIDE.md)
280
+
281
+ ---
282
+
283
+ ## Request Body Capture
284
+
285
+ Enable request body capture for debugging:
286
+
287
+ ```bash
288
+ export SECURENOW_CAPTURE_BODY=1
289
+ export SECURENOW_MAX_BODY_SIZE=10240 # 10KB
290
+ ```
291
+
292
+ **Automatically redacted:** passwords, tokens, API keys, card numbers, etc.
293
+
294
+ ---
295
+
296
+ ## PM2 Setup
297
+
298
+ ```javascript
299
+ // ecosystem.config.js
300
+ module.exports = {
301
+ apps: [{
302
+ name: 'my-app',
303
+ script: './app.js',
304
+ instances: 4,
305
+ exec_mode: 'cluster',
306
+ node_args: '-r securenow/register -r securenow/console-instrumentation',
307
+ env: {
308
+ SECURENOW_APPID: 'my-app',
309
+ SECURENOW_INSTANCE: 'http://localhost:4318',
310
+ SECURENOW_LOGGING_ENABLED: '1',
311
+ SECURENOW_NO_UUID: '1',
312
+ }
313
+ }]
314
+ };
315
+ ```
316
+
317
+ ```bash
318
+ pm2 start ecosystem.config.js
319
+ ```
320
+
321
+ ---
322
+
323
+ ## Docker Setup
324
+
325
+ ```dockerfile
326
+ FROM node:20-alpine
327
+
328
+ WORKDIR /app
329
+
330
+ COPY package*.json ./
331
+ RUN npm install
332
+
333
+ COPY . .
334
+
335
+ ENV SECURENOW_APPID=my-app
336
+ ENV SECURENOW_INSTANCE=http://collector:4318
337
+ ENV SECURENOW_LOGGING_ENABLED=1
338
+
339
+ EXPOSE 3000
340
+ CMD ["node", "app.js"]
341
+ ```
342
+
343
+ ---
344
+
345
+ ## Verification
346
+
347
+ After starting your app, you should see:
348
+
349
+ ```
350
+ [securenow] OTel SDK started → http://localhost:4318/v1/traces
351
+ [securenow] 📋 Logging: ENABLED → http://localhost:4318/v1/logs
352
+ [securenow] Console instrumentation installed
353
+ ```
354
+
355
+ Check your observability backend - traces and logs should appear within seconds.
356
+
357
+ ---
358
+
359
+ ## Troubleshooting
360
+
361
+ ### Traces Not Appearing
362
+
363
+ 1. Check environment variables:
364
+ ```bash
365
+ echo $SECURENOW_APPID
366
+ echo $SECURENOW_INSTANCE
367
+ ```
368
+
369
+ 2. Enable debug logging:
370
+ ```bash
371
+ export OTEL_LOG_LEVEL=debug
372
+ node app.js
373
+ ```
374
+
375
+ 3. Verify collector is running:
376
+ ```bash
377
+ curl http://localhost:4318/v1/traces
378
+ ```
379
+
380
+ ### Logs Not Appearing
381
+
382
+ 1. Check logging is enabled:
383
+ ```bash
384
+ echo $SECURENOW_LOGGING_ENABLED # Should be: 1
385
+ ```
386
+
387
+ 2. Verify console instrumentation loaded:
388
+ ```
389
+ [securenow] Console instrumentation installed
390
+ ```
391
+
392
+ 3. Check initialization order:
393
+ ```javascript
394
+ // ✅ Correct
395
+ require('securenow/register');
396
+ require('securenow/console-instrumentation');
397
+ const express = require('express');
398
+
399
+ // ❌ Wrong
400
+ const express = require('express');
401
+ require('securenow/register');
402
+ ```
403
+
404
+ ---
405
+
406
+ ## Complete Documentation
407
+
408
+ - **[NPM README](../NPM_README.md)** - Full npm package documentation
409
+ - **[Express Guide](./EXPRESS-SETUP-GUIDE.md)** - Complete Express.js setup
410
+ - **[Next.js Guide](./NEXTJS-SETUP-COMPLETE.md)** - Complete Next.js setup
411
+ - **[Logging Guide](./LOGGING-GUIDE.md)** - Complete logging reference
412
+ - **[Environment Variables](./ENVIRONMENT-VARIABLES.md)** - All variables explained
413
+
414
+ ---
415
+
416
+ ## What Gets Instrumented Automatically
417
+
418
+ - HTTP/HTTPS (incoming and outgoing)
419
+ - Express.js, Fastify, Koa, Hapi, Next.js
420
+ - PostgreSQL, MySQL, MongoDB, Redis
421
+ - GraphQL, gRPC
422
+ - axios, fetch, node-fetch, got
423
+ - And 50+ more libraries
424
+
425
+ **No code changes needed!**
426
+
427
+ ---
428
+
429
+ ## Performance
430
+
431
+ - **< 1% overhead:** Minimal CPU and memory impact
432
+ - **Async processing:** No blocking of requests
433
+ - **Batch export:** Efficient data transmission
434
+ - **Production-ready:** Battle-tested in high-traffic applications
435
+
436
+ ---
437
+
438
+ ## Security
439
+
440
+ - **Automatic redaction** of sensitive fields
441
+ - **Configurable** field patterns
442
+ - **No local storage** - data goes directly to your backend
443
+ - **Open source** - audit the code yourself
444
+
445
+ ---
446
+
447
+ ## Support
448
+
449
+ - **Documentation:** [GitHub Docs](https://github.com/your-repo/securenow-npm/tree/main/docs)
450
+ - **Issues:** [GitHub Issues](https://github.com/your-repo/securenow-npm/issues)
451
+ - **Examples:** [GitHub Examples](https://github.com/your-repo/securenow-npm/tree/main/examples)
452
+
453
+ ---
454
+
455
+ **Get your app observable in under 5 minutes!** 🚀