securenow 4.0.6 → 4.0.9
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/README.md +4 -3
- package/cli.js +4 -1
- package/docs/ARCHITECTURE.md +408 -0
- package/{AUTO-BODY-CAPTURE.md → docs/AUTO-BODY-CAPTURE.md} +3 -0
- package/docs/AUTO-SETUP-SUMMARY.md +331 -0
- package/{AUTO-SETUP.md → docs/AUTO-SETUP.md} +3 -0
- package/{AUTOMATIC-IP-CAPTURE.md → docs/AUTOMATIC-IP-CAPTURE.md} +3 -0
- package/{BODY-CAPTURE-FIX.md → docs/BODY-CAPTURE-FIX.md} +3 -0
- package/{BODY-CAPTURE-QUICKSTART.md → docs/BODY-CAPTURE-QUICKSTART.md} +147 -147
- package/docs/CHANGELOG-NEXTJS.md +235 -0
- package/docs/COMPLETION-REPORT.md +408 -0
- package/{EASIEST-SETUP.md → docs/EASIEST-SETUP.md} +3 -0
- package/docs/EXPRESS-BODY-CAPTURE.md +1027 -0
- package/{FINAL-SOLUTION.md → docs/FINAL-SOLUTION.md} +3 -0
- package/docs/IMPLEMENTATION-SUMMARY.md +410 -0
- package/docs/INDEX.md +129 -0
- package/{NEXTJS-BODY-CAPTURE-COMPARISON.md → docs/NEXTJS-BODY-CAPTURE-COMPARISON.md} +3 -0
- package/docs/NEXTJS-WEBPACK-WARNINGS.md +267 -0
- package/{NEXTJS-WRAPPER-APPROACH.md → docs/NEXTJS-WRAPPER-APPROACH.md} +3 -0
- package/{QUICKSTART-BODY-CAPTURE.md → docs/QUICKSTART-BODY-CAPTURE.md} +3 -0
- package/{REDACTION-EXAMPLES.md → docs/REDACTION-EXAMPLES.md} +3 -0
- package/{REQUEST-BODY-CAPTURE.md → docs/REQUEST-BODY-CAPTURE.md} +575 -575
- package/{SOLUTION-SUMMARY.md → docs/SOLUTION-SUMMARY.md} +3 -0
- package/docs/VERCEL-OTEL-MIGRATION.md +255 -0
- package/examples/README.md +3 -0
- package/examples/instrumentation-with-auto-capture.ts +3 -0
- package/examples/next.config.js +3 -0
- package/examples/nextjs-api-route-with-body-capture.ts +3 -0
- package/examples/nextjs-env-example.txt +3 -0
- package/examples/nextjs-instrumentation.js +3 -0
- package/examples/nextjs-instrumentation.ts +3 -0
- package/examples/nextjs-middleware.js +3 -0
- package/examples/nextjs-middleware.ts +3 -0
- package/examples/nextjs-with-options.ts +3 -0
- package/examples/test-nextjs-setup.js +3 -0
- package/nextjs-auto-capture.js +3 -0
- package/nextjs-middleware.js +3 -0
- package/nextjs-wrapper.js +3 -0
- package/nextjs.js +174 -72
- package/package.json +3 -19
- package/postinstall.js +310 -310
- package/tracing.js +287 -287
- /package/{CUSTOMER-GUIDE.md → docs/CUSTOMER-GUIDE.md} +0 -0
- /package/{NEXTJS-BODY-CAPTURE.md → docs/NEXTJS-BODY-CAPTURE.md} +0 -0
- /package/{NEXTJS-GUIDE.md → docs/NEXTJS-GUIDE.md} +0 -0
- /package/{NEXTJS-QUICKSTART.md → docs/NEXTJS-QUICKSTART.md} +0 -0
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ SECURENOW_INSTANCE=http://your-signoz-server:4318
|
|
|
36
36
|
npx securenow init
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
**Done!** 🎉 See [Next.js Complete Guide](./NEXTJS-GUIDE.md) for details.
|
|
39
|
+
**Done!** 🎉 See [Next.js Complete Guide](./docs/NEXTJS-GUIDE.md) for details.
|
|
40
40
|
|
|
41
41
|
---
|
|
42
42
|
|
|
@@ -126,8 +126,9 @@ SecureNow automatically instruments:
|
|
|
126
126
|
|
|
127
127
|
## 📚 Documentation
|
|
128
128
|
|
|
129
|
-
- **[Next.js Quick Start](./NEXTJS-QUICKSTART.md)** - Get started in 30 seconds
|
|
130
|
-
- **[Next.js Complete Guide](./NEXTJS-GUIDE.md)** - Full Next.js integration guide
|
|
129
|
+
- **[Next.js Quick Start](./docs/NEXTJS-QUICKSTART.md)** - Get started in 30 seconds
|
|
130
|
+
- **[Next.js Complete Guide](./docs/NEXTJS-GUIDE.md)** - Full Next.js integration guide
|
|
131
|
+
- **[📚 Complete Documentation](./docs/INDEX.md)** - All guides and references
|
|
131
132
|
- **[Examples](./examples/)** - Code examples for different setups
|
|
132
133
|
|
|
133
134
|
---
|
package/cli.js
CHANGED
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
# SecureNow Architecture
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
SecureNow provides seamless OpenTelemetry instrumentation for Node.js and Next.js applications with minimal configuration.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Component Architecture
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
13
|
+
│ SecureNow Package │
|
|
14
|
+
├─────────────────────────────────────────────────────────────┤
|
|
15
|
+
│ │
|
|
16
|
+
│ ┌─────────────┐ ┌──────────────┐ ┌──────────────┐ │
|
|
17
|
+
│ │ register.js │ │ tracing.js │ │ nextjs.js │ │
|
|
18
|
+
│ │ (Node.js │ │ (Manual │ │ (Next.js │ │
|
|
19
|
+
│ │ Preload) │ │ Setup) │ │ Integration)│ │
|
|
20
|
+
│ └─────────────┘ └──────────────┘ └──────────────┘ │
|
|
21
|
+
│ │ │ │ │
|
|
22
|
+
│ └─────────────────┴──────────────────┘ │
|
|
23
|
+
│ │ │
|
|
24
|
+
│ ▼ │
|
|
25
|
+
│ ┌──────────────────────────────────┐ │
|
|
26
|
+
│ │ OpenTelemetry Node SDK │ │
|
|
27
|
+
│ │ + Auto-Instrumentations │ │
|
|
28
|
+
│ └──────────────────────────────────┘ │
|
|
29
|
+
│ │ │
|
|
30
|
+
└───────────────────────────┼───────────────────────────────────┘
|
|
31
|
+
│
|
|
32
|
+
▼
|
|
33
|
+
┌──────────────────────────────────┐
|
|
34
|
+
│ OTLP/HTTP Trace Exporter │
|
|
35
|
+
└──────────────────────────────────┘
|
|
36
|
+
│
|
|
37
|
+
▼
|
|
38
|
+
┌──────────────────────────────────┐
|
|
39
|
+
│ SigNoz / OpenTelemetry │
|
|
40
|
+
│ Collector │
|
|
41
|
+
└──────────────────────────────────┘
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Entry Points
|
|
47
|
+
|
|
48
|
+
### 1. `register.js` - Node.js Preload (General Apps)
|
|
49
|
+
|
|
50
|
+
**Use Case:** Express, Fastify, NestJS, any Node.js app
|
|
51
|
+
|
|
52
|
+
**Usage:**
|
|
53
|
+
```bash
|
|
54
|
+
NODE_OPTIONS="-r securenow/register" node app.js
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**How it works:**
|
|
58
|
+
- Loads before your application code
|
|
59
|
+
- Imports `tracing.js` to initialize OpenTelemetry
|
|
60
|
+
- Works with any Node.js framework
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
### 2. `nextjs.js` - Next.js Integration
|
|
65
|
+
|
|
66
|
+
**Use Case:** Next.js applications (App Router & Pages Router)
|
|
67
|
+
|
|
68
|
+
**Usage:**
|
|
69
|
+
```typescript
|
|
70
|
+
// instrumentation.ts
|
|
71
|
+
import { registerSecureNow } from 'securenow/nextjs';
|
|
72
|
+
export function register() { registerSecureNow(); }
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**How it works:**
|
|
76
|
+
- Exports `registerSecureNow()` function
|
|
77
|
+
- Called by Next.js instrumentation hook
|
|
78
|
+
- Initializes OpenTelemetry SDK for Node.js runtime only
|
|
79
|
+
- Skips Edge runtime (not yet supported)
|
|
80
|
+
|
|
81
|
+
**Special features:**
|
|
82
|
+
- Detects Next.js environment variables (`VERCEL_ENV`, `VERCEL_REGION`)
|
|
83
|
+
- Uses `service.instance.id` for multi-worker deployments
|
|
84
|
+
- Disables noisy instrumentations (like `fs`) by default
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
### 3. `tracing.js` - Core Instrumentation
|
|
89
|
+
|
|
90
|
+
**Use Case:** Manual setup, or imported by other entry points
|
|
91
|
+
|
|
92
|
+
**Usage:**
|
|
93
|
+
```javascript
|
|
94
|
+
require('securenow/tracing');
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**How it works:**
|
|
98
|
+
- Core OpenTelemetry setup
|
|
99
|
+
- Configures OTLP exporter
|
|
100
|
+
- Initializes `getNodeAutoInstrumentations()`
|
|
101
|
+
- Handles graceful shutdown
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Configuration Flow
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
Environment Variables
|
|
109
|
+
│
|
|
110
|
+
├─► SECURENOW_APPID / OTEL_SERVICE_NAME
|
|
111
|
+
│ └─► service.name
|
|
112
|
+
│
|
|
113
|
+
├─► SECURENOW_INSTANCE / OTEL_EXPORTER_OTLP_ENDPOINT
|
|
114
|
+
│ └─► Traces endpoint URL
|
|
115
|
+
│
|
|
116
|
+
├─► OTEL_EXPORTER_OTLP_HEADERS
|
|
117
|
+
│ └─► Authentication headers
|
|
118
|
+
│
|
|
119
|
+
├─► SECURENOW_NO_UUID
|
|
120
|
+
│ └─► Disable UUID suffix
|
|
121
|
+
│
|
|
122
|
+
└─► SECURENOW_DISABLE_INSTRUMENTATIONS
|
|
123
|
+
└─► Disable specific instrumentations
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Auto-Instrumentation
|
|
129
|
+
|
|
130
|
+
SecureNow uses `@opentelemetry/auto-instrumentations-node` which includes:
|
|
131
|
+
|
|
132
|
+
### Web Frameworks
|
|
133
|
+
- `@opentelemetry/instrumentation-express`
|
|
134
|
+
- `@opentelemetry/instrumentation-fastify`
|
|
135
|
+
- `@opentelemetry/instrumentation-nestjs-core`
|
|
136
|
+
- `@opentelemetry/instrumentation-koa`
|
|
137
|
+
- `@opentelemetry/instrumentation-hapi`
|
|
138
|
+
|
|
139
|
+
### Databases
|
|
140
|
+
- `@opentelemetry/instrumentation-pg` (PostgreSQL)
|
|
141
|
+
- `@opentelemetry/instrumentation-mysql`
|
|
142
|
+
- `@opentelemetry/instrumentation-mysql2`
|
|
143
|
+
- `@opentelemetry/instrumentation-mongodb`
|
|
144
|
+
- `@opentelemetry/instrumentation-redis`
|
|
145
|
+
|
|
146
|
+
### HTTP & Network
|
|
147
|
+
- `@opentelemetry/instrumentation-http`
|
|
148
|
+
- `@opentelemetry/instrumentation-https`
|
|
149
|
+
- `@opentelemetry/instrumentation-fetch`
|
|
150
|
+
- `@opentelemetry/instrumentation-grpc`
|
|
151
|
+
- `@opentelemetry/instrumentation-graphql`
|
|
152
|
+
|
|
153
|
+
### Other
|
|
154
|
+
- `@opentelemetry/instrumentation-dns`
|
|
155
|
+
- `@opentelemetry/instrumentation-net`
|
|
156
|
+
- `@opentelemetry/instrumentation-fs`
|
|
157
|
+
- And many more...
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Data Flow
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
Your Application
|
|
165
|
+
│
|
|
166
|
+
├─► HTTP Request
|
|
167
|
+
├─► Database Query
|
|
168
|
+
├─► External API Call
|
|
169
|
+
└─► Custom Operations
|
|
170
|
+
│
|
|
171
|
+
▼
|
|
172
|
+
┌─────────────────┐
|
|
173
|
+
│ Auto │
|
|
174
|
+
│ Instrumentations│
|
|
175
|
+
└─────────────────┘
|
|
176
|
+
│
|
|
177
|
+
▼
|
|
178
|
+
┌─────────────────┐
|
|
179
|
+
│ OpenTelemetry │
|
|
180
|
+
│ SDK │
|
|
181
|
+
│ - Create Spans │
|
|
182
|
+
│ - Add Attributes│
|
|
183
|
+
│ - Sampling │
|
|
184
|
+
└─────────────────┘
|
|
185
|
+
│
|
|
186
|
+
▼
|
|
187
|
+
┌─────────────────┐
|
|
188
|
+
│ Batch Span │
|
|
189
|
+
│ Processor │
|
|
190
|
+
└─────────────────┘
|
|
191
|
+
│
|
|
192
|
+
▼
|
|
193
|
+
┌─────────────────┐
|
|
194
|
+
│ OTLP Trace │
|
|
195
|
+
│ Exporter │
|
|
196
|
+
│ (HTTP) │
|
|
197
|
+
└─────────────────┘
|
|
198
|
+
│
|
|
199
|
+
▼
|
|
200
|
+
┌─────────────────┐
|
|
201
|
+
│ SigNoz / │
|
|
202
|
+
│ OTLP Collector │
|
|
203
|
+
└─────────────────┘
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## Resource Attributes
|
|
209
|
+
|
|
210
|
+
Every span includes these resource attributes:
|
|
211
|
+
|
|
212
|
+
```javascript
|
|
213
|
+
{
|
|
214
|
+
"service.name": "my-app-uuid", // From SECURENOW_APPID
|
|
215
|
+
"service.instance.id": "my-app-uuid", // Unique per worker
|
|
216
|
+
"deployment.environment": "production", // From NODE_ENV
|
|
217
|
+
"service.version": "1.0.0", // From package.json
|
|
218
|
+
|
|
219
|
+
// Next.js specific
|
|
220
|
+
"next.runtime": "nodejs", // Next.js runtime type
|
|
221
|
+
"vercel.region": "iad1" // Vercel deployment region
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Span Lifecycle
|
|
228
|
+
|
|
229
|
+
```
|
|
230
|
+
1. Request arrives
|
|
231
|
+
│
|
|
232
|
+
▼
|
|
233
|
+
2. Auto-instrumentation creates root span
|
|
234
|
+
│
|
|
235
|
+
▼
|
|
236
|
+
3. Application code executes
|
|
237
|
+
- Child spans created automatically
|
|
238
|
+
- Database queries → spans
|
|
239
|
+
- HTTP calls → spans
|
|
240
|
+
- Framework operations → spans
|
|
241
|
+
│
|
|
242
|
+
▼
|
|
243
|
+
4. Request completes
|
|
244
|
+
│
|
|
245
|
+
▼
|
|
246
|
+
5. Spans end and are batched
|
|
247
|
+
│
|
|
248
|
+
▼
|
|
249
|
+
6. Batch sent to collector via HTTP
|
|
250
|
+
│
|
|
251
|
+
▼
|
|
252
|
+
7. Visible in SigNoz UI
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## Shutdown Process
|
|
258
|
+
|
|
259
|
+
```
|
|
260
|
+
Signal (SIGTERM/SIGINT)
|
|
261
|
+
│
|
|
262
|
+
▼
|
|
263
|
+
Shutdown handler triggered
|
|
264
|
+
│
|
|
265
|
+
├─► Flush pending spans
|
|
266
|
+
│
|
|
267
|
+
├─► Close exporter
|
|
268
|
+
│
|
|
269
|
+
└─► Exit process
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## Next.js Specific Behavior
|
|
275
|
+
|
|
276
|
+
### Instrumentation Hook Flow
|
|
277
|
+
|
|
278
|
+
```
|
|
279
|
+
1. Next.js starts
|
|
280
|
+
│
|
|
281
|
+
▼
|
|
282
|
+
2. Reads instrumentation.ts/js
|
|
283
|
+
│
|
|
284
|
+
▼
|
|
285
|
+
3. Calls register() function
|
|
286
|
+
│
|
|
287
|
+
▼
|
|
288
|
+
4. registerSecureNow() initializes
|
|
289
|
+
- Checks runtime (skip if Edge)
|
|
290
|
+
- Configures SDK
|
|
291
|
+
- Starts instrumentation
|
|
292
|
+
│
|
|
293
|
+
▼
|
|
294
|
+
5. Application code runs with tracing
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Runtime Detection
|
|
298
|
+
|
|
299
|
+
```javascript
|
|
300
|
+
if (process.env.NEXT_RUNTIME === 'edge') {
|
|
301
|
+
// Skip Edge runtime (not supported)
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Continue with Node.js runtime
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
## Performance Considerations
|
|
311
|
+
|
|
312
|
+
### Sampling
|
|
313
|
+
- Default: All spans sampled (100%)
|
|
314
|
+
- Configurable via OpenTelemetry SDK
|
|
315
|
+
|
|
316
|
+
### Batching
|
|
317
|
+
- Spans batched before export
|
|
318
|
+
- Reduces network calls
|
|
319
|
+
- Configurable batch size
|
|
320
|
+
|
|
321
|
+
### Overhead
|
|
322
|
+
- Typical overhead: 1-5% CPU
|
|
323
|
+
- Memory: ~10-50MB depending on traffic
|
|
324
|
+
- Negligible latency impact
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
## Security
|
|
329
|
+
|
|
330
|
+
### API Key Handling
|
|
331
|
+
```bash
|
|
332
|
+
# Passed via headers
|
|
333
|
+
OTEL_EXPORTER_OTLP_HEADERS="x-api-key=secret"
|
|
334
|
+
|
|
335
|
+
# Never logged or exposed
|
|
336
|
+
# Sent directly to collector
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### Network
|
|
340
|
+
- OTLP/HTTP uses standard HTTP(S)
|
|
341
|
+
- Supports TLS encryption
|
|
342
|
+
- Authentication via headers
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
## Troubleshooting
|
|
347
|
+
|
|
348
|
+
### Debug Mode
|
|
349
|
+
|
|
350
|
+
Enable verbose logging:
|
|
351
|
+
```bash
|
|
352
|
+
OTEL_LOG_LEVEL=debug
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
Output includes:
|
|
356
|
+
- SDK initialization
|
|
357
|
+
- Span creation
|
|
358
|
+
- Export attempts
|
|
359
|
+
- Errors
|
|
360
|
+
|
|
361
|
+
### Test Span
|
|
362
|
+
|
|
363
|
+
Create a test span on startup:
|
|
364
|
+
```bash
|
|
365
|
+
SECURENOW_TEST_SPAN=1
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
Verifies:
|
|
369
|
+
- SDK is initialized
|
|
370
|
+
- Tracer is working
|
|
371
|
+
- Configuration is correct
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
## Comparison Matrix
|
|
376
|
+
|
|
377
|
+
| Feature | register.js | nextjs.js | tracing.js |
|
|
378
|
+
|---------|-------------|-----------|------------|
|
|
379
|
+
| Node.js Apps | ✅ | ❌ | ✅ |
|
|
380
|
+
| Next.js | ❌ | ✅ | ❌ |
|
|
381
|
+
| Auto-preload | ✅ | ❌ | ❌ |
|
|
382
|
+
| Manual import | ❌ | ✅ | ✅ |
|
|
383
|
+
| Edge Runtime | ❌ | ⚠️ (skipped) | ❌ |
|
|
384
|
+
| PM2/Cluster | ✅ | ✅ | ✅ |
|
|
385
|
+
|
|
386
|
+
---
|
|
387
|
+
|
|
388
|
+
## Future Enhancements
|
|
389
|
+
|
|
390
|
+
- [ ] Edge Runtime support
|
|
391
|
+
- [ ] Browser instrumentation integration
|
|
392
|
+
- [ ] Metrics support (in addition to traces)
|
|
393
|
+
- [ ] Logs correlation
|
|
394
|
+
- [ ] Custom span decorators
|
|
395
|
+
- [ ] Configuration presets (development, production)
|
|
396
|
+
|
|
397
|
+
---
|
|
398
|
+
|
|
399
|
+
**For more details, see:**
|
|
400
|
+
- [NEXTJS-GUIDE.md](./NEXTJS-GUIDE.md) - Complete Next.js guide
|
|
401
|
+
- [README.md](./README.md) - General documentation
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|