securenow 7.6.7 → 7.6.8
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/NPM_README.md +13 -13
- package/README.md +21 -37
- package/app-config.js +5 -3
- package/cli/config.js +4 -3
- package/cli/diagnostics.js +54 -15
- package/cli/run.js +40 -11
- package/firewall-only.js +1 -1
- package/mcp/catalog.js +1 -1
- package/nextjs-webpack-config.js +3 -15
- package/nextjs.js +21 -23
- package/nuxt-server-plugin.mjs +20 -10
- package/package.json +33 -34
- package/register.js +1 -1
- package/tracing.js +17 -7
- package/web-vite.mjs +23 -13
- package/CONSUMING-APPS-GUIDE.md +0 -463
- package/docs/ALL-FRAMEWORKS-QUICKSTART.md +0 -1388
- package/docs/API-KEYS-GUIDE.md +0 -278
- package/docs/ARCHITECTURE.md +0 -408
- package/docs/AUTO-BODY-CAPTURE.md +0 -412
- package/docs/AUTO-SETUP-SUMMARY.md +0 -331
- package/docs/AUTO-SETUP.md +0 -419
- package/docs/AUTOMATIC-IP-CAPTURE.md +0 -359
- package/docs/BODY-CAPTURE-FIX.md +0 -261
- package/docs/BODY-CAPTURE-QUICKSTART.md +0 -147
- package/docs/CHANGELOG-NEXTJS.md +0 -235
- package/docs/COMPLETION-REPORT.md +0 -408
- package/docs/CUSTOMER-GUIDE.md +0 -364
- package/docs/EASIEST-SETUP.md +0 -342
- package/docs/ENVIRONMENT-VARIABLES.md +0 -166
- package/docs/ENVIRONMENTS.md +0 -60
- package/docs/EXPRESS-BODY-CAPTURE.md +0 -1028
- package/docs/EXPRESS-SETUP-GUIDE.md +0 -722
- package/docs/FINAL-SOLUTION.md +0 -335
- package/docs/FIREWALL-GUIDE.md +0 -440
- package/docs/IMPLEMENTATION-SUMMARY.md +0 -410
- package/docs/INDEX.md +0 -222
- package/docs/LOGGING-GUIDE.md +0 -704
- package/docs/LOGGING-QUICKSTART.md +0 -221
- package/docs/MCP-GUIDE.md +0 -58
- package/docs/NEXTJS-BODY-CAPTURE-COMPARISON.md +0 -323
- package/docs/NEXTJS-BODY-CAPTURE.md +0 -368
- package/docs/NEXTJS-GUIDE.md +0 -392
- package/docs/NEXTJS-QUICKSTART.md +0 -83
- package/docs/NEXTJS-SETUP-COMPLETE.md +0 -795
- package/docs/NEXTJS-WEBPACK-WARNINGS.md +0 -267
- package/docs/NEXTJS-WRAPPER-APPROACH.md +0 -414
- package/docs/NUXT-GUIDE.md +0 -173
- package/docs/QUICKSTART-BODY-CAPTURE.md +0 -293
- package/docs/REDACTION-EXAMPLES.md +0 -484
- package/docs/REQUEST-BODY-CAPTURE.md +0 -587
- package/docs/SOLUTION-SUMMARY.md +0 -312
- package/docs/VERCEL-OTEL-MIGRATION.md +0 -255
- package/examples/README.md +0 -265
- package/examples/express-with-logging.js +0 -137
- package/examples/instrumentation-with-auto-capture.ts +0 -41
- package/examples/next.config.js +0 -37
- package/examples/nextjs-api-route-with-body-capture.ts +0 -54
- package/examples/nextjs-env-example.txt +0 -32
- package/examples/nextjs-instrumentation.js +0 -36
- package/examples/nextjs-instrumentation.ts +0 -36
- package/examples/nextjs-middleware.js +0 -37
- package/examples/nextjs-middleware.ts +0 -37
- package/examples/nextjs-with-logging-example.md +0 -301
- package/examples/nextjs-with-options.ts +0 -36
- package/examples/test-nextjs-setup.js +0 -70
- package/postinstall.js +0 -296
package/docs/API-KEYS-GUIDE.md
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
# SecureNow API Keys
|
|
2
|
-
|
|
3
|
-
API keys provide programmatic access to the SecureNow platform. They support granular feature-level permissions, application scoping, IP allowlisting, and secure one-time-copy generation.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## Creating an API Key
|
|
8
|
-
|
|
9
|
-
### From the Dashboard
|
|
10
|
-
|
|
11
|
-
1. Go to **Settings → API Keys**
|
|
12
|
-
2. Click **Create API Key**
|
|
13
|
-
3. Enter a name (e.g., "Production Firewall", "CI/CD Pipeline")
|
|
14
|
-
4. Select the scopes (permissions) you need
|
|
15
|
-
5. Optionally restrict to specific applications and IP addresses
|
|
16
|
-
6. Click **Create**
|
|
17
|
-
7. **Copy the key immediately** — it will only be shown once
|
|
18
|
-
|
|
19
|
-
### From the CLI
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
npx securenow login
|
|
23
|
-
npx securenow firewall status
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
The `securenow init` and `securenow login` commands can automatically provision a firewall API key for you.
|
|
27
|
-
|
|
28
|
-
---
|
|
29
|
-
|
|
30
|
-
## Key Format
|
|
31
|
-
|
|
32
|
-
All API keys use the format:
|
|
33
|
-
|
|
34
|
-
```
|
|
35
|
-
snk_live_<64 hex characters>
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Example: `snk_live_a1b2c3d4e5f6...`
|
|
39
|
-
|
|
40
|
-
The `snk_live_` prefix makes it easy to identify SecureNow keys in your codebase and credential scanners.
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
## Storing the API Key
|
|
45
|
-
|
|
46
|
-
Since v7.1.0, the firewall reads its API key from `.securenow/credentials.json` as well as `SECURENOW_API_KEY`. You don't need to manage env vars for local dev.
|
|
47
|
-
|
|
48
|
-
**Resolution order (firewall):**
|
|
49
|
-
|
|
50
|
-
1. `SECURENOW_API_KEY` env var — **only if it starts with `snk_live_`** (non-matching values are ignored so the file can still win)
|
|
51
|
-
2. Project `./.securenow/credentials.json`
|
|
52
|
-
3. Global `~/.securenow/credentials.json`
|
|
53
|
-
|
|
54
|
-
### Writing the key to the credentials file
|
|
55
|
-
|
|
56
|
-
```bash
|
|
57
|
-
# Interactive onboarding - picks/creates an app, enables that app's firewall,
|
|
58
|
-
# and mints a key scoped firewall:read + blocklist:read + allowlist:read
|
|
59
|
-
# (the "firewall" preset, used by default for CLI firewall onboarding)
|
|
60
|
-
# and writes it to ./.securenow/credentials.json automatically.
|
|
61
|
-
npx securenow login
|
|
62
|
-
|
|
63
|
-
# Already have a key? Write it directly:
|
|
64
|
-
npx securenow api-key set snk_live_abc123...
|
|
65
|
-
|
|
66
|
-
# Save to ~/.securenow/ instead of the project
|
|
67
|
-
npx securenow api-key set snk_live_abc123... --global
|
|
68
|
-
|
|
69
|
-
# Inspect (masked) and see which file it came from
|
|
70
|
-
npx securenow api-key show
|
|
71
|
-
|
|
72
|
-
# Remove just the API key (leaves session/app in place)
|
|
73
|
-
npx securenow api-key clear
|
|
74
|
-
npx securenow api-key clear --global
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
The key must start with `snk_live_` — `api-key set` rejects anything else.
|
|
78
|
-
|
|
79
|
-
---
|
|
80
|
-
|
|
81
|
-
## Scopes (Permissions)
|
|
82
|
-
|
|
83
|
-
Each API key has a set of scopes that control what it can access. Scopes follow the `resource:action` pattern.
|
|
84
|
-
|
|
85
|
-
| Scope | Description |
|
|
86
|
-
|-------|-------------|
|
|
87
|
-
| `firewall:read` | Read the blocklist (used by the firewall SDK) |
|
|
88
|
-
| `blocklist:read` | List and check blocked IPs |
|
|
89
|
-
| `blocklist:write` | Add and remove blocked IPs |
|
|
90
|
-
| `applications:read` | List and view applications |
|
|
91
|
-
| `applications:write` | Create and delete applications |
|
|
92
|
-
| `traces:read` | Query traces |
|
|
93
|
-
| `logs:read` | Query logs |
|
|
94
|
-
| `issues:read` | List and view security issues |
|
|
95
|
-
| `issues:write` | Resolve and manage issues |
|
|
96
|
-
| `alerts:read` | View alert rules, channels, and history |
|
|
97
|
-
| `alerts:write` | Create and manage alert rules |
|
|
98
|
-
| `analytics:read` | View analytics data |
|
|
99
|
-
| `forensics:read` | Run forensic queries |
|
|
100
|
-
| `ip:read` | IP intelligence lookups |
|
|
101
|
-
| `trusted:read` | List trusted IPs |
|
|
102
|
-
| `trusted:write` | Manage trusted IPs |
|
|
103
|
-
| `notifications:read` | List notifications |
|
|
104
|
-
| `notifications:write` | Mark notifications as read |
|
|
105
|
-
| `api-map:read` | View API map |
|
|
106
|
-
| `instances:read` | List instances |
|
|
107
|
-
| `false-positives:read` | List false positive rules |
|
|
108
|
-
| `false-positives:write` | Create and manage false positive rules |
|
|
109
|
-
|
|
110
|
-
### Principle of Least Privilege
|
|
111
|
-
|
|
112
|
-
Only grant the scopes your use case requires:
|
|
113
|
-
|
|
114
|
-
- **Firewall SDK:** `firewall:read`
|
|
115
|
-
- **CI/CD monitoring:** `issues:read`, `traces:read`
|
|
116
|
-
- **Automated remediation:** `blocklist:read`, `blocklist:write`
|
|
117
|
-
- **Dashboard integration:** all `*:read` scopes
|
|
118
|
-
|
|
119
|
-
---
|
|
120
|
-
|
|
121
|
-
## Application Scoping
|
|
122
|
-
|
|
123
|
-
Restrict an API key to specific applications. When set, the key can only access data for those applications.
|
|
124
|
-
|
|
125
|
-
Leave empty to allow access to all applications on your account.
|
|
126
|
-
|
|
127
|
-
**Alert rules:** Keys that are scoped to specific applications **cannot** create or update alert rules with **`applicationsAll: true`** (“all applications”). Use explicit app keys on each rule instead. Unscoped keys may use all-apps mode.
|
|
128
|
-
|
|
129
|
-
---
|
|
130
|
-
|
|
131
|
-
## IP Allowlisting
|
|
132
|
-
|
|
133
|
-
Restrict an API key to specific client IPs or CIDR ranges. When set, requests from other IPs are rejected with 403.
|
|
134
|
-
|
|
135
|
-
```
|
|
136
|
-
34.56.78.90
|
|
137
|
-
10.0.0.0/24
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
Leave empty to allow from any IP.
|
|
141
|
-
|
|
142
|
-
---
|
|
143
|
-
|
|
144
|
-
## Using API Keys
|
|
145
|
-
|
|
146
|
-
### In HTTP Requests
|
|
147
|
-
|
|
148
|
-
Pass the API key in the `Authorization` header:
|
|
149
|
-
|
|
150
|
-
```bash
|
|
151
|
-
curl -s https://api.securenow.ai/api/v1/blocklist \
|
|
152
|
-
-H "Authorization: Bearer snk_live_abc123..."
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### In the Firewall SDK
|
|
156
|
-
|
|
157
|
-
Easiest path (v7.1+) — let the CLI write the key to the credentials file for you:
|
|
158
|
-
|
|
159
|
-
```bash
|
|
160
|
-
npx securenow login # firewall onboarding in the browser
|
|
161
|
-
# or, if you already have a key:
|
|
162
|
-
npx securenow api-key set snk_live_abc...
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
Or set the env var the old way:
|
|
166
|
-
|
|
167
|
-
```bash
|
|
168
|
-
SECURENOW_API_KEY=snk_live_abc123...
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
The firewall SDK reads the credentials file on startup if the env var is unset (or isn't a `snk_live_` key). Env vars still take precedence when present and well-formed — useful in CI / Docker / prod.
|
|
172
|
-
|
|
173
|
-
### In CI/CD
|
|
174
|
-
|
|
175
|
-
```yaml
|
|
176
|
-
# GitHub Actions example — SDK firewall key
|
|
177
|
-
env:
|
|
178
|
-
SECURENOW_API_KEY: ${{ secrets.SECURENOW_API_KEY }}
|
|
179
|
-
|
|
180
|
-
steps:
|
|
181
|
-
- run: |
|
|
182
|
-
ISSUES=$(curl -s https://api.securenow.ai/api/v1/issues \
|
|
183
|
-
-H "Authorization: Bearer $SECURENOW_API_KEY")
|
|
184
|
-
echo "$ISSUES" | jq '.issues | length'
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
### CLI Authentication in CI/CD
|
|
188
|
-
|
|
189
|
-
For CLI commands in CI, use the `SECURENOW_TOKEN` env var to skip file-based login:
|
|
190
|
-
|
|
191
|
-
```yaml
|
|
192
|
-
# GitHub Actions example — CLI auth via env var
|
|
193
|
-
env:
|
|
194
|
-
SECURENOW_TOKEN: ${{ secrets.SECURENOW_CLI_TOKEN }}
|
|
195
|
-
|
|
196
|
-
steps:
|
|
197
|
-
- run: npx securenow issues --json --status open
|
|
198
|
-
- run: npx securenow forensics "critical attacks in last 24h" --json
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
The `SECURENOW_TOKEN` env var takes priority over any stored credentials.
|
|
202
|
-
|
|
203
|
-
---
|
|
204
|
-
|
|
205
|
-
## Key Management
|
|
206
|
-
|
|
207
|
-
### Viewing Keys
|
|
208
|
-
|
|
209
|
-
```bash
|
|
210
|
-
# From the CLI
|
|
211
|
-
npx securenow api-keys list
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
Or go to **Settings → API Keys** in the dashboard. You'll see the key name, last 4 characters, status, scopes, and last used timestamp.
|
|
215
|
-
|
|
216
|
-
### Revoking a Key
|
|
217
|
-
|
|
218
|
-
```bash
|
|
219
|
-
npx securenow api-keys revoke <key-id>
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
Or click **Revoke** in the dashboard. Revoked keys immediately stop working. This cannot be undone.
|
|
223
|
-
|
|
224
|
-
### Regenerating a Key
|
|
225
|
-
|
|
226
|
-
Regeneration creates a new key with the same name, scopes, and settings. The old key is automatically revoked.
|
|
227
|
-
|
|
228
|
-
---
|
|
229
|
-
|
|
230
|
-
## Rate Limits
|
|
231
|
-
|
|
232
|
-
API keys are subject to rate limiting:
|
|
233
|
-
|
|
234
|
-
| Endpoint | Limit |
|
|
235
|
-
|----------|-------|
|
|
236
|
-
| General API (`/api/*`) | 600 requests/minute |
|
|
237
|
-
| Firewall sync (`/api/firewall/*`) | 120 requests/minute |
|
|
238
|
-
|
|
239
|
-
Rate limit headers are included in every response:
|
|
240
|
-
|
|
241
|
-
```
|
|
242
|
-
X-RateLimit-Limit: 600
|
|
243
|
-
X-RateLimit-Remaining: 597
|
|
244
|
-
X-RateLimit-Reset: 1712534400
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
---
|
|
248
|
-
|
|
249
|
-
## Security Best Practices
|
|
250
|
-
|
|
251
|
-
1. **Never commit API keys to source control.** Use `.env` files or secret managers.
|
|
252
|
-
2. **Use the minimum scopes required.** A firewall key only needs `firewall:read`.
|
|
253
|
-
3. **Restrict by IP when possible.** Server keys should be locked to your server IPs.
|
|
254
|
-
4. **Rotate keys periodically.** Use the regenerate feature to rotate without downtime.
|
|
255
|
-
5. **Monitor usage.** Check the "last used" timestamp and known IPs in the dashboard.
|
|
256
|
-
6. **Revoke unused keys.** Delete keys that are no longer in use.
|
|
257
|
-
|
|
258
|
-
---
|
|
259
|
-
|
|
260
|
-
## API Versioning
|
|
261
|
-
|
|
262
|
-
All API endpoints are available at both `/api/` and `/api/v1/`. We recommend using the versioned path for stability:
|
|
263
|
-
|
|
264
|
-
```bash
|
|
265
|
-
# Recommended
|
|
266
|
-
https://api.securenow.ai/api/v1/blocklist
|
|
267
|
-
|
|
268
|
-
# Also works (unversioned)
|
|
269
|
-
https://api.securenow.ai/api/blocklist
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
---
|
|
273
|
-
|
|
274
|
-
## Related Documentation
|
|
275
|
-
|
|
276
|
-
- [Firewall Guide](./FIREWALL-GUIDE.md) — Automatic IP blocking setup
|
|
277
|
-
- [Environment Variables Reference](./ENVIRONMENT-VARIABLES.md) — All configuration options
|
|
278
|
-
- [All Frameworks Quick Start](./ALL-FRAMEWORKS-QUICKSTART.md) — Framework setup guides
|
package/docs/ARCHITECTURE.md
DELETED
|
@@ -1,408 +0,0 @@
|
|
|
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
|
-
│ SecureNow / 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
|
-
│ SecureNow / │
|
|
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 SecureNow 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
|
-
|