securenow 5.5.0 → 5.6.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/CONSUMING-APPS-GUIDE.md +411 -415
- package/NPM_README.md +1544 -1609
- package/README.md +9 -21
- package/cli/monitor.js +13 -1
- package/cli.js +1 -1
- package/console-instrumentation.js +6 -1
- package/docs/ALL-FRAMEWORKS-QUICKSTART.md +1282 -455
- package/docs/EXPRESS-SETUP-GUIDE.md +719 -720
- package/docs/LOGGING-GUIDE.md +701 -708
- package/docs/LOGGING-QUICKSTART.md +234 -239
- package/nextjs.js +19 -3
- package/package.json +1 -1
- package/tracing.d.ts +1 -0
- package/tracing.js +87 -1
package/docs/LOGGING-GUIDE.md
CHANGED
|
@@ -1,708 +1,701 @@
|
|
|
1
|
-
# SecureNow Logging Guide
|
|
2
|
-
|
|
3
|
-
Complete guide for sending logs from your Node.js applications to SecureNow using the SecureNow library.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- [Method
|
|
13
|
-
- [
|
|
14
|
-
- [
|
|
15
|
-
|
|
16
|
-
- [
|
|
17
|
-
- [
|
|
18
|
-
- [
|
|
19
|
-
- [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
console
|
|
60
|
-
console.
|
|
61
|
-
console.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
export
|
|
117
|
-
export
|
|
118
|
-
export
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
require('securenow/
|
|
139
|
-
|
|
140
|
-
const express = require('express');
|
|
141
|
-
const app = express();
|
|
142
|
-
|
|
143
|
-
// Use console as normal - all logs are captured
|
|
144
|
-
console.log('Server starting...');
|
|
145
|
-
|
|
146
|
-
app.get('/', (req, res) => {
|
|
147
|
-
console.info('Request received', { path: req.path });
|
|
148
|
-
res.send('Hello World');
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
app.listen(3000, () => {
|
|
152
|
-
console.log('Server running on port 3000');
|
|
153
|
-
});
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
**Supported Methods:**
|
|
157
|
-
- `console.log()` → INFO level
|
|
158
|
-
- `console.info()` → INFO level
|
|
159
|
-
- `console.warn()` → WARN level
|
|
160
|
-
- `console.error()` → ERROR level
|
|
161
|
-
- `console.debug()` → DEBUG level
|
|
162
|
-
|
|
163
|
-
**Benefits:**
|
|
164
|
-
- ✅ Zero code changes needed
|
|
165
|
-
- ✅ Works with existing console logging
|
|
166
|
-
- ✅ Automatic severity mapping
|
|
167
|
-
- ✅ Works with all frameworks
|
|
168
|
-
|
|
169
|
-
---
|
|
170
|
-
|
|
171
|
-
### Method 2: Direct Logger API
|
|
172
|
-
|
|
173
|
-
Use the OpenTelemetry logger API directly for more control.
|
|
174
|
-
|
|
175
|
-
```javascript
|
|
176
|
-
require('securenow/register');
|
|
177
|
-
const { getLogger } = require('securenow/tracing');
|
|
178
|
-
|
|
179
|
-
// Get a logger instance
|
|
180
|
-
const logger = getLogger('my-service', '1.0.0');
|
|
181
|
-
|
|
182
|
-
// Emit structured logs
|
|
183
|
-
logger.emit({
|
|
184
|
-
severityNumber: 9, // OpenTelemetry severity number
|
|
185
|
-
severityText: 'INFO', // Human-readable severity
|
|
186
|
-
body: 'User login', // Log message
|
|
187
|
-
attributes: { // Structured attributes
|
|
188
|
-
userId: 123,
|
|
189
|
-
username: 'john',
|
|
190
|
-
ip: '192.168.1.1',
|
|
191
|
-
},
|
|
192
|
-
});
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
**Severity Numbers:**
|
|
196
|
-
- `5` - DEBUG
|
|
197
|
-
- `9` - INFO
|
|
198
|
-
- `13` - WARN
|
|
199
|
-
- `17` - ERROR
|
|
200
|
-
|
|
201
|
-
**Example with Error:**
|
|
202
|
-
|
|
203
|
-
```javascript
|
|
204
|
-
try {
|
|
205
|
-
// Some operation
|
|
206
|
-
} catch (error) {
|
|
207
|
-
logger.emit({
|
|
208
|
-
severityNumber: 17,
|
|
209
|
-
severityText: 'ERROR',
|
|
210
|
-
body: 'Database connection failed',
|
|
211
|
-
attributes: {
|
|
212
|
-
error: error.message,
|
|
213
|
-
stack: error.stack,
|
|
214
|
-
database: 'postgres',
|
|
215
|
-
},
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
---
|
|
221
|
-
|
|
222
|
-
### Method 3: Custom Logger Integration
|
|
223
|
-
|
|
224
|
-
Create a wrapper for your preferred logging style.
|
|
225
|
-
|
|
226
|
-
```javascript
|
|
227
|
-
// logger.js
|
|
228
|
-
require('securenow/register');
|
|
229
|
-
const { getLogger } = require('securenow/tracing');
|
|
230
|
-
|
|
231
|
-
const logger = getLogger('app-logger', '1.0.0');
|
|
232
|
-
|
|
233
|
-
const SeverityNumber = {
|
|
234
|
-
DEBUG: 5,
|
|
235
|
-
INFO: 9,
|
|
236
|
-
WARN: 13,
|
|
237
|
-
ERROR: 17,
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
function log(level, message, attributes = {}) {
|
|
241
|
-
if (!logger) {
|
|
242
|
-
console.log(message, attributes);
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
logger.emit({
|
|
247
|
-
severityNumber: SeverityNumber[level],
|
|
248
|
-
severityText: level,
|
|
249
|
-
body: message,
|
|
250
|
-
attributes,
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
// Also log to console
|
|
254
|
-
console.log(`[${level}] ${message}`, attributes);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
module.exports = {
|
|
258
|
-
debug: (msg, attrs) => log('DEBUG', msg, attrs),
|
|
259
|
-
info: (msg, attrs) => log('INFO', msg, attrs),
|
|
260
|
-
warn: (msg, attrs) => log('WARN', msg, attrs),
|
|
261
|
-
error: (msg, attrs) => log('ERROR', msg, attrs),
|
|
262
|
-
};
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
**Usage:**
|
|
266
|
-
|
|
267
|
-
```javascript
|
|
268
|
-
const logger = require('./logger');
|
|
269
|
-
|
|
270
|
-
logger.info('User signed up', { userId: 456, email: 'user@example.com' });
|
|
271
|
-
logger.error('Payment failed', { orderId: 789, amount: 99.99 });
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
---
|
|
275
|
-
|
|
276
|
-
## Framework-Specific Examples
|
|
277
|
-
|
|
278
|
-
### Express.js
|
|
279
|
-
|
|
280
|
-
```javascript
|
|
281
|
-
// app.js
|
|
282
|
-
require('securenow/register');
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
require('
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
```
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
```
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
```
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
```
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
```
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
```
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
const
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
```
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
export
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
```
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
//
|
|
617
|
-
require('
|
|
618
|
-
require('securenow/
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
require('securenow/register')
|
|
624
|
-
|
|
625
|
-
```
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
```
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
```
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
- [
|
|
700
|
-
- [
|
|
701
|
-
|
|
702
|
-
---
|
|
703
|
-
|
|
704
|
-
## Support
|
|
705
|
-
|
|
706
|
-
- **Issues**: [GitHub Issues](https://github.com/your-repo/securenow-npm)
|
|
707
|
-
- **Documentation**: [Full Docs](./INDEX.md)
|
|
708
|
-
- **Website**: [securenow.ai](http://securenow.ai/)
|
|
1
|
+
# SecureNow Logging Guide
|
|
2
|
+
|
|
3
|
+
Complete guide for sending logs from your Node.js applications to SecureNow using the SecureNow library.
|
|
4
|
+
|
|
5
|
+
**Since securenow v5.6.0:** When `SECURENOW_LOGGING_ENABLED=1` is set, all `console.log`, `console.warn`, `console.error`, `console.info`, and `console.debug` calls are automatically forwarded as OTLP log records. You only need `require('securenow/register')` — a separate `securenow/console-instrumentation` preload is no longer required.
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Quick Start](#quick-start)
|
|
10
|
+
- [Configuration](#configuration)
|
|
11
|
+
- [Usage Methods](#usage-methods)
|
|
12
|
+
- [Method 1: Automatic Console Instrumentation](#method-1-automatic-console-instrumentation-easiest)
|
|
13
|
+
- [Method 2: Direct Logger API](#method-2-direct-logger-api)
|
|
14
|
+
- [Method 3: Custom Logger Integration](#method-3-custom-logger-integration)
|
|
15
|
+
- [Framework-Specific Examples](#framework-specific-examples)
|
|
16
|
+
- [Express.js](#expressjs)
|
|
17
|
+
- [Next.js](#nextjs)
|
|
18
|
+
- [Fastify](#fastify)
|
|
19
|
+
- [NestJS](#nestjs)
|
|
20
|
+
- [Advanced Configuration](#advanced-configuration)
|
|
21
|
+
- [Troubleshooting](#troubleshooting)
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
### 1. Install SecureNow
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install securenow
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 2. Enable Logging
|
|
34
|
+
|
|
35
|
+
Set environment variables:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# Required: Enable logging
|
|
39
|
+
export SECURENOW_LOGGING_ENABLED=1
|
|
40
|
+
|
|
41
|
+
# Required: Your app identifier
|
|
42
|
+
export SECURENOW_APPID=my-app
|
|
43
|
+
|
|
44
|
+
# Optional: Your OTLP endpoint (defaults to https://freetrial.securenow.ai:4318)
|
|
45
|
+
export SECURENOW_INSTANCE=http://your-otlp-backend:4318
|
|
46
|
+
|
|
47
|
+
# Optional: Authentication for hosted OTLP / SecureNow
|
|
48
|
+
export OTEL_EXPORTER_OTLP_HEADERS="x-api-key=your-key-here"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 3. Choose Your Usage Method
|
|
52
|
+
|
|
53
|
+
**Option A: Automatic Console Logging (Easiest)**
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
// At the top of your main file (app.js, index.js, server.js)
|
|
57
|
+
require('securenow/register');
|
|
58
|
+
|
|
59
|
+
// With SECURENOW_LOGGING_ENABLED=1, all console logs are automatically sent to SecureNow
|
|
60
|
+
console.log('Application started');
|
|
61
|
+
console.error('An error occurred', { userId: 123 });
|
|
62
|
+
console.warn('Warning message');
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Option B: Direct Logger API**
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
require('securenow/register');
|
|
69
|
+
const { getLogger } = require('securenow/tracing');
|
|
70
|
+
|
|
71
|
+
const logger = getLogger('my-module', '1.0.0');
|
|
72
|
+
|
|
73
|
+
logger.emit({
|
|
74
|
+
severityNumber: 9, // INFO
|
|
75
|
+
severityText: 'INFO',
|
|
76
|
+
body: 'User logged in',
|
|
77
|
+
attributes: {
|
|
78
|
+
userId: 123,
|
|
79
|
+
username: 'john',
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Configuration
|
|
87
|
+
|
|
88
|
+
### Environment Variables
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# Logging Control
|
|
92
|
+
SECURENOW_LOGGING_ENABLED=1 # Enable logging (default: 1)
|
|
93
|
+
|
|
94
|
+
# Connection Settings
|
|
95
|
+
SECURENOW_INSTANCE=http://localhost:4318 # Base OTLP endpoint
|
|
96
|
+
OTEL_EXPORTER_OTLP_ENDPOINT=... # Alternative to SECURENOW_INSTANCE
|
|
97
|
+
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=... # Specific logs endpoint (overrides base)
|
|
98
|
+
|
|
99
|
+
# Authentication (for hosted OTLP / SecureNow)
|
|
100
|
+
OTEL_EXPORTER_OTLP_HEADERS="x-api-key=YOUR_KEY"
|
|
101
|
+
|
|
102
|
+
# Service Identification
|
|
103
|
+
SECURENOW_APPID=my-app # Your application name
|
|
104
|
+
OTEL_SERVICE_NAME=my-app # Alternative to SECURENOW_APPID
|
|
105
|
+
|
|
106
|
+
# Additional Options
|
|
107
|
+
OTEL_LOG_LEVEL=info # debug|info|warn|error
|
|
108
|
+
NODE_ENV=production # Environment name
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Hosted OTLP / SecureNow configuration
|
|
112
|
+
|
|
113
|
+
For SecureNow or another hosted OTLP endpoint:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
export SECURENOW_LOGGING_ENABLED=1
|
|
117
|
+
export SECURENOW_APPID=my-app
|
|
118
|
+
export SECURENOW_INSTANCE=https://freetrial.securenow.ai:4318
|
|
119
|
+
export OTEL_EXPORTER_OTLP_HEADERS="x-api-key=<your-api-key>"
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Replace:
|
|
123
|
+
- `SECURENOW_INSTANCE`: Use the OTLP base URL from your SecureNow dashboard (defaults to the freetrial endpoint above)
|
|
124
|
+
- `<your-api-key>`: Your API key or other credentials as required by your backend
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Usage Methods
|
|
129
|
+
|
|
130
|
+
### Method 1: Automatic Console Instrumentation (Easiest)
|
|
131
|
+
|
|
132
|
+
With `SECURENOW_LOGGING_ENABLED=1`, SecureNow wraps the default `console` methods to automatically send logs to SecureNow while still printing to the console.
|
|
133
|
+
|
|
134
|
+
**Setup:**
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
// app.js or index.js
|
|
138
|
+
require('securenow/register');
|
|
139
|
+
|
|
140
|
+
const express = require('express');
|
|
141
|
+
const app = express();
|
|
142
|
+
|
|
143
|
+
// Use console as normal - all logs are captured
|
|
144
|
+
console.log('Server starting...');
|
|
145
|
+
|
|
146
|
+
app.get('/', (req, res) => {
|
|
147
|
+
console.info('Request received', { path: req.path });
|
|
148
|
+
res.send('Hello World');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
app.listen(3000, () => {
|
|
152
|
+
console.log('Server running on port 3000');
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**Supported Methods:**
|
|
157
|
+
- `console.log()` → INFO level
|
|
158
|
+
- `console.info()` → INFO level
|
|
159
|
+
- `console.warn()` → WARN level
|
|
160
|
+
- `console.error()` → ERROR level
|
|
161
|
+
- `console.debug()` → DEBUG level
|
|
162
|
+
|
|
163
|
+
**Benefits:**
|
|
164
|
+
- ✅ Zero code changes needed
|
|
165
|
+
- ✅ Works with existing console logging
|
|
166
|
+
- ✅ Automatic severity mapping
|
|
167
|
+
- ✅ Works with all frameworks
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
### Method 2: Direct Logger API
|
|
172
|
+
|
|
173
|
+
Use the OpenTelemetry logger API directly for more control.
|
|
174
|
+
|
|
175
|
+
```javascript
|
|
176
|
+
require('securenow/register');
|
|
177
|
+
const { getLogger } = require('securenow/tracing');
|
|
178
|
+
|
|
179
|
+
// Get a logger instance
|
|
180
|
+
const logger = getLogger('my-service', '1.0.0');
|
|
181
|
+
|
|
182
|
+
// Emit structured logs
|
|
183
|
+
logger.emit({
|
|
184
|
+
severityNumber: 9, // OpenTelemetry severity number
|
|
185
|
+
severityText: 'INFO', // Human-readable severity
|
|
186
|
+
body: 'User login', // Log message
|
|
187
|
+
attributes: { // Structured attributes
|
|
188
|
+
userId: 123,
|
|
189
|
+
username: 'john',
|
|
190
|
+
ip: '192.168.1.1',
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**Severity Numbers:**
|
|
196
|
+
- `5` - DEBUG
|
|
197
|
+
- `9` - INFO
|
|
198
|
+
- `13` - WARN
|
|
199
|
+
- `17` - ERROR
|
|
200
|
+
|
|
201
|
+
**Example with Error:**
|
|
202
|
+
|
|
203
|
+
```javascript
|
|
204
|
+
try {
|
|
205
|
+
// Some operation
|
|
206
|
+
} catch (error) {
|
|
207
|
+
logger.emit({
|
|
208
|
+
severityNumber: 17,
|
|
209
|
+
severityText: 'ERROR',
|
|
210
|
+
body: 'Database connection failed',
|
|
211
|
+
attributes: {
|
|
212
|
+
error: error.message,
|
|
213
|
+
stack: error.stack,
|
|
214
|
+
database: 'postgres',
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
### Method 3: Custom Logger Integration
|
|
223
|
+
|
|
224
|
+
Create a wrapper for your preferred logging style.
|
|
225
|
+
|
|
226
|
+
```javascript
|
|
227
|
+
// logger.js
|
|
228
|
+
require('securenow/register');
|
|
229
|
+
const { getLogger } = require('securenow/tracing');
|
|
230
|
+
|
|
231
|
+
const logger = getLogger('app-logger', '1.0.0');
|
|
232
|
+
|
|
233
|
+
const SeverityNumber = {
|
|
234
|
+
DEBUG: 5,
|
|
235
|
+
INFO: 9,
|
|
236
|
+
WARN: 13,
|
|
237
|
+
ERROR: 17,
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
function log(level, message, attributes = {}) {
|
|
241
|
+
if (!logger) {
|
|
242
|
+
console.log(message, attributes);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
logger.emit({
|
|
247
|
+
severityNumber: SeverityNumber[level],
|
|
248
|
+
severityText: level,
|
|
249
|
+
body: message,
|
|
250
|
+
attributes,
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
// Also log to console
|
|
254
|
+
console.log(`[${level}] ${message}`, attributes);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
module.exports = {
|
|
258
|
+
debug: (msg, attrs) => log('DEBUG', msg, attrs),
|
|
259
|
+
info: (msg, attrs) => log('INFO', msg, attrs),
|
|
260
|
+
warn: (msg, attrs) => log('WARN', msg, attrs),
|
|
261
|
+
error: (msg, attrs) => log('ERROR', msg, attrs),
|
|
262
|
+
};
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**Usage:**
|
|
266
|
+
|
|
267
|
+
```javascript
|
|
268
|
+
const logger = require('./logger');
|
|
269
|
+
|
|
270
|
+
logger.info('User signed up', { userId: 456, email: 'user@example.com' });
|
|
271
|
+
logger.error('Payment failed', { orderId: 789, amount: 99.99 });
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## Framework-Specific Examples
|
|
277
|
+
|
|
278
|
+
### Express.js
|
|
279
|
+
|
|
280
|
+
```javascript
|
|
281
|
+
// app.js
|
|
282
|
+
require('securenow/register');
|
|
283
|
+
|
|
284
|
+
const express = require('express');
|
|
285
|
+
const app = express();
|
|
286
|
+
|
|
287
|
+
app.use(express.json());
|
|
288
|
+
|
|
289
|
+
// Logging middleware
|
|
290
|
+
app.use((req, res, next) => {
|
|
291
|
+
console.info('Request received', {
|
|
292
|
+
method: req.method,
|
|
293
|
+
path: req.path,
|
|
294
|
+
ip: req.ip,
|
|
295
|
+
});
|
|
296
|
+
next();
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
app.get('/', (req, res) => {
|
|
300
|
+
console.log('Home page accessed');
|
|
301
|
+
res.send('Hello World');
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
app.post('/api/users', (req, res) => {
|
|
305
|
+
console.info('User created', { userData: req.body });
|
|
306
|
+
res.json({ success: true });
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// Error handler with logging
|
|
310
|
+
app.use((err, req, res, next) => {
|
|
311
|
+
console.error('Express error', {
|
|
312
|
+
error: err.message,
|
|
313
|
+
stack: err.stack,
|
|
314
|
+
path: req.path,
|
|
315
|
+
});
|
|
316
|
+
res.status(500).json({ error: 'Internal server error' });
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
app.listen(3000, () => {
|
|
320
|
+
console.log('Express server running on port 3000');
|
|
321
|
+
});
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
**Run with:**
|
|
325
|
+
|
|
326
|
+
```bash
|
|
327
|
+
SECURENOW_LOGGING_ENABLED=1 \
|
|
328
|
+
SECURENOW_APPID=express-app \
|
|
329
|
+
NODE_OPTIONS="-r securenow/register" \
|
|
330
|
+
node app.js
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
### Next.js
|
|
336
|
+
|
|
337
|
+
#### App Router (Next.js 13+)
|
|
338
|
+
|
|
339
|
+
**instrumentation.ts:**
|
|
340
|
+
|
|
341
|
+
```typescript
|
|
342
|
+
// instrumentation.ts (in root directory)
|
|
343
|
+
export async function register() {
|
|
344
|
+
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
|
345
|
+
// Enable tracing and logging
|
|
346
|
+
process.env.SECURENOW_LOGGING_ENABLED = '1';
|
|
347
|
+
|
|
348
|
+
await import('securenow/register');
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
**Environment Variables (.env.local):**
|
|
354
|
+
|
|
355
|
+
```bash
|
|
356
|
+
SECURENOW_LOGGING_ENABLED=1
|
|
357
|
+
SECURENOW_APPID=nextjs-app
|
|
358
|
+
SECURENOW_INSTANCE=http://your-otlp-backend:4318
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
**Usage in API Routes:**
|
|
362
|
+
|
|
363
|
+
```typescript
|
|
364
|
+
// app/api/users/route.ts
|
|
365
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
366
|
+
|
|
367
|
+
export async function GET(request: NextRequest) {
|
|
368
|
+
console.log('GET /api/users called');
|
|
369
|
+
|
|
370
|
+
const users = await fetchUsers();
|
|
371
|
+
console.info('Users fetched', { count: users.length });
|
|
372
|
+
|
|
373
|
+
return NextResponse.json(users);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export async function POST(request: NextRequest) {
|
|
377
|
+
const data = await request.json();
|
|
378
|
+
console.info('Creating user', { email: data.email });
|
|
379
|
+
|
|
380
|
+
try {
|
|
381
|
+
const user = await createUser(data);
|
|
382
|
+
console.log('User created successfully', { userId: user.id });
|
|
383
|
+
return NextResponse.json(user);
|
|
384
|
+
} catch (error) {
|
|
385
|
+
console.error('Failed to create user', { error: error.message });
|
|
386
|
+
return NextResponse.json({ error: 'Failed' }, { status: 500 });
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
**Usage in Server Components:**
|
|
392
|
+
|
|
393
|
+
```typescript
|
|
394
|
+
// app/dashboard/page.tsx
|
|
395
|
+
export default async function DashboardPage() {
|
|
396
|
+
console.log('Dashboard page rendering');
|
|
397
|
+
|
|
398
|
+
const data = await fetchDashboardData();
|
|
399
|
+
console.info('Dashboard data loaded', { items: data.length });
|
|
400
|
+
|
|
401
|
+
return <div>{/* your component */}</div>;
|
|
402
|
+
}
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
### Fastify
|
|
408
|
+
|
|
409
|
+
```javascript
|
|
410
|
+
// server.js
|
|
411
|
+
require('securenow/register');
|
|
412
|
+
|
|
413
|
+
const fastify = require('fastify')({ logger: false });
|
|
414
|
+
|
|
415
|
+
// Logging hook
|
|
416
|
+
fastify.addHook('onRequest', async (request, reply) => {
|
|
417
|
+
console.info('Request received', {
|
|
418
|
+
method: request.method,
|
|
419
|
+
url: request.url,
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
fastify.get('/', async (request, reply) => {
|
|
424
|
+
console.log('Root endpoint called');
|
|
425
|
+
return { hello: 'world' };
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
fastify.post('/users', async (request, reply) => {
|
|
429
|
+
console.info('Creating user', { body: request.body });
|
|
430
|
+
return { success: true };
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
// Error handler
|
|
434
|
+
fastify.setErrorHandler((error, request, reply) => {
|
|
435
|
+
console.error('Fastify error', {
|
|
436
|
+
error: error.message,
|
|
437
|
+
stack: error.stack,
|
|
438
|
+
url: request.url,
|
|
439
|
+
});
|
|
440
|
+
reply.status(500).send({ error: 'Internal server error' });
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
const start = async () => {
|
|
444
|
+
try {
|
|
445
|
+
await fastify.listen({ port: 3000 });
|
|
446
|
+
console.log('Fastify server running on port 3000');
|
|
447
|
+
} catch (err) {
|
|
448
|
+
console.error('Server start failed', { error: err });
|
|
449
|
+
process.exit(1);
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
start();
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
---
|
|
457
|
+
|
|
458
|
+
### NestJS
|
|
459
|
+
|
|
460
|
+
**main.ts:**
|
|
461
|
+
|
|
462
|
+
```typescript
|
|
463
|
+
// main.ts
|
|
464
|
+
require('securenow/register');
|
|
465
|
+
|
|
466
|
+
import { NestFactory } from '@nestjs/core';
|
|
467
|
+
import { AppModule } from './app.module';
|
|
468
|
+
|
|
469
|
+
async function bootstrap() {
|
|
470
|
+
const app = await NestFactory.create(AppModule);
|
|
471
|
+
|
|
472
|
+
console.log('NestJS application starting...');
|
|
473
|
+
|
|
474
|
+
await app.listen(3000);
|
|
475
|
+
console.log('NestJS application running on port 3000');
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
bootstrap();
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
**Service with logging:**
|
|
482
|
+
|
|
483
|
+
```typescript
|
|
484
|
+
// users.service.ts
|
|
485
|
+
import { Injectable } from '@nestjs/common';
|
|
486
|
+
|
|
487
|
+
@Injectable()
|
|
488
|
+
export class UsersService {
|
|
489
|
+
async findAll() {
|
|
490
|
+
console.log('Fetching all users');
|
|
491
|
+
const users = await this.fetchFromDatabase();
|
|
492
|
+
console.info('Users retrieved', { count: users.length });
|
|
493
|
+
return users;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
async create(userData: any) {
|
|
497
|
+
console.info('Creating user', { email: userData.email });
|
|
498
|
+
|
|
499
|
+
try {
|
|
500
|
+
const user = await this.saveToDatabase(userData);
|
|
501
|
+
console.log('User created', { userId: user.id });
|
|
502
|
+
return user;
|
|
503
|
+
} catch (error) {
|
|
504
|
+
console.error('Failed to create user', {
|
|
505
|
+
error: error.message,
|
|
506
|
+
email: userData.email,
|
|
507
|
+
});
|
|
508
|
+
throw error;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
**Run with environment variables:**
|
|
515
|
+
|
|
516
|
+
```bash
|
|
517
|
+
SECURENOW_LOGGING_ENABLED=1 \
|
|
518
|
+
SECURENOW_APPID=nestjs-app \
|
|
519
|
+
npm run start
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
---
|
|
523
|
+
|
|
524
|
+
## Advanced Configuration
|
|
525
|
+
|
|
526
|
+
### Disable Logging Temporarily
|
|
527
|
+
|
|
528
|
+
```bash
|
|
529
|
+
SECURENOW_LOGGING_ENABLED=0 node app.js
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
### Custom Logs Endpoint
|
|
533
|
+
|
|
534
|
+
```bash
|
|
535
|
+
export OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=http://custom-collector:4318/v1/logs
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
### Check if Logging is Enabled
|
|
539
|
+
|
|
540
|
+
```javascript
|
|
541
|
+
const { isLoggingEnabled } = require('securenow/tracing');
|
|
542
|
+
|
|
543
|
+
if (isLoggingEnabled()) {
|
|
544
|
+
console.log('Logging is enabled');
|
|
545
|
+
}
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
### Multiple Logger Instances
|
|
549
|
+
|
|
550
|
+
```javascript
|
|
551
|
+
const { getLogger } = require('securenow/tracing');
|
|
552
|
+
|
|
553
|
+
const authLogger = getLogger('auth-service', '1.0.0');
|
|
554
|
+
const dbLogger = getLogger('database', '2.0.0');
|
|
555
|
+
const apiLogger = getLogger('api', '1.0.0');
|
|
556
|
+
|
|
557
|
+
authLogger.emit({
|
|
558
|
+
severityNumber: 9,
|
|
559
|
+
severityText: 'INFO',
|
|
560
|
+
body: 'User logged in',
|
|
561
|
+
attributes: { userId: 123 },
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
dbLogger.emit({
|
|
565
|
+
severityNumber: 13,
|
|
566
|
+
severityText: 'WARN',
|
|
567
|
+
body: 'Slow query detected',
|
|
568
|
+
attributes: { queryTime: 5000, query: 'SELECT ...' },
|
|
569
|
+
});
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
---
|
|
573
|
+
|
|
574
|
+
## Troubleshooting
|
|
575
|
+
|
|
576
|
+
### Logs not appearing in SecureNow
|
|
577
|
+
|
|
578
|
+
**Check 1: Is logging enabled?**
|
|
579
|
+
|
|
580
|
+
```bash
|
|
581
|
+
SECURENOW_LOGGING_ENABLED=1
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
**Check 2: Verify endpoint**
|
|
585
|
+
|
|
586
|
+
```bash
|
|
587
|
+
# For self-hosted OTLP collector
|
|
588
|
+
export SECURENOW_INSTANCE=http://your-otlp-backend:4318
|
|
589
|
+
|
|
590
|
+
# For SecureNow / hosted OTLP
|
|
591
|
+
export SECURENOW_INSTANCE=https://freetrial.securenow.ai:4318
|
|
592
|
+
export OTEL_EXPORTER_OTLP_HEADERS="x-api-key=<your-key>"
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
**Check 3: Enable debug logging**
|
|
596
|
+
|
|
597
|
+
```bash
|
|
598
|
+
export OTEL_LOG_LEVEL=debug
|
|
599
|
+
node app.js
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
Look for messages like:
|
|
603
|
+
```
|
|
604
|
+
[securenow] 📋 Logging: ENABLED → http://localhost:4318/v1/logs
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
**Check 4: Verify initialization order**
|
|
608
|
+
|
|
609
|
+
Make sure `securenow/register` is required BEFORE any other code:
|
|
610
|
+
|
|
611
|
+
```javascript
|
|
612
|
+
// ✅ Correct
|
|
613
|
+
require('securenow/register');
|
|
614
|
+
const express = require('express');
|
|
615
|
+
|
|
616
|
+
// ❌ Wrong
|
|
617
|
+
const express = require('express');
|
|
618
|
+
require('securenow/register');
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
### Console logs not forwarded
|
|
622
|
+
|
|
623
|
+
**Check load order:** `require('securenow/register')` must run before your app code so console forwarding can be installed.
|
|
624
|
+
|
|
625
|
+
```javascript
|
|
626
|
+
require('securenow/register');
|
|
627
|
+
// ... rest of your app
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
**Verify in output:**
|
|
631
|
+
|
|
632
|
+
You should see messages indicating logging is enabled, for example:
|
|
633
|
+
```
|
|
634
|
+
[securenow] 📋 Logging: ENABLED → http://localhost:4318/v1/logs
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
### Logger returns null
|
|
638
|
+
|
|
639
|
+
This happens when logging is not enabled:
|
|
640
|
+
|
|
641
|
+
```javascript
|
|
642
|
+
const { getLogger } = require('securenow/tracing');
|
|
643
|
+
const logger = getLogger('test');
|
|
644
|
+
|
|
645
|
+
if (!logger) {
|
|
646
|
+
console.log('Logging not enabled - set SECURENOW_LOGGING_ENABLED=1');
|
|
647
|
+
}
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
### Logs in SecureNow but missing attributes
|
|
651
|
+
|
|
652
|
+
Make sure you're passing attributes correctly:
|
|
653
|
+
|
|
654
|
+
```javascript
|
|
655
|
+
// ✅ Correct
|
|
656
|
+
console.log('User action', { userId: 123, action: 'login' });
|
|
657
|
+
|
|
658
|
+
// ❌ Won't capture structured data
|
|
659
|
+
console.log('User action userId=123 action=login');
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
Or use direct logger API:
|
|
663
|
+
|
|
664
|
+
```javascript
|
|
665
|
+
logger.emit({
|
|
666
|
+
severityNumber: 9,
|
|
667
|
+
severityText: 'INFO',
|
|
668
|
+
body: 'User action',
|
|
669
|
+
attributes: {
|
|
670
|
+
userId: 123,
|
|
671
|
+
action: 'login',
|
|
672
|
+
},
|
|
673
|
+
});
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
---
|
|
677
|
+
|
|
678
|
+
## Best Practices
|
|
679
|
+
|
|
680
|
+
1. **Always enable logging via environment variable** - don't hardcode it
|
|
681
|
+
2. **Use structured logging** - pass objects with meaningful attributes
|
|
682
|
+
3. **Include context** - userId, requestId, etc. in log attributes
|
|
683
|
+
4. **Use appropriate severity levels** - INFO for normal flow, ERROR for exceptions
|
|
684
|
+
5. **Don't log sensitive data** - passwords, tokens, credit cards
|
|
685
|
+
6. **Use different loggers for different modules** - easier filtering in SecureNow
|
|
686
|
+
|
|
687
|
+
---
|
|
688
|
+
|
|
689
|
+
## Next Steps
|
|
690
|
+
|
|
691
|
+
- [SecureNow](https://securenow.ai/)
|
|
692
|
+
- [Documentation](./INDEX.md)
|
|
693
|
+
- [Combine with tracing](../README.md) for full observability
|
|
694
|
+
|
|
695
|
+
---
|
|
696
|
+
|
|
697
|
+
## Support
|
|
698
|
+
|
|
699
|
+
- **Issues**: [GitHub Issues](https://github.com/your-repo/securenow-npm)
|
|
700
|
+
- **Documentation**: [Full Docs](./INDEX.md)
|
|
701
|
+
- **Website**: [securenow.ai](http://securenow.ai/)
|