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/README.md
CHANGED
|
@@ -70,9 +70,7 @@ Run `npx securenow help` for all commands. See the [CLI Reference](#cli-referenc
|
|
|
70
70
|
|
|
71
71
|
---
|
|
72
72
|
|
|
73
|
-
### For Node.js Applications (Express, Fastify, NestJS, etc.)
|
|
74
|
-
|
|
75
|
-
#### Tracing Only
|
|
73
|
+
### For Node.js Applications (Express, Fastify, NestJS, Koa, Hapi, h3, Polka, Hono, Feathers, etc.)
|
|
76
74
|
|
|
77
75
|
```bash
|
|
78
76
|
# 1. Install
|
|
@@ -80,30 +78,20 @@ npm install securenow
|
|
|
80
78
|
|
|
81
79
|
# 2. Set environment variables
|
|
82
80
|
export SECURENOW_APPID=my-app
|
|
83
|
-
export SECURENOW_INSTANCE=
|
|
81
|
+
export SECURENOW_INSTANCE=https://freetrial.securenow.ai:4318
|
|
82
|
+
export SECURENOW_LOGGING_ENABLED=1
|
|
83
|
+
export SECURENOW_NO_UUID=1
|
|
84
84
|
|
|
85
85
|
# 3. Run with preload
|
|
86
86
|
NODE_OPTIONS="-r securenow/register" node app.js
|
|
87
|
-
# or
|
|
88
|
-
NODE_OPTIONS="-r securenow/register" npm start
|
|
89
87
|
```
|
|
90
88
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
# 1. Install
|
|
95
|
-
npm install securenow
|
|
89
|
+
That's it. Traces are captured automatically via OpenTelemetry HTTP instrumentation.
|
|
90
|
+
Since **v5.6.0**, when `SECURENOW_LOGGING_ENABLED=1`, all `console.log`/`warn`/`error` calls are
|
|
91
|
+
**automatically** forwarded as OTLP log records — no extra require needed.
|
|
96
92
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
export SECURENOW_INSTANCE=http://your-otlp-collector:4318
|
|
100
|
-
export SECURENOW_LOGGING_ENABLED=1
|
|
101
|
-
|
|
102
|
-
# 3. Run with preload (adds logging)
|
|
103
|
-
NODE_OPTIONS="-r securenow/register -r securenow/console-instrumentation" node app.js
|
|
104
|
-
|
|
105
|
-
# Now all console.log/info/warn/error automatically go to your OTLP backend (for example SecureNow)!
|
|
106
|
-
```
|
|
93
|
+
See the [All Frameworks Quick Start](./docs/ALL-FRAMEWORKS-QUICKSTART.md) for tested setup guides
|
|
94
|
+
for Express, Fastify, Koa, NestJS, Hapi, h3, Polka, Micro, Hono, and Feathers.
|
|
107
95
|
|
|
108
96
|
---
|
|
109
97
|
|
package/cli/monitor.js
CHANGED
|
@@ -105,7 +105,19 @@ async function tracesAnalyze(args, flags) {
|
|
|
105
105
|
|
|
106
106
|
const s = ui.spinner('Analyzing trace with AI');
|
|
107
107
|
try {
|
|
108
|
-
|
|
108
|
+
let result = await api.post('/traces/analyze', { traceId });
|
|
109
|
+
|
|
110
|
+
if (result.analysisId && result.status === 'running') {
|
|
111
|
+
const analysisId = result.analysisId;
|
|
112
|
+
for (let i = 0; i < 120; i++) {
|
|
113
|
+
await new Promise(r => setTimeout(r, 3000));
|
|
114
|
+
result = await api.get(`/traces/analyze/${analysisId}`);
|
|
115
|
+
if (result.status === 'completed' || result.status === 'failed') break;
|
|
116
|
+
}
|
|
117
|
+
if (result.status === 'failed') throw new Error(result.error || 'Analysis failed');
|
|
118
|
+
if (result.status === 'running') throw new Error('Analysis timed out');
|
|
119
|
+
}
|
|
120
|
+
|
|
109
121
|
s.stop('Analysis complete');
|
|
110
122
|
|
|
111
123
|
if (flags.json) { ui.json(result); return; }
|
package/cli.js
CHANGED
|
@@ -71,13 +71,17 @@ function formatMessage(args) {
|
|
|
71
71
|
.join(' ');
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
const { context, trace } = require('@opentelemetry/api');
|
|
75
|
+
|
|
74
76
|
/**
|
|
75
|
-
* Emit a log record
|
|
77
|
+
* Emit a log record, correlating with the active trace/span when available
|
|
76
78
|
*/
|
|
77
79
|
function emitLog(severityNumber, severityText, args) {
|
|
78
80
|
const message = formatMessage(args);
|
|
79
81
|
|
|
80
82
|
try {
|
|
83
|
+
const activeCtx = context.active();
|
|
84
|
+
const spanCtx = trace.getSpanContext(activeCtx);
|
|
81
85
|
logger.emit({
|
|
82
86
|
severityNumber,
|
|
83
87
|
severityText,
|
|
@@ -86,6 +90,7 @@ function emitLog(severityNumber, severityText, args) {
|
|
|
86
90
|
'log.source': 'console',
|
|
87
91
|
'log.method': severityText.toLowerCase(),
|
|
88
92
|
},
|
|
93
|
+
...(spanCtx && { context: activeCtx }),
|
|
89
94
|
});
|
|
90
95
|
} catch (e) {
|
|
91
96
|
// Silently fail to avoid breaking the application
|