securenow 5.6.0 → 5.7.0
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 +1594 -1609
- package/README.md +72 -36
- package/cli/monitor.js +13 -1
- package/cli/run.js +133 -0
- package/cli.js +22 -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/INDEX.md +14 -3
- package/docs/LOGGING-GUIDE.md +701 -708
- package/docs/LOGGING-QUICKSTART.md +234 -239
- package/docs/NUXT-GUIDE.md +166 -0
- package/nextjs-webpack-config.js +77 -0
- package/nextjs.js +19 -3
- package/nuxt-server-plugin.mjs +400 -0
- package/nuxt.d.ts +60 -0
- package/nuxt.mjs +75 -0
- package/package.json +21 -4
- package/register.js +39 -4
- package/tracing.js +15 -7
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "securenow",
|
|
3
|
-
"version": "5.
|
|
4
|
-
"description": "OpenTelemetry instrumentation for Node.js
|
|
3
|
+
"version": "5.7.0",
|
|
4
|
+
"description": "OpenTelemetry instrumentation for Node.js, Next.js, and Nuxt - Send traces and logs to any OTLP-compatible backend",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "register.js",
|
|
7
7
|
"types": "register.d.ts",
|
|
@@ -29,7 +29,11 @@
|
|
|
29
29
|
"node",
|
|
30
30
|
"express",
|
|
31
31
|
"fastify",
|
|
32
|
-
"nestjs"
|
|
32
|
+
"nestjs",
|
|
33
|
+
"nuxt",
|
|
34
|
+
"nuxt3",
|
|
35
|
+
"nitro",
|
|
36
|
+
"vue"
|
|
33
37
|
],
|
|
34
38
|
"exports": {
|
|
35
39
|
".": {
|
|
@@ -65,6 +69,11 @@
|
|
|
65
69
|
},
|
|
66
70
|
"./nextjs-webpack-config": "./nextjs-webpack-config.js",
|
|
67
71
|
"./package.json": "./package.json",
|
|
72
|
+
"./nuxt": {
|
|
73
|
+
"types": "./nuxt.d.ts",
|
|
74
|
+
"import": "./nuxt.mjs",
|
|
75
|
+
"default": "./nuxt.mjs"
|
|
76
|
+
},
|
|
68
77
|
"./register-vite": "./register-vite.js",
|
|
69
78
|
"./web-vite": {
|
|
70
79
|
"import": "./web-vite.mjs",
|
|
@@ -85,6 +94,10 @@
|
|
|
85
94
|
"nextjs-middleware.d.ts",
|
|
86
95
|
"nextjs-wrapper.js",
|
|
87
96
|
"nextjs-wrapper.d.ts",
|
|
97
|
+
"nextjs-webpack-config.js",
|
|
98
|
+
"nuxt.mjs",
|
|
99
|
+
"nuxt.d.ts",
|
|
100
|
+
"nuxt-server-plugin.mjs",
|
|
88
101
|
"cli.js",
|
|
89
102
|
"cli/",
|
|
90
103
|
"free-trial-banner.js",
|
|
@@ -119,11 +132,15 @@
|
|
|
119
132
|
"uuid": "^9.0.0"
|
|
120
133
|
},
|
|
121
134
|
"peerDependencies": {
|
|
122
|
-
"next": ">=13.0.0"
|
|
135
|
+
"next": ">=13.0.0",
|
|
136
|
+
"nuxt": ">=3.0.0"
|
|
123
137
|
},
|
|
124
138
|
"peerDependenciesMeta": {
|
|
125
139
|
"next": {
|
|
126
140
|
"optional": true
|
|
141
|
+
},
|
|
142
|
+
"nuxt": {
|
|
143
|
+
"optional": true
|
|
127
144
|
}
|
|
128
145
|
},
|
|
129
146
|
"overrides": {
|
package/register.js
CHANGED
|
@@ -1,14 +1,49 @@
|
|
|
1
|
-
// securenow/
|
|
1
|
+
// securenow/register.js — the only preload customers need:
|
|
2
|
+
// node --require securenow/register app.js
|
|
3
|
+
//
|
|
4
|
+
// For ESM apps ("type": "module"), this file auto-registers the
|
|
5
|
+
// OpenTelemetry ESM loader hook via module.register() (Node >=20.6).
|
|
6
|
+
// On older Node versions it falls back to a warning.
|
|
2
7
|
'use strict';
|
|
3
8
|
|
|
4
|
-
//
|
|
9
|
+
// 1. load .env before anything else
|
|
5
10
|
try {
|
|
6
11
|
require('dotenv').config();
|
|
7
12
|
console.log('[securenow] dotenv loaded from', process.env.DOTENV_CONFIG_PATH || '.env');
|
|
8
13
|
} catch (e) {
|
|
9
|
-
// dotenv is optional — only warn if it’s missing
|
|
10
14
|
console.warn('[securenow] dotenv not found or failed to load');
|
|
11
15
|
}
|
|
12
16
|
|
|
13
|
-
//
|
|
17
|
+
// 2. Auto-register the ESM loader hook so customers never need --import
|
|
18
|
+
(() => {
|
|
19
|
+
try {
|
|
20
|
+
const fs = require('fs');
|
|
21
|
+
const path = require('path');
|
|
22
|
+
const pkgPath = path.resolve(process.cwd(), 'package.json');
|
|
23
|
+
if (!fs.existsSync(pkgPath)) return;
|
|
24
|
+
|
|
25
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
26
|
+
if (pkg.type !== 'module') return;
|
|
27
|
+
|
|
28
|
+
// Already registered via --import?
|
|
29
|
+
const execArgv = process.execArgv.join(' ');
|
|
30
|
+
if (execArgv.includes('hook.mjs') || execArgv.includes('import-in-the-middle')) return;
|
|
31
|
+
|
|
32
|
+
// Node >=20.6 exposes module.register() for programmatic ESM hooks
|
|
33
|
+
const mod = require('node:module');
|
|
34
|
+
if (typeof mod.register !== 'function') {
|
|
35
|
+
console.warn('[securenow] ESM app detected but Node %s lacks module.register().', process.version);
|
|
36
|
+
console.warn('[securenow] Upgrade to Node >=20.6 or add: --import @opentelemetry/instrumentation/hook.mjs');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const { pathToFileURL } = require('node:url');
|
|
41
|
+
mod.register('@opentelemetry/instrumentation/hook.mjs', pathToFileURL(__filename));
|
|
42
|
+
console.log('[securenow] ESM loader hook auto-registered (module.register)');
|
|
43
|
+
} catch (_) {
|
|
44
|
+
// Non-fatal — tracing.js will show its own ESM warning if the hook is missing
|
|
45
|
+
}
|
|
46
|
+
})();
|
|
47
|
+
|
|
48
|
+
// 3. Run the OTel SDK setup
|
|
14
49
|
require('./tracing');
|
package/tracing.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Preload with: node --require securenow/register app.js
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* Works for both CJS and ESM apps. On Node >=20.6 the ESM loader hook is
|
|
7
|
+
* auto-registered via module.register() — no --import flag needed.
|
|
8
|
+
* On Node 18 with "type": "module", add the hook manually:
|
|
7
9
|
* node --import @opentelemetry/instrumentation/hook.mjs --require securenow/register app.js
|
|
8
10
|
*
|
|
9
11
|
* Env:
|
|
@@ -21,7 +23,7 @@
|
|
|
21
23
|
* SECURENOW_STRICT=1 -> if no appid/name is provided in cluster, exit(1) so PM2 restarts the worker
|
|
22
24
|
*/
|
|
23
25
|
|
|
24
|
-
const { diag, DiagConsoleLogger, DiagLogLevel } = require('@opentelemetry/api');
|
|
26
|
+
const { diag, DiagConsoleLogger, DiagLogLevel, context, trace } = require('@opentelemetry/api');
|
|
25
27
|
const { NodeSDK } = require('@opentelemetry/sdk-node');
|
|
26
28
|
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
|
|
27
29
|
const { OTLPLogExporter } = require('@opentelemetry/exporter-logs-otlp-http');
|
|
@@ -101,6 +103,9 @@ function redactGraphQLQuery(query, sensitiveFields = DEFAULT_SENSITIVE_FIELDS) {
|
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
// -------- ESM detection --------
|
|
106
|
+
// register.js auto-registers the hook via module.register() on Node >=20.6.
|
|
107
|
+
// This warning only fires if BOTH --import AND module.register() were skipped
|
|
108
|
+
// (e.g. Node 18, or require('securenow/tracing') called directly without register.js).
|
|
104
109
|
(() => {
|
|
105
110
|
try {
|
|
106
111
|
const fs = require('fs');
|
|
@@ -110,11 +115,11 @@ function redactGraphQLQuery(query, sensitiveFields = DEFAULT_SENSITIVE_FIELDS) {
|
|
|
110
115
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
111
116
|
if (pkg.type === 'module') {
|
|
112
117
|
const execArgv = process.execArgv.join(' ');
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
console.warn('[securenow]
|
|
117
|
-
console.warn('[securenow]
|
|
118
|
+
const hasCliHook = execArgv.includes('hook.mjs') || execArgv.includes('import-in-the-middle');
|
|
119
|
+
const hasModuleRegister = typeof require('node:module').register === 'function';
|
|
120
|
+
if (!hasCliHook && !hasModuleRegister) {
|
|
121
|
+
console.warn('[securenow] ⚠️ ESM app detected ("type": "module") but no ESM loader hook available.');
|
|
122
|
+
console.warn('[securenow] Upgrade to Node >=20.6 (recommended) or add: --import @opentelemetry/instrumentation/hook.mjs');
|
|
118
123
|
}
|
|
119
124
|
}
|
|
120
125
|
}
|
|
@@ -363,11 +368,14 @@ if (loggingEnabled) {
|
|
|
363
368
|
const SEV = { DEBUG: 5, INFO: 9, WARN: 13, ERROR: 17 };
|
|
364
369
|
function _emit(sn, st, args) {
|
|
365
370
|
try {
|
|
371
|
+
const activeCtx = context.active();
|
|
372
|
+
const spanCtx = trace.getSpanContext(activeCtx);
|
|
366
373
|
_logger.emit({
|
|
367
374
|
severityNumber: sn,
|
|
368
375
|
severityText: st,
|
|
369
376
|
body: args.map(a => (typeof a === 'object' && a !== null) ? JSON.stringify(a) : String(a)).join(' '),
|
|
370
377
|
attributes: { 'log.source': 'console', 'log.method': st.toLowerCase() },
|
|
378
|
+
...(spanCtx && { context: activeCtx }),
|
|
371
379
|
});
|
|
372
380
|
} catch (_) {}
|
|
373
381
|
}
|