securenow 5.4.0 → 5.5.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.
Files changed (3) hide show
  1. package/nextjs.js +22 -4
  2. package/package.json +3 -2
  3. package/tracing.js +25 -1
package/nextjs.js CHANGED
@@ -5,18 +5,36 @@
5
5
  *
6
6
  * Usage in Next.js app:
7
7
  *
8
- * 1. Create instrumentation.ts (or .js) in your project root:
8
+ * 1. Add serverExternalPackages to next.config.js (REQUIRED to avoid webpack bundling issues):
9
+ *
10
+ * const nextConfig = {
11
+ * serverExternalPackages: [
12
+ * "securenow",
13
+ * "@opentelemetry/sdk-node",
14
+ * "@opentelemetry/auto-instrumentations-node",
15
+ * "@opentelemetry/instrumentation-http",
16
+ * "@opentelemetry/exporter-trace-otlp-http",
17
+ * "@opentelemetry/exporter-logs-otlp-http",
18
+ * "@opentelemetry/sdk-logs",
19
+ * "@opentelemetry/instrumentation",
20
+ * "@opentelemetry/resources",
21
+ * "@opentelemetry/semantic-conventions",
22
+ * "@opentelemetry/api",
23
+ * "@opentelemetry/api-logs",
24
+ * "@vercel/otel",
25
+ * ],
26
+ * };
27
+ *
28
+ * 2. Create instrumentation.ts (or .js) in your project root:
9
29
  *
10
30
  * import { registerSecureNow } from 'securenow/nextjs';
11
31
  * export function register() {
12
32
  * registerSecureNow();
13
33
  * }
14
34
  *
15
- * 2. Set environment variables:
35
+ * 3. Set environment variables:
16
36
  * SECURENOW_APPID=my-nextjs-app
17
37
  * SECURENOW_INSTANCE=http://your-otlp-backend:4318
18
- *
19
- * That's it! 🎉 No webpack warnings!
20
38
  */
21
39
 
22
40
  const { v4: uuidv4 } = require('uuid');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securenow",
3
- "version": "5.4.0",
3
+ "version": "5.5.0",
4
4
  "description": "OpenTelemetry instrumentation for Node.js and Next.js - Send traces and logs to any OTLP-compatible backend",
5
5
  "type": "commonjs",
6
6
  "main": "register.js",
@@ -64,6 +64,7 @@
64
64
  "default": "./nextjs-wrapper.js"
65
65
  },
66
66
  "./nextjs-webpack-config": "./nextjs-webpack-config.js",
67
+ "./package.json": "./package.json",
67
68
  "./register-vite": "./register-vite.js",
68
69
  "./web-vite": {
69
70
  "import": "./web-vite.mjs",
@@ -105,7 +106,7 @@
105
106
  "@opentelemetry/instrumentation": "0.47.0",
106
107
  "@opentelemetry/instrumentation-document-load": "0.47.0",
107
108
  "@opentelemetry/instrumentation-fetch": "0.47.0",
108
- "@opentelemetry/instrumentation-http": "^0.208.0",
109
+ "@opentelemetry/instrumentation-http": "0.47.0",
109
110
  "@opentelemetry/instrumentation-user-interaction": "0.47.0",
110
111
  "@opentelemetry/instrumentation-xml-http-request": "0.47.0",
111
112
  "@opentelemetry/resources": "1.20.0",
package/tracing.js CHANGED
@@ -1,7 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  /**
4
- * Preload with: NODE_OPTIONS="-r securenow/register"
4
+ * Preload with: node --require securenow/register app.js
5
+ *
6
+ * For ESM apps ("type": "module" in package.json), you MUST also add the ESM loader hook:
7
+ * node --import @opentelemetry/instrumentation/hook.mjs --require securenow/register app.js
5
8
  *
6
9
  * Env:
7
10
  * SECURENOW_APPID=logical-name # or OTEL_SERVICE_NAME=logical-name
@@ -97,6 +100,27 @@ function redactGraphQLQuery(query, sensitiveFields = DEFAULT_SENSITIVE_FIELDS) {
97
100
  return redacted;
98
101
  }
99
102
 
103
+ // -------- ESM detection --------
104
+ (() => {
105
+ try {
106
+ const fs = require('fs');
107
+ const path = require('path');
108
+ const pkgPath = path.resolve(process.cwd(), 'package.json');
109
+ if (fs.existsSync(pkgPath)) {
110
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
111
+ if (pkg.type === 'module') {
112
+ const execArgv = process.execArgv.join(' ');
113
+ const hasEsmHook = execArgv.includes('hook.mjs') || execArgv.includes('import-in-the-middle');
114
+ if (!hasEsmHook) {
115
+ console.warn('[securenow] ⚠️ ESM app detected ("type": "module") but no ESM loader hook found.');
116
+ console.warn('[securenow] Instrumentations will NOT work without the ESM hook.');
117
+ console.warn('[securenow] Fix: node --import @opentelemetry/instrumentation/hook.mjs --require securenow/register app.js');
118
+ }
119
+ }
120
+ }
121
+ } catch (_) {}
122
+ })();
123
+
100
124
  // -------- diagnostics --------
101
125
  (() => {
102
126
  const L = (env('OTEL_LOG_LEVEL') || '').toLowerCase();