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.
- package/CONSUMING-APPS-GUIDE.md +415 -0
- package/NPM_README.md +1328 -0
- package/docs/ALL-FRAMEWORKS-QUICKSTART.md +455 -0
- package/docs/ENVIRONMENT-VARIABLES.md +652 -0
- package/docs/EXPRESS-SETUP-GUIDE.md +720 -0
- package/docs/INDEX.md +206 -147
- package/docs/NEXTJS-SETUP-COMPLETE.md +795 -0
- package/package.json +4 -2
- package/tracing.d.ts +182 -182
- package/tracing.js +2 -2
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
# How to Use SecureNow Logging in Your App
|
|
2
|
+
|
|
3
|
+
This guide is for developers who want to add the `securenow` package to their applications to enable logging to SigNoz.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install securenow
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Setup Steps
|
|
16
|
+
|
|
17
|
+
### Step 1: Configure Environment Variables
|
|
18
|
+
|
|
19
|
+
Add these to your `.env` file or export them:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Required: Enable logging
|
|
23
|
+
SECURENOW_LOGGING_ENABLED=1
|
|
24
|
+
|
|
25
|
+
# Required: Your app name
|
|
26
|
+
SECURENOW_APPID=my-app-name
|
|
27
|
+
|
|
28
|
+
# Required: Your SigNoz endpoint
|
|
29
|
+
SECURENOW_INSTANCE=http://your-signoz-server:4318
|
|
30
|
+
|
|
31
|
+
# For SigNoz Cloud (optional):
|
|
32
|
+
# OTEL_EXPORTER_OTLP_HEADERS="signoz-ingestion-key=your-key"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
### Step 2: Choose Your Integration Method
|
|
38
|
+
|
|
39
|
+
You have **three options** to integrate logging:
|
|
40
|
+
|
|
41
|
+
#### **Option A: Automatic Console Instrumentation** (Recommended - Easiest)
|
|
42
|
+
|
|
43
|
+
This automatically captures all `console.log()`, `console.info()`, `console.warn()`, and `console.error()` calls and sends them to SigNoz.
|
|
44
|
+
|
|
45
|
+
**Add to your main application file:**
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
// At the very top of your app.js, index.js, server.js, or main.ts
|
|
49
|
+
require('securenow/register');
|
|
50
|
+
require('securenow/console-instrumentation');
|
|
51
|
+
|
|
52
|
+
// Now use console normally - all logs go to SigNoz!
|
|
53
|
+
console.log('Application started');
|
|
54
|
+
console.error('An error occurred', { userId: 123, details: 'Something went wrong' });
|
|
55
|
+
console.warn('Warning message');
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Or using NODE_OPTIONS (no code changes needed):**
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
NODE_OPTIONS="-r securenow/register -r securenow/console-instrumentation" node app.js
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
#### **Option B: Direct Logger API**
|
|
67
|
+
|
|
68
|
+
For more control over logging, use the OpenTelemetry logger API directly:
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
require('securenow/register');
|
|
72
|
+
const { getLogger } = require('securenow/tracing');
|
|
73
|
+
|
|
74
|
+
// Get a logger instance
|
|
75
|
+
const logger = getLogger('my-service', '1.0.0');
|
|
76
|
+
|
|
77
|
+
// Emit structured logs
|
|
78
|
+
logger.emit({
|
|
79
|
+
severityNumber: 9, // INFO level
|
|
80
|
+
severityText: 'INFO',
|
|
81
|
+
body: 'User logged in',
|
|
82
|
+
attributes: {
|
|
83
|
+
userId: 123,
|
|
84
|
+
username: 'john',
|
|
85
|
+
ip: '192.168.1.1',
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Severity Levels:**
|
|
91
|
+
- `5` = DEBUG
|
|
92
|
+
- `9` = INFO
|
|
93
|
+
- `13` = WARN
|
|
94
|
+
- `17` = ERROR
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
#### **Option C: Custom Logger Wrapper**
|
|
99
|
+
|
|
100
|
+
Create your own logger wrapper for cleaner API:
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
// logger.js
|
|
104
|
+
require('securenow/register');
|
|
105
|
+
const { getLogger } = require('securenow/tracing');
|
|
106
|
+
|
|
107
|
+
const logger = getLogger('app-logger', '1.0.0');
|
|
108
|
+
|
|
109
|
+
const SeverityNumber = {
|
|
110
|
+
DEBUG: 5,
|
|
111
|
+
INFO: 9,
|
|
112
|
+
WARN: 13,
|
|
113
|
+
ERROR: 17,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
function log(level, message, attributes = {}) {
|
|
117
|
+
if (logger) {
|
|
118
|
+
logger.emit({
|
|
119
|
+
severityNumber: SeverityNumber[level],
|
|
120
|
+
severityText: level,
|
|
121
|
+
body: message,
|
|
122
|
+
attributes,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
console.log(`[${level}] ${message}`, attributes);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
module.exports = {
|
|
129
|
+
debug: (msg, attrs) => log('DEBUG', msg, attrs),
|
|
130
|
+
info: (msg, attrs) => log('INFO', msg, attrs),
|
|
131
|
+
warn: (msg, attrs) => log('WARN', msg, attrs),
|
|
132
|
+
error: (msg, attrs) => log('ERROR', msg, attrs),
|
|
133
|
+
};
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Usage:**
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
const logger = require('./logger');
|
|
140
|
+
|
|
141
|
+
logger.info('User signed up', { userId: 456, email: 'user@example.com' });
|
|
142
|
+
logger.error('Payment failed', { orderId: 789, amount: 99.99 });
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Framework-Specific Setup
|
|
148
|
+
|
|
149
|
+
### Express.js
|
|
150
|
+
|
|
151
|
+
```javascript
|
|
152
|
+
// app.js
|
|
153
|
+
require('securenow/register');
|
|
154
|
+
require('securenow/console-instrumentation');
|
|
155
|
+
|
|
156
|
+
const express = require('express');
|
|
157
|
+
const app = express();
|
|
158
|
+
|
|
159
|
+
app.get('/', (req, res) => {
|
|
160
|
+
console.log('Home page accessed');
|
|
161
|
+
res.send('Hello World');
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
app.listen(3000, () => {
|
|
165
|
+
console.log('Server running on port 3000');
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Run:**
|
|
170
|
+
```bash
|
|
171
|
+
SECURENOW_LOGGING_ENABLED=1 SECURENOW_APPID=express-app node app.js
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
### Next.js (App Router)
|
|
177
|
+
|
|
178
|
+
**1. Create `instrumentation.ts` in project root:**
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
// instrumentation.ts
|
|
182
|
+
export async function register() {
|
|
183
|
+
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
|
184
|
+
process.env.SECURENOW_LOGGING_ENABLED = '1';
|
|
185
|
+
await import('securenow/register');
|
|
186
|
+
await import('securenow/console-instrumentation');
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**2. Enable in `next.config.js`:**
|
|
192
|
+
|
|
193
|
+
```javascript
|
|
194
|
+
/** @type {import('next').NextConfig} */
|
|
195
|
+
const nextConfig = {
|
|
196
|
+
experimental: {
|
|
197
|
+
instrumentationHook: true,
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
module.exports = nextConfig;
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**3. Add to `.env.local`:**
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
SECURENOW_LOGGING_ENABLED=1
|
|
208
|
+
SECURENOW_APPID=my-nextjs-app
|
|
209
|
+
SECURENOW_INSTANCE=http://localhost:4318
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**4. Use in API routes:**
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
// app/api/users/route.ts
|
|
216
|
+
export async function GET() {
|
|
217
|
+
console.log('GET /api/users called');
|
|
218
|
+
const users = await fetchUsers();
|
|
219
|
+
console.info('Users fetched', { count: users.length });
|
|
220
|
+
return Response.json(users);
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
### Fastify
|
|
227
|
+
|
|
228
|
+
```javascript
|
|
229
|
+
// server.js
|
|
230
|
+
require('securenow/register');
|
|
231
|
+
require('securenow/console-instrumentation');
|
|
232
|
+
|
|
233
|
+
const fastify = require('fastify')();
|
|
234
|
+
|
|
235
|
+
fastify.get('/', async () => {
|
|
236
|
+
console.log('Root endpoint called');
|
|
237
|
+
return { hello: 'world' };
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
fastify.listen({ port: 3000 });
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
### NestJS
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
// main.ts
|
|
249
|
+
require('securenow/register');
|
|
250
|
+
require('securenow/console-instrumentation');
|
|
251
|
+
|
|
252
|
+
import { NestFactory } from '@nestjs/core';
|
|
253
|
+
import { AppModule } from './app.module';
|
|
254
|
+
|
|
255
|
+
async function bootstrap() {
|
|
256
|
+
const app = await NestFactory.create(AppModule);
|
|
257
|
+
console.log('NestJS application starting');
|
|
258
|
+
await app.listen(3000);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
bootstrap();
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## Verification
|
|
267
|
+
|
|
268
|
+
After starting your app, you should see:
|
|
269
|
+
|
|
270
|
+
```
|
|
271
|
+
[securenow] OTel SDK started → http://your-signoz-server:4318/v1/traces
|
|
272
|
+
[securenow] 📋 Logging: ENABLED → http://your-signoz-server:4318/v1/logs
|
|
273
|
+
[securenow] Console instrumentation installed
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## View Logs in SigNoz
|
|
279
|
+
|
|
280
|
+
1. Open your SigNoz dashboard
|
|
281
|
+
2. Go to **Logs** section
|
|
282
|
+
3. Filter by `service.name = my-app-name`
|
|
283
|
+
4. See all your logs with:
|
|
284
|
+
- Automatic severity levels
|
|
285
|
+
- Structured attributes
|
|
286
|
+
- Trace correlation
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## Common Issues
|
|
291
|
+
|
|
292
|
+
### Logs Not Appearing
|
|
293
|
+
|
|
294
|
+
**Check 1:** Verify `SECURENOW_LOGGING_ENABLED=1` is set
|
|
295
|
+
|
|
296
|
+
```bash
|
|
297
|
+
echo $SECURENOW_LOGGING_ENABLED # Should output: 1
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
**Check 2:** Verify endpoint is correct
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
# Self-hosted SigNoz
|
|
304
|
+
export SECURENOW_INSTANCE=http://localhost:4318
|
|
305
|
+
|
|
306
|
+
# SigNoz Cloud
|
|
307
|
+
export SECURENOW_INSTANCE=https://ingest.<region>.signoz.cloud:443
|
|
308
|
+
export OTEL_EXPORTER_OTLP_HEADERS="signoz-ingestion-key=<your-key>"
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
**Check 3:** Enable debug logging
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
export OTEL_LOG_LEVEL=debug
|
|
315
|
+
node app.js
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
### Console Instrumentation Not Working
|
|
321
|
+
|
|
322
|
+
Make sure the load order is correct:
|
|
323
|
+
|
|
324
|
+
```javascript
|
|
325
|
+
// ✅ Correct
|
|
326
|
+
require('securenow/register');
|
|
327
|
+
require('securenow/console-instrumentation');
|
|
328
|
+
const express = require('express');
|
|
329
|
+
|
|
330
|
+
// ❌ Wrong
|
|
331
|
+
const express = require('express');
|
|
332
|
+
require('securenow/register');
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
### Logger Returns Null
|
|
338
|
+
|
|
339
|
+
This happens when logging is disabled:
|
|
340
|
+
|
|
341
|
+
```javascript
|
|
342
|
+
const { getLogger } = require('securenow/tracing');
|
|
343
|
+
const logger = getLogger('test');
|
|
344
|
+
|
|
345
|
+
if (!logger) {
|
|
346
|
+
console.log('Set SECURENOW_LOGGING_ENABLED=1 to enable logging');
|
|
347
|
+
}
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## Environment Variables Reference
|
|
353
|
+
|
|
354
|
+
```bash
|
|
355
|
+
# Logging
|
|
356
|
+
SECURENOW_LOGGING_ENABLED=1 # Enable/disable logging (default: 1)
|
|
357
|
+
|
|
358
|
+
# Connection
|
|
359
|
+
SECURENOW_INSTANCE=http://localhost:4318 # OTLP endpoint
|
|
360
|
+
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=... # Override logs endpoint
|
|
361
|
+
|
|
362
|
+
# Authentication
|
|
363
|
+
OTEL_EXPORTER_OTLP_HEADERS="signoz-ingestion-key=KEY"
|
|
364
|
+
|
|
365
|
+
# Service Info
|
|
366
|
+
SECURENOW_APPID=my-app # Your app name
|
|
367
|
+
OTEL_SERVICE_NAME=my-app # Alternative
|
|
368
|
+
|
|
369
|
+
# Debugging
|
|
370
|
+
OTEL_LOG_LEVEL=debug # Enable debug output
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
## Best Practices
|
|
376
|
+
|
|
377
|
+
1. **Use Structured Logging** - Pass objects with meaningful attributes
|
|
378
|
+
```javascript
|
|
379
|
+
console.log('User action', { userId: 123, action: 'login' });
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
2. **Choose Appropriate Severity Levels**
|
|
383
|
+
- `console.log()` / `console.info()` - Normal operations
|
|
384
|
+
- `console.warn()` - Warnings, deprecations
|
|
385
|
+
- `console.error()` - Errors, exceptions
|
|
386
|
+
|
|
387
|
+
3. **Include Context** - Add userId, requestId, etc. to log attributes
|
|
388
|
+
|
|
389
|
+
4. **Don't Log Sensitive Data** - SecureNow automatically redacts passwords, tokens, etc.
|
|
390
|
+
|
|
391
|
+
5. **Use Different Loggers for Different Modules**
|
|
392
|
+
```javascript
|
|
393
|
+
const authLogger = getLogger('auth-service');
|
|
394
|
+
const dbLogger = getLogger('database');
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
---
|
|
398
|
+
|
|
399
|
+
## Complete Documentation
|
|
400
|
+
|
|
401
|
+
- [Logging Quick Start](./docs/LOGGING-QUICKSTART.md)
|
|
402
|
+
- [Logging Complete Guide](./docs/LOGGING-GUIDE.md)
|
|
403
|
+
- [All Examples](./examples/)
|
|
404
|
+
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
## Support
|
|
408
|
+
|
|
409
|
+
- **Documentation**: [Full Docs](./docs/INDEX.md)
|
|
410
|
+
- **Website**: [securenow.ai](http://securenow.ai/)
|
|
411
|
+
- **Issues**: GitHub Issues
|
|
412
|
+
|
|
413
|
+
---
|
|
414
|
+
|
|
415
|
+
**That's it!** Your app is now sending logs to SigNoz. 🎉
|